From 1291a4407dca0d8f8341e2ffed09168b3f92b08e Mon Sep 17 00:00:00 2001 From: Fabrice Fontaine Date: Fri, 5 Mar 2021 18:59:29 +0100 Subject: [PATCH] src/TinyGsmModem.tpp: fix registration state As specified in the ETSI standards (e.g. ETSI TS 127 001), CREG and CEREG responses can contain optional parameters: +CEREG: ,[,,[,]] For example, the Monarch GMS01Q returns the following response: +CEREG: 2,1,"3982","00DF3B03",7 This results in TinyGSM setting state as '7' instead of 1 preventing any connection. Fix this by picking the next integer after the first ',' which will always works (with or without optional parameters) Signed-off-by: Fabrice Fontaine --- src/TinyGsmModem.tpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TinyGsmModem.tpp b/src/TinyGsmModem.tpp index 1f2f928..4089c6e 100644 --- a/src/TinyGsmModem.tpp +++ b/src/TinyGsmModem.tpp @@ -192,7 +192,7 @@ class TinyGsmModem { GF("+CEREG:")); if (resp != 1 && resp != 2 && resp != 3) { return -1; } thisModem().streamSkipUntil(','); /* Skip format (0) */ - int status = thisModem().streamGetIntBefore('\n'); + int status = thisModem().stream.parseInt(); thisModem().waitResponse(); return status; }