From 3885f182940329c1697150bb7565551bc6c071d6 Mon Sep 17 00:00:00 2001 From: maidnl Date: Tue, 28 Jan 2025 17:18:26 +0100 Subject: [PATCH 1/6] introducing Cellular possibility on Connection Handler Demo --- examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino index 46a0c9d4..edc9c11d 100644 --- a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino +++ b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino @@ -35,7 +35,8 @@ #define CONN_TOGGLE_MS 60000 #if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \ - defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)) + defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT) \ + || defined(BOARD_HAS_CELLULAR)) #error "Please check Arduino Connection Handler supported boards list: https://github.com/arduino-libraries/Arduino_ConnectionHandler/blob/master/README.md" #endif From 1cecbf270f72ba7f5b42ad7750b06c5c4a2b5042 Mon Sep 17 00:00:00 2001 From: maidnl Date: Tue, 28 Jan 2025 17:19:41 +0100 Subject: [PATCH 2/6] Introducing Arduino Opta Cellular as possible connection source for Arduino Opta --- src/CellularConnectionHandler.cpp | 31 ++++++++++++++++++++++++++++++ src/ConnectionHandlerDefinitions.h | 1 + 2 files changed, 32 insertions(+) diff --git a/src/CellularConnectionHandler.cpp b/src/CellularConnectionHandler.cpp index b73f5866..ecbc3e2c 100644 --- a/src/CellularConnectionHandler.cpp +++ b/src/CellularConnectionHandler.cpp @@ -54,9 +54,40 @@ UDP & CellularConnectionHandler::getUDP() PROTECTED MEMBER FUNCTIONS ******************************************************************************/ +#if defined(ARDUINO_OPTA) && defined(BOARD_HAS_CELLULAR) +CellularExpansion ce; +static void beginOptaCellular() { + static bool first_call = true; + + if(first_call) { + first_call = false; + OptaController.registerCustomExpansion(CellularExpansion::getProduct(), + CellularExpansion::makeExpansion, + CellularExpansion::startUp); + OptaController.begin(); + delay(500); + for (int i = 0; i < OptaController.getExpansionNum(); i++) { + ce = OptaController.getExpansion(i); + if(ce) { + ce.ctrlModem(true); + delay(100); + break; + } + } + } + else { + OptaController.update(); + } +} +#endif + NetworkConnectionState CellularConnectionHandler::update_handleInit() { +#if defined(ARDUINO_OPTA) && defined(BOARD_HAS_CELLULAR) + beginOptaCellular(); +#else _cellular.begin(); +#endif _cellular.setDebugStream(Serial); if (strlen(_settings.cell.pin) > 0 && !_cellular.unlockSIM(_settings.cell.pin)) { DEBUG_ERROR(F("SIM not present or wrong PIN")); diff --git a/src/ConnectionHandlerDefinitions.h b/src/ConnectionHandlerDefinitions.h index 1534e473..588bbd4f 100644 --- a/src/ConnectionHandlerDefinitions.h +++ b/src/ConnectionHandlerDefinitions.h @@ -74,6 +74,7 @@ #if defined(ARDUINO_OPTA) #define BOARD_HAS_WIFI #define BOARD_HAS_ETHERNET + #define BOARD_HAS_CELLULAR #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD #define NETWORK_IDLE_STATUS WL_IDLE_STATUS #define NETWORK_CONNECTED WL_CONNECTED From 335a553d566e9e8b6b825f7579e88e46fb32fd03 Mon Sep 17 00:00:00 2001 From: Daniele <34984733+maidnl@users.noreply.github.com> Date: Wed, 29 Jan 2025 11:19:11 +0100 Subject: [PATCH 3/6] Update src/CellularConnectionHandler.cpp removed redundant preprocessor #if defined Co-authored-by: Andrea Gilardoni <4046444+andreagilardoni@users.noreply.github.com> --- src/CellularConnectionHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CellularConnectionHandler.cpp b/src/CellularConnectionHandler.cpp index ecbc3e2c..71c8e7b3 100644 --- a/src/CellularConnectionHandler.cpp +++ b/src/CellularConnectionHandler.cpp @@ -54,7 +54,7 @@ UDP & CellularConnectionHandler::getUDP() PROTECTED MEMBER FUNCTIONS ******************************************************************************/ -#if defined(ARDUINO_OPTA) && defined(BOARD_HAS_CELLULAR) +#if defined(ARDUINO_OPTA) CellularExpansion ce; static void beginOptaCellular() { static bool first_call = true; From eb26ac8f8a474889b787ca9e97fdd0bb8447bea6 Mon Sep 17 00:00:00 2001 From: maidnl Date: Fri, 31 Jan 2025 14:08:29 +0100 Subject: [PATCH 4/6] handled the case the Opta Cellular is not present If the Opta Cellular is not present the Opta crashed due to some impossible communication or timeout in the _cellular.unlockSIM() function call With this change if the Cellular is not present no useless call to _cellular.unlockSIM() is performed and this prevent the crash --- src/CellularConnectionHandler.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/CellularConnectionHandler.cpp b/src/CellularConnectionHandler.cpp index 71c8e7b3..020fc330 100644 --- a/src/CellularConnectionHandler.cpp +++ b/src/CellularConnectionHandler.cpp @@ -83,12 +83,27 @@ static void beginOptaCellular() { NetworkConnectionState CellularConnectionHandler::update_handleInit() { -#if defined(ARDUINO_OPTA) && defined(BOARD_HAS_CELLULAR) +#if defined(ARDUINO_OPTA) beginOptaCellular(); #else _cellular.begin(); #endif _cellular.setDebugStream(Serial); + +#if defined(ARDUINO_OPTA) + /* in case Opta Cellular is not wired this check on ce prevent the call + to unlockSIM that cause a crash in the Opta (deep due to the missing + communication with the modem) */ + if(ce) { + if (String(_pin).length() > 0 && !_cellular.unlockSIM(_pin)) { + Debug.print(DBG_ERROR, F("SIM not present or wrong PIN")); + return NetworkConnectionState::ERROR; + } + } + else { + return NetworkConnectionState::ERROR; + } +#else if (strlen(_settings.cell.pin) > 0 && !_cellular.unlockSIM(_settings.cell.pin)) { DEBUG_ERROR(F("SIM not present or wrong PIN")); return NetworkConnectionState::ERROR; @@ -98,6 +113,7 @@ NetworkConnectionState CellularConnectionHandler::update_handleInit() DEBUG_ERROR(F("The board was not able to register to the network...")); return NetworkConnectionState::ERROR; } +#endif DEBUG_INFO(F("Connected to Network")); return NetworkConnectionState::CONNECTING; } From c8f87a25ae7b8095b55496a3b0a888c2a169abdb Mon Sep 17 00:00:00 2001 From: maidnl Date: Mon, 22 Sep 2025 15:36:22 +0200 Subject: [PATCH 5/6] Added Opta Cellular as Cellular connection handler --- src/CellularConnectionHandler.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/CellularConnectionHandler.h b/src/CellularConnectionHandler.h index 7a5f00b1..2594c8a2 100644 --- a/src/CellularConnectionHandler.h +++ b/src/CellularConnectionHandler.h @@ -20,6 +20,8 @@ #if defined(ARDUINO_PORTENTA_C33) || defined(ARDUINO_PORTENTA_H7_M7) #include +#elif defined(ARDUINO_OPTA) +#include #endif #ifndef BOARD_HAS_CELLULAR @@ -53,7 +55,16 @@ class CellularConnectionHandler : public ConnectionHandler private: + const char * _pin; + const char * _apn; + const char * _login; + const char * _pass; + + #if defined(ARDUINO_OPTA) + ArduinoCellular &_cellular = CellularExpansion::getCellular(); + #else ArduinoCellular _cellular; + #endif TinyGsmClient _gsm_client = _cellular.getNetworkClient(); }; From e18e9e82a17e04594e44f40b0657ac624249be90 Mon Sep 17 00:00:00 2001 From: maidnl Date: Tue, 14 Oct 2025 15:18:42 +0200 Subject: [PATCH 6/6] Added Arduino_OptaCellular as dependecy --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 9ad0dc11..d8c527c9 100644 --- a/library.properties +++ b/library.properties @@ -7,4 +7,4 @@ paragraph=Originally part of ArduinoIoTCloud category=Communication url=https://github.com/arduino-libraries/Arduino_ConnectionHandler architectures=samd,esp32,esp8266,mbed,megaavr,mbed_nano,mbed_portenta,mbed_nicla,mbed_opta,mbed_giga,renesas_portenta,renesas_uno,mbed_edge,stm32,rp2040 -depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN, Blues Wireless Notecard (>=1.6.3) +depends=Arduino_OptaCellular, Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN, Blues Wireless Notecard (>=1.6.3)