CMUX disabled by default

This commit is contained in:
oarcher 2024-07-26 23:59:11 +02:00
parent 90ec353d85
commit 71725ab4c4
4 changed files with 31 additions and 10 deletions

View file

@ -1,3 +1,5 @@
import logging
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_ID,
CONF_USE_ADDRESS, CONF_USE_ADDRESS,
@ -17,9 +19,11 @@ from esphome.core import 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 import pins, automation from esphome import pins, automation
_LOGGER = logging.getLogger(__name__)
CODEOWNERS = ["@oarcher"] CODEOWNERS = ["@oarcher"]
DEPENDENCIES = ["esp32"] DEPENDENCIES = ["esp32"]
AUTO_LOAD = ["network", "binary_sensor", "gpio"] AUTO_LOAD = ["network"]
# following should be removed if conflicts are resolved (so we can have a wifi ap using modem) # following should be removed if conflicts are resolved (so we can have a wifi ap using modem)
CONFLICTS_WITH = ["wifi", "captive_portal", "ethernet"] CONFLICTS_WITH = ["wifi", "captive_portal", "ethernet"]
@ -30,6 +34,7 @@ CONF_STATUS_PIN = "status_pin"
CONF_POWER_PIN = "power_pin" CONF_POWER_PIN = "power_pin"
CONF_INIT_AT = "init_at" CONF_INIT_AT = "init_at"
CONF_ON_NOT_RESPONDING = "on_not_responding" CONF_ON_NOT_RESPONDING = "on_not_responding"
CONF_ENABLE_CMUX = "enable_cmux"
MODEM_MODELS = ["BG96", "SIM800", "SIM7000", "SIM7600", "GENERIC"] MODEM_MODELS = ["BG96", "SIM800", "SIM7000", "SIM7600", "GENERIC"]
MODEM_MODELS_POWER = { MODEM_MODELS_POWER = {
@ -70,6 +75,7 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(CONF_USE_ADDRESS): cv.string, cv.Optional(CONF_USE_ADDRESS): cv.string,
cv.Optional(CONF_INIT_AT): cv.All(cv.ensure_list(cv.string)), cv.Optional(CONF_INIT_AT): cv.All(cv.ensure_list(cv.string)),
cv.Optional(CONF_ENABLE_ON_BOOT, default=True): cv.boolean, cv.Optional(CONF_ENABLE_ON_BOOT, default=True): cv.boolean,
cv.Optional(CONF_ENABLE_CMUX, default=False): cv.boolean,
cv.Optional(CONF_ON_NOT_RESPONDING): automation.validate_automation( cv.Optional(CONF_ON_NOT_RESPONDING): automation.validate_automation(
{ {
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id( cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
@ -100,6 +106,12 @@ def _final_validate(config):
# raise cv.Invalid( # raise cv.Invalid(
# f"'{CONF_STATUS_PIN}' must be declared if using '{CONF_POWER_PIN}'" # f"'{CONF_STATUS_PIN}' must be declared if using '{CONF_POWER_PIN}'"
# ) # )
if config.get(CONF_STATUS_PIN, None):
_LOGGER.warning("Using '%s' is experimental", CONF_STATUS_PIN)
if config[CONF_ENABLE_CMUX]:
_LOGGER.warning("Using '%s: True' is experimental", CONF_ENABLE_CMUX)
if not config[CONF_ENABLE_ON_BOOT]:
_LOGGER.warning("Using '%s: False' is experimental", CONF_ENABLE_ON_BOOT)
if config.get(CONF_POWER_PIN, None): if config.get(CONF_POWER_PIN, None):
if config[CONF_MODEL] not in MODEM_MODELS_POWER: if config[CONF_MODEL] not in MODEM_MODELS_POWER:
raise cv.Invalid( raise cv.Invalid(
@ -114,8 +126,8 @@ FINAL_VALIDATE_SCHEMA = _final_validate
async def to_code(config): async def to_code(config):
add_idf_component( add_idf_component(
name="esp_modem", name="esp_modem",
repo="https://github.com/oarcher/esp-protocols.git", repo="https://github.com/espressif/esp-protocols.git",
ref="dev", ref="modem-v1.1.0",
path="components/esp_modem", path="components/esp_modem",
) )
@ -124,18 +136,23 @@ async def to_code(config):
add_idf_sdkconfig_option("CONFIG_LWIP_PPP_SUPPORT", True) add_idf_sdkconfig_option("CONFIG_LWIP_PPP_SUPPORT", True)
add_idf_sdkconfig_option("CONFIG_PPP_PAP_SUPPORT", True) add_idf_sdkconfig_option("CONFIG_PPP_PAP_SUPPORT", True)
add_idf_sdkconfig_option("CONFIG_LWIP_PPP_PAP_SUPPORT", True) add_idf_sdkconfig_option("CONFIG_LWIP_PPP_PAP_SUPPORT", True)
add_idf_sdkconfig_option("CONFIG_ESP_MODEM_CMUX_DEFRAGMENT_PAYLOAD", True)
# ("ESP_MODEM_CMUX_USE_SHORT_PAYLOADS_ONLY", True)
add_idf_sdkconfig_option("CONFIG_ESP_MODEM_CMUX_DELAY_AFTER_DLCI_SETUP", 0) add_idf_sdkconfig_option("CONFIG_ESP_MODEM_CMUX_DELAY_AFTER_DLCI_SETUP", 0)
add_idf_sdkconfig_option("CONFIG_PPP_SUPPORT", True) add_idf_sdkconfig_option("CONFIG_PPP_SUPPORT", True)
add_idf_sdkconfig_option("CONFIG_PPP_NOTIFY_PHASE_SUPPORT", True) add_idf_sdkconfig_option("CONFIG_PPP_NOTIFY_PHASE_SUPPORT", True)
add_idf_sdkconfig_option("CONFIG_PPP_CHAP_SUPPORT", True) add_idf_sdkconfig_option("CONFIG_PPP_CHAP_SUPPORT", True)
add_idf_sdkconfig_option("CONFIG_LWIP_PPP_VJ_HEADER_COMPRESSION", True) add_idf_sdkconfig_option("CONFIG_LWIP_PPP_VJ_HEADER_COMPRESSION", True)
add_idf_sdkconfig_option("CONFIG_LWIP_PPP_NOTIFY_PHASE_SUPPORT", True) add_idf_sdkconfig_option("CONFIG_LWIP_PPP_NOTIFY_PHASE_SUPPORT", True)
# commented because cause crash if another UART is defined in the yaml # commented because cause crash if another UART is defined in the yaml
# If enabled, it should increase the reliability and the speed of the connection (TODO: test) # If enabled, it should increase the reliability and the speed of the connection (TODO: test)
# add_idf_sdkconfig_option("CONFIG_UART_ISR_IN_IRAM", True) # add_idf_sdkconfig_option("CONFIG_UART_ISR_IN_IRAM", True)
# If Uart queue full message ( A7672 ), those config option might be changed
# https://github.com/espressif/esp-protocols/issues/272#issuecomment-1558682967
add_idf_sdkconfig_option("CONFIG_ESP_MODEM_CMUX_DEFRAGMENT_PAYLOAD", True)
add_idf_sdkconfig_option("ESP_MODEM_USE_INFLATABLE_BUFFER_IF_NEEDED", False)
add_idf_sdkconfig_option("ESP_MODEM_CMUX_USE_SHORT_PAYLOADS_ONLY", False)
cg.add_define("USE_MODEM") cg.add_define("USE_MODEM")
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
@ -151,10 +168,12 @@ async def to_code(config):
if pin_code := config.get(CONF_PIN_CODE, None): if pin_code := config.get(CONF_PIN_CODE, None):
cg.add(var.set_pin_code(pin_code)) cg.add(var.set_pin_code(pin_code))
if enable_on_boot := config.get(CONF_ENABLE_ON_BOOT, None): if config[CONF_ENABLE_ON_BOOT]:
if enable_on_boot:
cg.add(var.enable()) cg.add(var.enable())
if config[CONF_ENABLE_CMUX]:
cg.add(var.enable_cmux())
if init_at := config.get(CONF_INIT_AT, None): if init_at := config.get(CONF_INIT_AT, None):
for cmd in init_at: for cmd in init_at:
cg.add(var.add_init_at_command(cmd)) cg.add(var.add_init_at_command(cmd))

View file

@ -6,7 +6,6 @@
#include "esphome/core/application.h" #include "esphome/core/application.h"
#include "esphome/core/defines.h" #include "esphome/core/defines.h"
#include "esphome/components/network/util.h" #include "esphome/components/network/util.h"
// #include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
#include <esp_netif.h> #include <esp_netif.h>
#include <esp_netif_ppp.h> #include <esp_netif_ppp.h>
@ -112,6 +111,7 @@ void ModemComponent::setup() {
ESP_LOGCONFIG(TAG, " Status pin: Not defined"); ESP_LOGCONFIG(TAG, " Status pin: Not defined");
} }
ESP_LOGCONFIG(TAG, " Enabled : %s", this->enabled_ ? "Yes" : "No"); ESP_LOGCONFIG(TAG, " Enabled : %s", this->enabled_ ? "Yes" : "No");
ESP_LOGCONFIG(TAG, " Use CMUX : %s", this->cmux_ ? "Yes" : "No");
ESP_LOGV(TAG, "PPP netif setup"); ESP_LOGV(TAG, "PPP netif setup");
esp_err_t err; esp_err_t err;
@ -272,7 +272,7 @@ void ModemComponent::start_connect_() {
ESP_LOGD(TAG, "Modem has correctly entered multiplexed command/data mode"); ESP_LOGD(TAG, "Modem has correctly entered multiplexed command/data mode");
} else { } else {
ESP_LOGD(TAG, "Unable to enter CMUX mode"); ESP_LOGE(TAG, "Unable to enter CMUX mode");
this->status_set_error("Unable to enter CMUX mode"); this->status_set_error("Unable to enter CMUX mode");
} }
assert(this->modem_ready()); assert(this->modem_ready());

View file

@ -60,6 +60,7 @@ class ModemComponent : public Component {
void set_pin_code(const std::string &pin_code) { this->pin_code_ = pin_code; } void set_pin_code(const std::string &pin_code) { this->pin_code_ = pin_code; }
void set_apn(const std::string &apn) { this->apn_ = apn; } void set_apn(const std::string &apn) { this->apn_ = apn; }
void set_not_responding_cb(Trigger<> *not_responding_cb) { this->not_responding_cb_ = not_responding_cb; } void set_not_responding_cb(Trigger<> *not_responding_cb) { this->not_responding_cb_ = not_responding_cb; }
void enable_cmux() { this->cmux_ = true; }
void add_init_at_command(const std::string &cmd) { this->init_at_commands_.push_back(cmd); } void add_init_at_command(const std::string &cmd) { this->init_at_commands_.push_back(cmd); }
std::string send_at(const std::string &cmd); std::string send_at(const std::string &cmd);
bool get_imei(std::string &result); bool get_imei(std::string &result);

View file

@ -12,6 +12,7 @@ modem:
apn: orange apn: orange
pin_code: "0000" pin_code: "0000"
enable_on_boot: True enable_on_boot: True
enable_cmux: False
init_at: init_at:
- AT - AT
on_not_responding: on_not_responding: