This commit is contained in:
Otto Winter 2019-08-31 20:23:35 +02:00
commit 23ff8178a0
No known key found for this signature in database
GPG key ID: DB66C0BE6013F97E

View file

@ -67,12 +67,18 @@ void Sim800LComponent::parse_cmd_(std::string message) {
} }
switch (this->state_) { switch (this->state_) {
case STATE_INIT: case STATE_INIT: {
if (message.compare(0, 6, "+CMTI:") == 0) { // While we were waiting for update to check for messages, this notifies a message
// While we were waiting for update to check for messages, this notifies a message // is available.
// is available. Grab it quickly bool message_available = message.compare(0, 6, "+CMTI:") == 0;
this->state_ = STATE_CHECK_SMS; if (!message_available)
} break;
// Else fall thru ...
}
case STATE_CHECK_SMS:
send_cmd_("AT+CMGL=\"ALL\"");
this->state_ = STATE_PARSE_SMS;
this->parse_index_ = 0;
break; break;
case STATE_DISABLE_ECHO: case STATE_DISABLE_ECHO:
send_cmd_("ATE0"); send_cmd_("ATE0");
@ -95,7 +101,6 @@ void Sim800LComponent::parse_cmd_(std::string message) {
if (registered) { if (registered) {
if (!this->registered_) if (!this->registered_)
ESP_LOGD(TAG, "Registered OK"); ESP_LOGD(TAG, "Registered OK");
send_cmd_("AT+CSQ");
this->state_ = STATE_CSQ; this->state_ = STATE_CSQ;
this->expect_ack_ = true; this->expect_ack_ = true;
} else { } else {
@ -113,6 +118,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
break; break;
} }
case STATE_CSQ: case STATE_CSQ:
send_cmd_("AT+CSQ");
this->state_ = STATE_CSQ_RESPONSE; this->state_ = STATE_CSQ_RESPONSE;
break; break;
case STATE_CSQ_RESPONSE: case STATE_CSQ_RESPONSE:
@ -123,6 +129,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
ESP_LOGD(TAG, "RSSI: %d", this->rssi_); ESP_LOGD(TAG, "RSSI: %d", this->rssi_);
} }
} }
this->expect_ack_ = true;
this->state_ = STATE_CHECK_SMS; this->state_ = STATE_CHECK_SMS;
break; break;
case STATE_PARSE_SMS: case STATE_PARSE_SMS:
@ -209,12 +216,6 @@ void Sim800LComponent::parse_cmd_(std::string message) {
ESP_LOGD(TAG, "Unhandled: %s - %d", message.c_str(), this->state_); ESP_LOGD(TAG, "Unhandled: %s - %d", message.c_str(), this->state_);
break; break;
} }
if (this->state_ == STATE_CHECK_SMS) {
send_cmd_("AT+CMGL=\"ALL\"");
this->state_ = STATE_PARSE_SMS;
this->parse_index_ = 0;
this->expect_ack_ = true;
}
} }
void Sim800LComponent::loop() { void Sim800LComponent::loop() {