Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getNetworkStatus fails when it receives Call Ready and SMS Ready messages #109

Open
garageeks opened this issue Oct 9, 2019 · 0 comments

Comments

@garageeks
Copy link

garageeks commented Oct 9, 2019

  • Arduino board: bare ATMEGA328PB, MiniCore board definition

  • Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.8

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too):

fona.getNetworkStatus(), used to poll the modem whether it is registered on the network or not, fails if issued right after initialization (fona.begin command).
The reason is because the SIM800 modem by itself writes "Call Ready" and "SMS Ready" messages, and getNetworkStatus() doesn't handle the messages properly, therefore it is returning a value of 100, sometimes forever, maybe because the replyBuffer is not cleaned.

This is the outcome with a state machine:

GPRS1 - TRY 1/3 - Modem init... ---> AT <--- ⸮ ---> AT <--- AT ---> AT <--- AT ---> ATE0 <--- ATE0 ---> ATE0 <--- OK Modem OK ---> AT+CSCLK=1 <--- OK ---> AT+CREG? <--- Call Ready GPRS3 - TRY 1/60 - Net status 100: Failed ---> AT+CREG? <--- SMS Ready GPRS3 - TRY 1/60 - Net status 100: Failed ---> AT+CREG? <--- GPRS3 - TRY 1/60 - Net status 100: Failed ---> AT+CREG? <--- GPRS3 - TRY 1/60 - Net status 100: Failed ---> AT+CREG? <--- ---> AT+CREG? <--- +CREG: 0,1 GPRS3 - TRY 1/60 - Net status 1: Registered (home)

Proposed solution: in getNetworkStatus function, use readline(100) command to eat garbage in the buffer before issuing the AT+CREG? command, as this:

`
uint8_t Adafruit_FONA::getNetworkStatus(void) {
uint16_t status;
readline(100);
if (! sendParseReply(F("AT+CREG?"), F("+CREG: "), &status, ',', 1)) return 100;

return status;
}
`

Result: getNetworkStatus always recover when receiving those "Call Ready" messages with a small penalty (timeout of 100ms)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant