fix pin check

This commit is contained in:
oarcher 2024-08-28 20:15:11 +02:00
parent c166e16911
commit bc7eb17c0b

View file

@ -98,7 +98,7 @@ AtCommandResult ModemComponent::get_imei() {
} }
int ModemComponent::get_baud_rate_() { int ModemComponent::get_baud_rate_() {
AtCommandResult at_command_result = this->send_at("AT+IPR?"); AtCommandResult at_command_result = this->send_at("AT+IPR?", 1000);
const std::string sep = ": "; const std::string sep = ": ";
size_t pos = at_command_result.output.find(sep); size_t pos = at_command_result.output.find(sep);
if (pos == std::string::npos) { if (pos == std::string::npos) {
@ -386,6 +386,7 @@ void ModemComponent::loop() {
ESP_LOGE(TAG, "modem is unable to enter PPP (time left before abort: %.0fs)", time_left_s); ESP_LOGE(TAG, "modem is unable to enter PPP (time left before abort: %.0fs)", time_left_s);
this->stop_ppp_(); this->stop_ppp_();
this->is_modem_connected(); this->is_modem_connected();
next_loop_millis = millis() + 25000; // delay to retry
} }
} else { } else {
ESP_LOGW(TAG, "Waiting for the modem to be attached to a network (time left before abort: %.0fs)", ESP_LOGW(TAG, "Waiting for the modem to be attached to a network (time left before abort: %.0fs)",
@ -399,9 +400,8 @@ void ModemComponent::loop() {
next_loop_millis = millis() + 1000; // delay for next loop next_loop_millis = millis() + 1000; // delay for next loop
// connecting timeout // connecting timeout
if (millis() - this->internal_state_.connect_begin > 15000) { if (millis() - this->internal_state_.connect_begin > 25000) {
ESP_LOGW(TAG, "Connecting via Modem failed! Re-connecting..."); ESP_LOGW(TAG, "Connecting via Modem failed! Re-connecting...");
// TODO: exit data/cmux without error check
connecting = false; connecting = false;
} }
} else { } else {
@ -708,12 +708,12 @@ bool ModemComponent::prepare_sim_() {
ESP_LOGD(TAG, "SIM: %s", output.c_str()); ESP_LOGD(TAG, "SIM: %s", output.c_str());
if ((output.find("+CPIN: READY") != std::string::npos) || (output.find("+CPIN: SIM PIN") != std::string::npos)) { if (output.find("+CPIN: READY") != std::string::npos) {
ESP_LOGD(TAG, "Pin already unlocked");
return true; // pin not needed or already unlocked return true; // pin not needed or already unlocked
} else { } else if (output.find("SIM not inserted") != std::string::npos) {
if (output.find("SIM not inserted") != std::string::npos) { ESP_LOGE(TAG, "sim card missing?");
return false; return false;
}
} }
ESPMODEM_ERROR_CHECK(this->dce->set_pin(this->pin_code_), "Set pin error"); ESPMODEM_ERROR_CHECK(this->dce->set_pin(this->pin_code_), "Set pin error");
@ -721,6 +721,12 @@ bool ModemComponent::prepare_sim_() {
bool pin_ok = false; bool pin_ok = false;
ESPMODEM_ERROR_CHECK(this->dce->read_pin(pin_ok), "Error checking pin"); ESPMODEM_ERROR_CHECK(this->dce->read_pin(pin_ok), "Error checking pin");
if (pin_ok) {
ESP_LOGD(TAG, "SIM pin unlocked");
} else {
ESP_LOGE(TAG, "SIM pin error");
}
return pin_ok; return pin_ok;
} }