From f8756e97d28fc32e31b33063063db05ee0aa07bd Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 8 Oct 2024 09:55:12 +0200 Subject: [PATCH 1/6] catM1: connect or die retrying --- src/CatM1ConnectionHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index 2a63dea..316ee5a 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -74,7 +74,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleInit() _settings.catm1.band)) { Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); - return NetworkConnectionState::ERROR; + return NetworkConnectionState::DISCONNECTED; } return NetworkConnectionState::CONNECTING; } From 2a6cbce0eed572d2255a9171d226de073380d6c7 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 14 Oct 2024 10:38:37 +0200 Subject: [PATCH 2/6] catM1: reset internal state machine --- src/CatM1ConnectionHandler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index 316ee5a..dd8699e 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -123,6 +123,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnecting() NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnected() { + GSM.end(); if (_keep_alive) { return NetworkConnectionState::INIT; From c79c71ec7eb7689f458510dfb95e8b523226af27 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 15 Oct 2024 11:32:32 +0200 Subject: [PATCH 3/6] catM1: add comment about edge control module power on --- src/CatM1ConnectionHandler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index dd8699e..b430034 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -61,6 +61,7 @@ unsigned long CatM1ConnectionHandler::getTime() NetworkConnectionState CatM1ConnectionHandler::update_handleInit() { #if defined (ARDUINO_EDGE_CONTROL) + /* Power on module */ pinMode(ON_MKR2, OUTPUT); digitalWrite(ON_MKR2, HIGH); #endif From c7ca8ee19172a2ad6ceb82ee357a2313837a4953 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 15 Oct 2024 11:33:11 +0200 Subject: [PATCH 4/6] catM1: do not rely on time stored in the modem --- src/CatM1ConnectionHandler.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index b430034..6169d31 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -51,7 +51,10 @@ CatM1ConnectionHandler::CatM1ConnectionHandler( unsigned long CatM1ConnectionHandler::getTime() { - return GSM.getTime(); + /* It is not safe to call GSM.getTime() since we don't know if modem internal + * RTC is in sync with current time. + */ + return 0; } /****************************************************************************** From 7c50a80629674095cfc02f33f9d197d48bc2f2e5 Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 15 Nov 2024 13:55:19 +0100 Subject: [PATCH 5/6] catM1: add ping check by default --- src/CatM1ConnectionHandler.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index 6169d31..7b29e00 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -37,6 +37,8 @@ CatM1ConnectionHandler::CatM1ConnectionHandler( : ConnectionHandler{keep_alive, NetworkAdapter::CATM1} { _settings.type = NetworkAdapter::CATM1; + // To keep the backward compatibility, the user can call enableCheckInternetAvailability(false) for disabling the check + _check_internet_availability = true; strncpy(_settings.catm1.pin, pin, sizeof(_settings.catm1.pin)-1); strncpy(_settings.catm1.apn, apn, sizeof(_settings.catm1.apn)-1); strncpy(_settings.catm1.login, login, sizeof(_settings.catm1.login)-1); @@ -87,19 +89,21 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting() { if (!GSM.isConnected()) { - return NetworkConnectionState::INIT; + Debug.print(DBG_ERROR, F("GSM connection not alive... disconnecting")); + return NetworkConnectionState::DISCONNECTED; } if(!_check_internet_availability){ return NetworkConnectionState::CONNECTED; } - int ping_result = GSM.ping("time.arduino.cc"); + Debug.print(DBG_INFO, F("Sending PING to outer space...")); + int const ping_result = GSM.ping("time.arduino.cc"); Debug.print(DBG_INFO, F("GSM.ping(): %d"), ping_result); if (ping_result < 0) { Debug.print(DBG_ERROR, F("Internet check failed")); - Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); + Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), 2 * CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); return NetworkConnectionState::CONNECTING; } else @@ -114,6 +118,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnected() int const is_gsm_access_alive = GSM.isConnected(); if (is_gsm_access_alive != 1) { + Debug.print(DBG_ERROR, F("GSM connection not alive... disconnecting")); return NetworkConnectionState::DISCONNECTED; } return NetworkConnectionState::CONNECTED; From c38bc16592459bd55256f1fff79513379db78f27 Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 15 Nov 2024 13:56:41 +0100 Subject: [PATCH 6/6] catM1: use hardware reset if modem cannot attach to network --- src/CatM1ConnectionHandler.cpp | 6 +++++- src/CatM1ConnectionHandler.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index 7b29e00..c8bd7fc 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -45,6 +45,7 @@ CatM1ConnectionHandler::CatM1ConnectionHandler( strncpy(_settings.catm1.pass, pass, sizeof(_settings.catm1.pass)-1); _settings.catm1.rat = static_cast(rat); _settings.catm1.band = band; + _reset = false; } /****************************************************************************** @@ -77,11 +78,14 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleInit() _settings.catm1.login, _settings.catm1.pass, static_cast(_settings.catm1.rat) , - _settings.catm1.band)) + _settings.catm1.band, + _reset)) { Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); + _reset = true; return NetworkConnectionState::DISCONNECTED; } + _reset = false; return NetworkConnectionState::CONNECTING; } diff --git a/src/CatM1ConnectionHandler.h b/src/CatM1ConnectionHandler.h index 67f317b..37c9205 100644 --- a/src/CatM1ConnectionHandler.h +++ b/src/CatM1ConnectionHandler.h @@ -60,6 +60,8 @@ class CatM1ConnectionHandler : public ConnectionHandler private: + bool _reset; + GSMUDP _gsm_udp; GSMClient _gsm_client; };