I have the following code that reads the signal strength from a SIM800L GSM modem.
The code works and receives the data from the SIM800L.
However, I must break from the do/While loop if the signal strength (value) is greater than 0.
void getSignal() {
unsigned long start = millis ();
uint8_t signal = sim800l->getSignal();
do {
delay(1000);
signal = sim800l->getSignal();
mySignal = signal;
// if (mySignal > 0) {
// break;
// }
} while (millis () - start <= 10000);// && (mySignal <= 0));
Serial.println("CSQ Timeout");
if (mySignal <= 0) mySignal = 21;
sprintf(txSignal, "%02d", mySignal);
Serial.print(F("txSignal: "));
Serial.println(txSignal);
}
The commented section of code does not work:
// if (mySignal > 0) {
// break;
// }
If the value is <= 0, I then insert a value of 21.
However, the code always times out and inserts the value of 21, even though a valid value has been received from the SIM800L modem.
The Log from the above code illustrates this:
SIM800L : Send "AT+CSQ"
SIM800L : End of transmission
SIM800L : Receive "
+CSQ: 0,0
"
SIM800L : Send "AT+CSQ"
SIM800L : End of transmission
SIM800L : Receive "
+CSQ: 29,0
"
SIM800L : Send "AT+CSQ"
SIM800L : End of transmission
SIM800L : Receive "
+CSQ: 29,0
"
SIM800L : Send "AT+CSQ"
SIM800L : End of transmission
SIM800L : Receive "
+CSQ: 29,0
"
SIM800L : Send "AT+CSQ"
SIM800L : End of transmission
SIM800L : Receive "
+CSQ: 30,0
"
SIM800L : Send "AT+CSQ"
SIM800L : End of transmission
SIM800L : Receive "
+CSQ: 30,0
"
SIM800L : Send "AT+CSQ"
SIM800L : End of transmission
SIM800L : Receive "
+CSQ: 30,0
"
SIM800L : Send "AT+CSQ"
SIM800L : End of transmission
SIM800L : Receive "
+CSQ: 30,0
"
SIM800L : Send "AT+CSQ"
SIM800L : End of transmission
SIM800L : Receive "
+CSQ: 30,0
"
SIM800L : Send "AT+CSQ"
SIM800L : End of transmission
SIM800L : Receive "
+CSQ: 30,0
"
SIM800L : Send "AT+CSQ"
SIM800L : End of transmission
SIM800L : Receive "
+CSQ: 30,0
"
CSQ Timeout
txSignal: 21
I cannot see what I am doing incorrectly.