edit config modem component

This commit is contained in:
Chelios 2024-10-01 10:13:06 +03:00
parent 9c7822fad0
commit d8905417ba
2 changed files with 46 additions and 89 deletions

View file

@ -4,29 +4,28 @@ import esphome.codegen as cg
from esphome.const import ( from esphome.const import (
CONF_DOMAIN, CONF_DOMAIN,
CONF_ID, CONF_ID,
CONF_MANUAL_IP,
CONF_STATIC_IP,
CONF_TYPE, CONF_TYPE,
CONF_RESET_PIN,
CONF_RX_BUFFER_SIZE,
CONF_RX_PIN,
CONF_TX_BUFFER_SIZE,
CONF_TX_PIN,
CONF_USE_ADDRESS, CONF_USE_ADDRESS,
CONF_GATEWAY,
CONF_SUBNET,
CONF_DNS1,
CONF_DNS2,
) )
from esphome.core import CORE, coroutine_with_priority from esphome.core import CORE, coroutine_with_priority
from esphome.components.esp32 import add_idf_component, add_idf_sdkconfig_option from esphome.components.esp32 import add_idf_component, add_idf_sdkconfig_option
from esphome.components.network import IPAddress from esphome.components.network import IPAddress
CONFLICTS_WITH = ["wifi"] CONFLICTS_WITH = ["wifi", "ethernet"]
DEPENDENCIES = ["esp32"] DEPENDENCIES = ["esp32"]
AUTO_LOAD = ["network"] AUTO_LOAD = ["network"]
modem_ns = cg.esphome_ns.namespace("modem") modem_ns = cg.esphome_ns.namespace("modem")
# CONF_PHY_ADDR = "phy_addr" CONF_APN = "apn"
# CONF_MDC_PIN = "mdc_pin" CONF_UART_EVENT_TASK_STACK_SIZE = "uart_event_task_stack_size"
# CONF_MDIO_PIN = "mdio_pin" CONF_UART_EVENT_TASK_PRIORITY = "uart_event_task_priority"
# CONF_CLK_MODE = "clk_mode" CONF_UART_EVENT_QUEUE_SIZE = "uart_event_queue_size"
# CONF_POWER_PIN = "power_pin"
ModemType = modem_ns.enum("ModemType") ModemType = modem_ns.enum("ModemType")
MODEM_TYPES = { MODEM_TYPES = {
@ -58,16 +57,6 @@ MODEM_TYPES = {
# } # }
# MANUAL_IP_SCHEMA = cv.Schema(
# {
# cv.Required(CONF_STATIC_IP): cv.ipv4,
# cv.Required(CONF_GATEWAY): cv.ipv4,
# cv.Required(CONF_SUBNET): cv.ipv4,
# cv.Optional(CONF_DNS1, default="0.0.0.0"): cv.ipv4,
# cv.Optional(CONF_DNS2, default="0.0.0.0"): cv.ipv4,
# }
# )
ModemComponent = modem_ns.class_("ModemComponent", cg.Component) ModemComponent = modem_ns.class_("ModemComponent", cg.Component)
#ManualIP = ethernet_ns.struct("ManualIP") #ManualIP = ethernet_ns.struct("ManualIP")
@ -82,65 +71,40 @@ CONFIG_SCHEMA = cv.Schema(
{ {
cv.GenerateID(): cv.declare_id(ModemComponent), cv.GenerateID(): cv.declare_id(ModemComponent),
cv.Required(CONF_TYPE): cv.enum(MODEM_TYPES, upper=True), cv.Required(CONF_TYPE): cv.enum(MODEM_TYPES, upper=True),
cv.Required(CONF_RESET_PIN): pins.internal_gpio_output_pin_schema,
cv.Required(CONF_TX_PIN): pins.internal_gpio_output_pin_schema,
cv.Required(CONF_RX_PIN): pins.internal_gpio_input_pin_schema,
cv.Optional(CONF_APN, default="internet"): cv.string,
cv.Optional(CONF_UART_EVENT_TASK_STACK_SIZE, default=2048): cv.positive_not_null_int,
cv.Optional(CONF_UART_EVENT_TASK_PRIORITY, default=5): cv.positive_not_null_int,
cv.Optional(CONF_UART_EVENT_QUEUE_SIZE, default=30): cv.positive_not_null_int,
cv.Optional(CONF_TX_BUFFER_SIZE, default=512): cv.positive_not_null_int,
cv.Optional(CONF_RX_BUFFER_SIZE, default=1024): cv.positive_not_null_int,
cv.Optional(CONF_DOMAIN, default=".local"): cv.domain_name, cv.Optional(CONF_DOMAIN, default=".local"): cv.domain_name,
cv.Optional(CONF_USE_ADDRESS): cv.string_strict, cv.Optional(CONF_USE_ADDRESS): cv.string_strict,
} }
).extend(cv.COMPONENT_SCHEMA) ).extend(cv.COMPONENT_SCHEMA)
# cv.All(
# cv.Schema(
# {
# cv.GenerateID(): cv.declare_id(ModemComponent),
# cv.Required(CONF_TYPE): cv.enum(MODEM_TYPES, upper=True),
# #cv.Required(CONF_MDC_PIN): pins.internal_gpio_output_pin_number,
# # cv.Required(CONF_MDIO_PIN): pins.internal_gpio_output_pin_number,
# # cv.Optional(CONF_CLK_MODE, default="GPIO0_IN"): cv.enum(
# # CLK_MODES, upper=True, space="_"
# # ),
# # cv.Optional(CONF_PHY_ADDR, default=0): cv.int_range(min=0, max=31),
# # cv.Optional(CONF_POWER_PIN): pins.internal_gpio_output_pin_number,
# # cv.Optional(CONF_MANUAL_IP): MANUAL_IP_SCHEMA,
# cv.Optional(CONF_DOMAIN, default=".local"): cv.domain_name,
# cv.Optional(CONF_USE_ADDRESS): cv.string_strict,
# # cv.Optional("enable_mdns"): cv.invalid(
# # "This option has been removed. Please use the [disabled] option under the "
# # "new mdns component instead."
# # ),
# }
# ).extend(cv.COMPONENT_SCHEMA),
# _validate,
# )
# def manual_ip(config):
# return cg.StructInitializer(
# ManualIP,
# ("static_ip", IPAddress(*config[CONF_STATIC_IP].args)),
# ("gateway", IPAddress(*config[CONF_GATEWAY].args)),
# ("subnet", IPAddress(*config[CONF_SUBNET].args)),
# ("dns1", IPAddress(*config[CONF_DNS1].args)),
# ("dns2", IPAddress(*config[CONF_DNS2].args)),
# )
@coroutine_with_priority(60.0) @coroutine_with_priority(60.0)
async def to_code(config): async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config) await cg.register_component(var, config)
#cg.add(var.set_phy_addr(config[CONF_PHY_ADDR]))
#cg.add(var.set_mdc_pin(config[CONF_MDC_PIN]))
#cg.add(var.set_mdio_pin(config[CONF_MDIO_PIN]))
cg.add(var.set_type(config[CONF_TYPE])) cg.add(var.set_type(config[CONF_TYPE]))
#cg.add(var.set_clk_mode(*CLK_MODES[config[CONF_CLK_MODE]])) cg.add(var.set_reset_pin(config[CONF_RESET_PIN]))
cg.add(var.set_tx_pin(config[CONF_TX_PIN]))
cg.add(var.set_rx_pin(config[CONF_RX_PIN]))
cg.add(var.set_apn(config[CONF_APN]))
cg.add(var.set_tx_buffer_size(config[CONF_TX_BUFFER_SIZE]))
cg.add(var.set_rx_buffer_size(config[CONF_RX_BUFFER_SIZE]))
cg.add(var.set_uart_event_task_stack_size(config[CONF_UART_EVENT_TASK_STACK_SIZE]))
cg.add(var.set_uart_event_task_priority(config[CONF_UART_EVENT_TASK_PRIORITY]))
cg.add(var.set_uart_event_queue_size([CONF_UART_EVENT_QUEUE_SIZE]))
cg.add(var.set_use_address(config[CONF_USE_ADDRESS])) cg.add(var.set_use_address(config[CONF_USE_ADDRESS]))
# if CONF_POWER_PIN in config: # if CONF_POWER_PIN in config:
# cg.add(var.set_power_pin(config[CONF_POWER_PIN])) # cg.add(var.set_power_pin(config[CONF_POWER_PIN]))
# if CONF_MANUAL_IP in config:
# cg.add(var.set_manual_ip(manual_ip(config[CONF_MANUAL_IP])))
cg.add_define("USE_MODEM") cg.add_define("USE_MODEM")
if CORE.using_arduino: if CORE.using_arduino:

View file

@ -1,16 +1,11 @@
#define CONFIG_EXAMPLE_MODEM_PPP_APN "internet" #define CONFIG_MODEM_PPP_APN "internet"
#define CONFIG_EXAMPLE_MODEM_PPP_AUTH_USERNAME "espressif" #define CONFIG_MODEM_UART_TX_PIN 25
#define CONFIG_EXAMPLE_MODEM_PPP_AUTH_PASSWORD "esp32" #define CONFIG_MODEM_UART_RX_PIN 26
#define CONFIG_EXAMPLE_MODEM_UART_TX_PIN 25 #define CONFIG_MODEM_UART_EVENT_TASK_STACK_SIZE 2048
#define CONFIG_EXAMPLE_MODEM_UART_RX_PIN 26 #define CONFIG_MODEM_UART_EVENT_TASK_PRIORITY 5
#define CONFIG_EXAMPLE_MODEM_UART_RTS_PIN 27 #define CONFIG_MODEM_UART_EVENT_QUEUE_SIZE 30
#define CONFIG_EXAMPLE_MODEM_UART_CTS_PIN 23 #define CONFIG_MODEM_UART_TX_BUFFER_SIZE 512
#define CONFIG_EXAMPLE_MODEM_UART_EVENT_TASK_STACK_SIZE 2048 #define CONFIG_MODEM_UART_RX_BUFFER_SIZE 1024
#define CONFIG_EXAMPLE_MODEM_UART_EVENT_TASK_PRIORITY 5
#define CONFIG_EXAMPLE_MODEM_UART_EVENT_QUEUE_SIZE 30
#define CONFIG_EXAMPLE_MODEM_UART_PATTERN_QUEUE_SIZE 20
#define CONFIG_EXAMPLE_MODEM_UART_TX_BUFFER_SIZE 512
#define CONFIG_EXAMPLE_MODEM_UART_RX_BUFFER_SIZE 1024
#include "esp_modem_c_api_types.h" #include "esp_modem_c_api_types.h"
@ -135,7 +130,7 @@ void ModemComponent::setup() {
/* Configure the PPP netif */ /* Configure the PPP netif */
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG(CONFIG_EXAMPLE_MODEM_PPP_APN); esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG(CONFIG_MODEM_PPP_APN);
esp_netif_config_t netif_ppp_config = ESP_NETIF_DEFAULT_PPP(); esp_netif_config_t netif_ppp_config = ESP_NETIF_DEFAULT_PPP();
this->modem_netif_ = esp_netif_new(&netif_ppp_config); this->modem_netif_ = esp_netif_new(&netif_ppp_config);
//esp_netif_t *esp_netif = esp_netif_new(&netif_ppp_config); //esp_netif_t *esp_netif = esp_netif_new(&netif_ppp_config);
@ -146,16 +141,14 @@ void ModemComponent::setup() {
/* Configure the DTE */ /* Configure the DTE */
esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG(); esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG();
/* setup UART specific configuration based on kconfig options */ /* setup UART specific configuration based on kconfig options */
dte_config.uart_config.tx_io_num = CONFIG_EXAMPLE_MODEM_UART_TX_PIN; dte_config.uart_config.tx_io_num = CONFIG_MODEM_UART_TX_PIN;
dte_config.uart_config.rx_io_num = CONFIG_EXAMPLE_MODEM_UART_RX_PIN; dte_config.uart_config.rx_io_num = CONFIG_MODEM_UART_RX_PIN;
dte_config.uart_config.rts_io_num = CONFIG_EXAMPLE_MODEM_UART_RTS_PIN; dte_config.uart_config.rx_buffer_size = CONFIG_MODEM_UART_RX_BUFFER_SIZE;
dte_config.uart_config.cts_io_num = CONFIG_EXAMPLE_MODEM_UART_CTS_PIN; dte_config.uart_config.tx_buffer_size = CONFIG_MODEM_UART_TX_BUFFER_SIZE;
dte_config.uart_config.rx_buffer_size = CONFIG_EXAMPLE_MODEM_UART_RX_BUFFER_SIZE; dte_config.uart_config.event_queue_size = CONFIG_MODEM_UART_EVENT_QUEUE_SIZE;
dte_config.uart_config.tx_buffer_size = CONFIG_EXAMPLE_MODEM_UART_TX_BUFFER_SIZE; dte_config.task_stack_size = CONFIG_MODEM_UART_EVENT_TASK_STACK_SIZE;
dte_config.uart_config.event_queue_size = CONFIG_EXAMPLE_MODEM_UART_EVENT_QUEUE_SIZE; dte_config.task_priority = CONFIG_MODEM_UART_EVENT_TASK_PRIORITY;
dte_config.task_stack_size = CONFIG_EXAMPLE_MODEM_UART_EVENT_TASK_STACK_SIZE; dte_config.dte_buffer_size = CONFIG_MODEM_UART_RX_BUFFER_SIZE / 2;
dte_config.task_priority = CONFIG_EXAMPLE_MODEM_UART_EVENT_TASK_PRIORITY;
dte_config.dte_buffer_size = CONFIG_EXAMPLE_MODEM_UART_RX_BUFFER_SIZE / 2;
ESP_LOGD(TAG, "Initializing esp_modem"); ESP_LOGD(TAG, "Initializing esp_modem");
dte = esp_modem::create_uart_dte(&dte_config); dte = esp_modem::create_uart_dte(&dte_config);