code clean

This commit is contained in:
oarcher 2024-07-17 12:34:05 +02:00
parent bd5fd0c12b
commit 521931d0fe
2 changed files with 11 additions and 52 deletions

View file

@ -43,8 +43,6 @@ CONFIG_SCHEMA = cv.All(
cv.Required(CONF_RX_PIN): cv.positive_int,
cv.Required(CONF_MODEL): cv.string,
cv.Required(CONF_APN): cv.string,
# cv.Optional(CONF_ON_SCRIPT): cv.use_id(Script),
# cv.Optional(CONF_OFF_SCRIPT): cv.use_id(Script),
cv.Optional(CONF_DTR_PIN): cv.positive_int,
cv.Optional(CONF_PIN_CODE): cv.string_strict,
cv.Optional(CONF_USERNAME): cv.string,
@ -109,18 +107,6 @@ async def to_code(config):
for cmd in init_at:
cg.add(var.add_init_at_command(cmd))
# if modem_ready := config.get(CONF_READY, None):
# modem_ready_sensor = await cg.get_variable(modem_ready)
# cg.add(var.set_ready_bsensor(modem_ready_sensor))
# if conf_on_script := config.get(CONF_ON_SCRIPT, None):
# on_script = await cg.get_variable(conf_on_script)
# cg.add(var.set_on_script(on_script))
#
# if conf_off_script := config.get(CONF_OFF_SCRIPT, None):
# off_script = await cg.get_variable(conf_off_script)
# cg.add(var.set_off_script(off_script))
cg.add(var.set_model(config[CONF_MODEL]))
cg.add(var.set_apn(config[CONF_APN]))

View file

@ -242,50 +242,23 @@ void ModemComponent::loop() {
case ModemComponentState::STOPPED:
if (this->started_) {
if (!this->modem_ready()) {
// ESP_LOGW(TAG, "Trying to recover dce");
// ESP_ERROR_CHECK_WITHOUT_ABORT(this->dce->recover());
// delay(1000);
// ESP_LOGW(TAG, "Forcing undef mode");
// ESP_ERROR_CHECK_WITHOUT_ABORT(this->dce->set_mode(esp_modem::modem_mode::UNDEF));
// delay(1000);
ESP_LOGW(TAG, "Forcing cmux manual mode mode");
ESP_ERROR_CHECK_WITHOUT_ABORT(this->dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_MODE));
ESP_LOGD(TAG, "Modem not responding. Trying to recover...");
// Errors are not checked, because some commands return FAIL, but make the modem to answer again...
ESP_LOGV(TAG, "Forcing cmux manual mode mode");
this->dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_MODE);
delay(1000); // NOLINT
// // ESP_LOGW(TAG, "Trying to recover dce");
// // ESP_ERROR_CHECK_WITHOUT_ABORT(this->dce->recover());
// // delay(1000);
ESP_LOGW(TAG, "Forcing cmux manual command mode");
ESP_ERROR_CHECK_WITHOUT_ABORT(this->dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_COMMAND));
ESP_LOGV(TAG, "Forcing cmux manual command mode");
this->dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_COMMAND);
delay(1000); // NOLINT
ESP_LOGW(TAG, "Forcing cmux manual exit mode");
ESP_ERROR_CHECK_WITHOUT_ABORT(this->dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_EXIT));
this->dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_EXIT);
delay(1000); // NOLINT
// ESP_LOGW(TAG, "Forcing command mode");
// ESP_ERROR_CHECK_WITHOUT_ABORT(this->dce->set_mode(esp_modem::modem_mode::COMMAND_MODE));
// delay(1000);
// ESP_LOGW(TAG, "Forcing reset");
// this->dce->reset();
// ESP_LOGW(TAG, "Forcing hangup");
// this->dce->hang_up();
// this->send_at("AT+CGATT=0"); // disconnect network
// delay(1000);
// this->send_at("ATH"); // hangup
// delay(1000);
// delay(1000);
// ESP_LOGW(TAG, "Forcing disconnect");
// this->send_at("AT+CGATT=0"); // disconnect network
// delay(1000);
// ESP_LOGW(TAG, "Unable to sync modem");
if (!this->modem_ready()) {
this->on_not_responding_callback_.call();
// if (this->on_script_ != nullptr) {
// ESP_LOGD(TAG, "Executing recover_script");
// this->on_script_->execute();
// } else {
// ESP_LOGE(TAG, "Modem not responding, and no recover_script");
// }
} else {
ESP_LOGD(TAG, "Modem is ready");
}
if (this->modem_ready()) {
ESP_LOGI(TAG, "Modem is ready");
}
} else {
ESP_LOGI(TAG, "Starting modem connection");