From b800fbb25f06b01d67e41cde1018957b2474e87c Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 8 Oct 2024 09:55:12 +0200 Subject: [PATCH 1/7] 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 0263a39..65f923c 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -67,7 +67,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting() if(!GSM.begin(_pin, _apn, _login, _pass, _rat, _band)) { Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); - return NetworkConnectionState::ERROR; + return NetworkConnectionState::DISCONNECTED; } Debug.print(DBG_INFO, F("Connected to Network")); return NetworkConnectionState::CONNECTED; From af6f8af8e9c7a0a82cd9aae79be1e42697a86b6b Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 14 Oct 2024 10:38:37 +0200 Subject: [PATCH 2/7] 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 65f923c..4cf5c0a 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -91,6 +91,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnecting() NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnected() { + GSM.end(); if (_keep_alive) { return NetworkConnectionState::INIT; From dcd1616f4fcca7f341d74469779e7382d8cb8309 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 15 Oct 2024 11:32:32 +0200 Subject: [PATCH 3/7] 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 4cf5c0a..439ffee 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -56,6 +56,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 8dcb05da2622e284013250f2a54733a2c58b3e16 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 15 Oct 2024 11:33:11 +0200 Subject: [PATCH 4/7] 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 439ffee..4bab19f 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -46,7 +46,10 @@ CatM1ConnectionHandler::CatM1ConnectionHandler(const char * pin, const char * ap 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 a946dd1308f54bfa808542de8302736c23ee68c6 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 31 Oct 2024 14:44:40 +0100 Subject: [PATCH 5/7] Download arduino ascii logo while connected --- .../ConnectionHandlerDemo.ino | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino index 46a0c9d..2f0971c 100644 --- a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino +++ b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino @@ -130,7 +130,53 @@ void loop() { * which might not guarantee the correct functioning of the ConnectionHandler * object. */ - conMan.check(); + if (conMan.check() != NetworkConnectionState::CONNECTED) { + return; + } + +#if !defined(BOARD_HAS_LORA) + Client &client = conMan.getClient(); + /* arduino.tips */ + IPAddress ip = IPAddress(104, 21, 62, 246); + int port = 80; + + Serial.println("\nStarting connection to server..."); + /* if you get a connection, report back via serial: */ + if (!client.connect(ip, port)) { + Serial.println("unable to connect to server"); + return; + } + + Serial.println("connected to server"); + /* Make a HTTP request: */ + size_t w = client.println("GET /asciilogo.txt HTTP/1.1"); + w += client.println("Host: arduino.tips"); + w += client.println("User-Agent: Arduino"); + w += client.println("Connection: close"); + w += client.println(); + Serial.print("Write size is "); + Serial.println(w); + + /* if there are incoming bytes available from the server, + * read them and print them: + */ + while (client.connected()) { + size_t len = client.available(); + if (len) { + uint8_t buff[len]; + client.read(buff, len); + Serial.write(buff, len); + } + delay(0); + } + + /* if the server's disconnected, stop the client: */ + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + delay(1000); +#endif + } void onNetworkConnect() { From 2d63bb133e885ea4d5a227dc561553e03b38aaa6 Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 15 Nov 2024 13:55:19 +0100 Subject: [PATCH 6/7] catM1: add ping check --- src/CatM1ConnectionHandler.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index 4bab19f..b436ff1 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -63,18 +63,38 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleInit() pinMode(ON_MKR2, OUTPUT); digitalWrite(ON_MKR2, HIGH); #endif + + if(!GSM.begin(_pin, _apn, _login, _pass, _rat, _band)) + { + Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); + return NetworkConnectionState::DISCONNECTED; + } return NetworkConnectionState::CONNECTING; } NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting() { - if(!GSM.begin(_pin, _apn, _login, _pass, _rat, _band)) + int const is_gsm_access_alive = GSM.isConnected(); + if (is_gsm_access_alive != 1) { - Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); + Debug.print(DBG_ERROR, F("GSM connection not alive... disconnecting")); return NetworkConnectionState::DISCONNECTED; } - Debug.print(DBG_INFO, F("Connected to Network")); - return NetworkConnectionState::CONNECTED; + + 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("PING failed")); + Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), 2 * CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); + return NetworkConnectionState::CONNECTING; + } + else + { + Debug.print(DBG_INFO, F("Connected to Network")); + return NetworkConnectionState::CONNECTED; + } } NetworkConnectionState CatM1ConnectionHandler::update_handleConnected() @@ -82,6 +102,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 617b82731a2c3b01733ec593d321e9613e2cc887 Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 15 Nov 2024 13:56:41 +0100 Subject: [PATCH 7/7] catM1: use hardware reset if modem cannot attach to network --- src/CatM1ConnectionHandler.cpp | 5 ++++- src/CatM1ConnectionHandler.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index b436ff1..c64f3a3 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -36,6 +36,7 @@ CatM1ConnectionHandler::CatM1ConnectionHandler(const char * pin, const char * ap , _pass(pass) , _rat(rat) , _band(band) +, _reset(false) { } @@ -64,11 +65,13 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleInit() digitalWrite(ON_MKR2, HIGH); #endif - if(!GSM.begin(_pin, _apn, _login, _pass, _rat, _band)) + if(!GSM.begin(_pin, _apn, _login, _pass, _rat, _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 33ac9fe..d25ebd1 100644 --- a/src/CatM1ConnectionHandler.h +++ b/src/CatM1ConnectionHandler.h @@ -66,6 +66,7 @@ class CatM1ConnectionHandler : public ConnectionHandler RadioAccessTechnologyType _rat; uint32_t _band; + bool _reset; GSMUDP _gsm_udp; GSMClient _gsm_client;