From 6070dd836b4a312e1afd68c97e24851601343381 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Fri, 24 Jul 2020 10:37:50 +0200 Subject: [PATCH 001/203] Add PortentaH7 target (#37) Co-authored-by: Martino Facchin --- src/Arduino_ConnectionHandler.h | 10 ++++++++++ src/Arduino_WiFiConnectionHandler.cpp | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 64520189..195ab13f 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -40,6 +40,16 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION #endif +#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) + #include + #include + + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + #ifdef ARDUINO_SAMD_MKRGSM1400 #include #define BOARD_HAS_GSM diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 24bbceb0..728bc062 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -65,12 +65,15 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() Debug.print(DBG_ERROR, "Current WiFi Firmware: %s", WiFi.firmwareVersion()); +#if defined(WIFI_FIRMWARE_VERSION_REQUIRED) if (WiFi.firmwareVersion() < WIFI_FIRMWARE_VERSION_REQUIRED) { Debug.print(DBG_ERROR, "Latest WiFi Firmware: %s", WIFI_FIRMWARE_VERSION_REQUIRED); Debug.print(DBG_ERROR, "Please update to the latest version for best performance."); delay(5000); } +#endif + #else Debug.print(DBG_ERROR, "WiFi status ESP: %d", WiFi.status()); WiFi.disconnect(); From 43b3ee2b164e8e3b4a3dba975c7025bab3327bed Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 27 Jul 2020 13:25:23 +0200 Subject: [PATCH 002/203] Releasing v0.4.8 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index ca969568..d491568b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.4.7 +version=0.4.8 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From e023315d9cb378a625d68d45e5f1f3b4778ba11f Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 26 Aug 2020 10:32:12 +0200 Subject: [PATCH 003/203] Use flash strings for storing debug messages in order to conserve RAM (#39) --- src/Arduino_GSMConnectionHandler.cpp | 20 +++++++-------- src/Arduino_LoRaConnectionHandler.cpp | 36 +++++++++++++-------------- src/Arduino_NBConnectionHandler.cpp | 18 +++++++------- src/Arduino_WiFiConnectionHandler.cpp | 26 +++++++++---------- 4 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/Arduino_GSMConnectionHandler.cpp b/src/Arduino_GSMConnectionHandler.cpp index 629699b6..67afa14f 100644 --- a/src/Arduino_GSMConnectionHandler.cpp +++ b/src/Arduino_GSMConnectionHandler.cpp @@ -60,19 +60,19 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit() { if (_gsm.begin(_pin) != GSM_READY) { - Debug.print(DBG_ERROR, "SIM not present or wrong PIN"); + Debug.print(DBG_ERROR, F("SIM not present or wrong PIN")); return NetworkConnectionState::ERROR; } - Debug.print(DBG_INFO, "SIM card ok"); + Debug.print(DBG_INFO, F("SIM card ok")); _gsm.setTimeout(GSM_TIMEOUT); GSM3_NetworkStatus_t const network_status = _gprs.attachGPRS(_apn, _login, _pass, true); - Debug.print(DBG_DEBUG, "GPRS.attachGPRS(): %d", network_status); + Debug.print(DBG_DEBUG, F("GPRS.attachGPRS(): %d"), network_status); if (network_status == GSM3_NetworkStatus_t::ERROR) { - Debug.print(DBG_ERROR, "GPRS attach failed"); - Debug.print(DBG_ERROR, "Make sure the antenna is connected and reset your board."); + Debug.print(DBG_ERROR, F("GPRS attach failed")); + Debug.print(DBG_ERROR, F("Make sure the antenna is connected and reset your board.")); return NetworkConnectionState::ERROR; } @@ -81,18 +81,18 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit() NetworkConnectionState GSMConnectionHandler::update_handleConnecting() { - Debug.print(DBG_INFO, "Sending PING to outer space..."); + Debug.print(DBG_INFO, F("Sending PING to outer space...")); int const ping_result = _gprs.ping("time.arduino.cc"); - Debug.print(DBG_INFO, "GPRS.ping(): %d", ping_result); + Debug.print(DBG_INFO, F("GPRS.ping(): %d"), ping_result); if (ping_result < 0) { - Debug.print(DBG_ERROR, "PING failed"); - Debug.print(DBG_INFO, "Retrying in \"%d\" milliseconds", CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); + Debug.print(DBG_ERROR, F("PING failed")); + Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); return NetworkConnectionState::CONNECTING; } else { - Debug.print(DBG_INFO, "Connected to GPRS Network"); + Debug.print(DBG_INFO, F("Connected to GPRS Network")); return NetworkConnectionState::CONNECTED; } } diff --git a/src/Arduino_LoRaConnectionHandler.cpp b/src/Arduino_LoRaConnectionHandler.cpp index d3b86c97..c0183e3e 100644 --- a/src/Arduino_LoRaConnectionHandler.cpp +++ b/src/Arduino_LoRaConnectionHandler.cpp @@ -68,20 +68,20 @@ int LoRaConnectionHandler::write(const uint8_t * buf, size_t size) { switch (err) { - case LoRaCommunicationError::LORA_ERROR_ACK_NOT_RECEIVED: Debug.print(DBG_ERROR, "Message ack was not received, the message could not be delivered"); break; - case LoRaCommunicationError::LORA_ERROR_GENERIC: Debug.print(DBG_ERROR, "LoRa generic error (LORA_ERROR)"); break; - case LoRaCommunicationError::LORA_ERROR_WRONG_PARAM: Debug.print(DBG_ERROR, "LoRa malformed param error (LORA_ERROR_PARAM"); break; - case LoRaCommunicationError::LORA_ERROR_COMMUNICATION_BUSY: Debug.print(DBG_ERROR, "LoRa chip is busy (LORA_ERROR_BUSY)"); break; - case LoRaCommunicationError::LORA_ERROR_MESSAGE_OVERFLOW: Debug.print(DBG_ERROR, "LoRa chip overflow error (LORA_ERROR_OVERFLOW)"); break; - case LoRaCommunicationError::LORA_ERROR_NO_NETWORK_AVAILABLE: Debug.print(DBG_ERROR, "LoRa no network error (LORA_ERROR_NO_NETWORK)"); break; - case LoRaCommunicationError::LORA_ERROR_RX_PACKET: Debug.print(DBG_ERROR, "LoRa rx error (LORA_ERROR_RX)"); break; - case LoRaCommunicationError::LORA_ERROR_REASON_UNKNOWN: Debug.print(DBG_ERROR, "LoRa unknown error (LORA_ERROR_UNKNOWN)"); break; - case LoRaCommunicationError::LORA_ERROR_MAX_PACKET_SIZE: Debug.print(DBG_ERROR, "Message length is bigger than max LoRa packet!"); break; + case LoRaCommunicationError::LORA_ERROR_ACK_NOT_RECEIVED: Debug.print(DBG_ERROR, F("Message ack was not received, the message could not be delivered")); break; + case LoRaCommunicationError::LORA_ERROR_GENERIC: Debug.print(DBG_ERROR, F("LoRa generic error (LORA_ERROR)")); break; + case LoRaCommunicationError::LORA_ERROR_WRONG_PARAM: Debug.print(DBG_ERROR, F("LoRa malformed param error (LORA_ERROR_PARAM")); break; + case LoRaCommunicationError::LORA_ERROR_COMMUNICATION_BUSY: Debug.print(DBG_ERROR, F("LoRa chip is busy (LORA_ERROR_BUSY)")); break; + case LoRaCommunicationError::LORA_ERROR_MESSAGE_OVERFLOW: Debug.print(DBG_ERROR, F("LoRa chip overflow error (LORA_ERROR_OVERFLOW)")); break; + case LoRaCommunicationError::LORA_ERROR_NO_NETWORK_AVAILABLE: Debug.print(DBG_ERROR, F("LoRa no network error (LORA_ERROR_NO_NETWORK)")); break; + case LoRaCommunicationError::LORA_ERROR_RX_PACKET: Debug.print(DBG_ERROR, F("LoRa rx error (LORA_ERROR_RX)")); break; + case LoRaCommunicationError::LORA_ERROR_REASON_UNKNOWN: Debug.print(DBG_ERROR, F("LoRa unknown error (LORA_ERROR_UNKNOWN)")); break; + case LoRaCommunicationError::LORA_ERROR_MAX_PACKET_SIZE: Debug.print(DBG_ERROR, F("Message length is bigger than max LoRa packet!")); break; } } else { - Debug.print(DBG_INFO, "Message sent correctly!"); + Debug.print(DBG_INFO, F("Message sent correctly!")); } return err; } @@ -104,14 +104,14 @@ NetworkConnectionState LoRaConnectionHandler::update_handleInit() { if (!_modem.begin(_band)) { - Debug.print(DBG_ERROR, "Something went wrong; are you indoor? Move near a window, then reset and retry."); + Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry.")); return NetworkConnectionState::ERROR; } //A delay is required between _modem.begin(band) and _modem.joinOTAA(appeui, appkey) in order to let the chip to be correctly initialized before the connection attempt delay(100); _modem.configureClass(_device_class); delay(100); - Debug.print(DBG_INFO, "Connecting to the network"); + Debug.print(DBG_INFO, F("Connecting to the network")); return NetworkConnectionState::CONNECTING; } @@ -120,12 +120,12 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnecting() bool const network_status = _modem.joinOTAA(_appeui, _appkey); if (network_status != true) { - Debug.print(DBG_ERROR, "Something went wrong; are you indoor? Move near a window, then reset and retry."); + Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry.")); return NetworkConnectionState::ERROR; } else { - Debug.print(DBG_INFO, "Connected to the network"); + Debug.print(DBG_INFO, F("Connected to the network")); return NetworkConnectionState::CONNECTED; } } @@ -135,10 +135,10 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnected() bool const network_status = _modem.connected(); if (network_status != true) { - Debug.print(DBG_ERROR, "Connection to the network lost."); + Debug.print(DBG_ERROR, F("Connection to the network lost.")); if (_keep_alive) { - Debug.print(DBG_ERROR, "Attempting reconnection"); + Debug.print(DBG_ERROR, F("Attempting reconnection")); } return NetworkConnectionState::DISCONNECTED; } @@ -147,10 +147,10 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnected() NetworkConnectionState LoRaConnectionHandler::update_handleDisconnecting() { - Debug.print(DBG_ERROR, "Connection to the network lost."); + Debug.print(DBG_ERROR, F("Connection to the network lost.")); if (_keep_alive) { - Debug.print(DBG_ERROR, "Attempting reconnection"); + Debug.print(DBG_ERROR, F("Attempting reconnection")); } return NetworkConnectionState::DISCONNECTED; } diff --git a/src/Arduino_NBConnectionHandler.cpp b/src/Arduino_NBConnectionHandler.cpp index b3c719dd..a4d8765b 100644 --- a/src/Arduino_NBConnectionHandler.cpp +++ b/src/Arduino_NBConnectionHandler.cpp @@ -71,13 +71,13 @@ NetworkConnectionState NBConnectionHandler::update_handleInit() { if (_nb.begin(_pin, _apn, _login, _pass) == NB_READY) { - Debug.print(DBG_INFO, "SIM card ok"); + Debug.print(DBG_INFO, F("SIM card ok")); _nb.setTimeout(NB_TIMEOUT); return NetworkConnectionState::CONNECTING; } else { - Debug.print(DBG_ERROR, "SIM not present or wrong PIN"); + Debug.print(DBG_ERROR, F("SIM not present or wrong PIN")); return NetworkConnectionState::ERROR; } } @@ -85,15 +85,15 @@ NetworkConnectionState NBConnectionHandler::update_handleInit() NetworkConnectionState NBConnectionHandler::update_handleConnecting() { NB_NetworkStatus_t const network_status = _nb_gprs.attachGPRS(true); - Debug.print(DBG_DEBUG, "GPRS.attachGPRS(): %d", network_status); + Debug.print(DBG_DEBUG, F("GPRS.attachGPRS(): %d"), network_status); if (network_status == NB_NetworkStatus_t::ERROR) { - Debug.print(DBG_ERROR, "GPRS.attachGPRS() failed"); + Debug.print(DBG_ERROR, F("GPRS.attachGPRS() failed")); return NetworkConnectionState::ERROR; } else { - Debug.print(DBG_INFO, "Connected to GPRS Network"); + Debug.print(DBG_INFO, F("Connected to GPRS Network")); return NetworkConnectionState::CONNECTED; } } @@ -101,22 +101,22 @@ NetworkConnectionState NBConnectionHandler::update_handleConnecting() NetworkConnectionState NBConnectionHandler::update_handleConnected() { int const nb_is_access_alive = _nb.isAccessAlive(); - Debug.print(DBG_VERBOSE, "GPRS.isAccessAlive(): %d", nb_is_access_alive); + Debug.print(DBG_VERBOSE, F("GPRS.isAccessAlive(): %d"), nb_is_access_alive); if (nb_is_access_alive != 1) { - Debug.print(DBG_INFO, "Disconnected from cellular network"); + Debug.print(DBG_INFO, F("Disconnected from cellular network")); return NetworkConnectionState::DISCONNECTED; } else { - Debug.print(DBG_VERBOSE, "Connected to Cellular Network"); + Debug.print(DBG_VERBOSE, F("Connected to Cellular Network")); return NetworkConnectionState::CONNECTED; } } NetworkConnectionState NBConnectionHandler::update_handleDisconnecting() { - Debug.print(DBG_VERBOSE, "Disconnecting from Cellular Network"); + Debug.print(DBG_VERBOSE, F("Disconnecting from Cellular Network")); _nb.shutdown(); return NetworkConnectionState::DISCONNECTED; } diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 728bc062..8cfb2f06 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -55,27 +55,27 @@ unsigned long WiFiConnectionHandler::getTime() NetworkConnectionState WiFiConnectionHandler::update_handleInit() { #ifndef BOARD_ESP8266 - Debug.print(DBG_INFO, "WiFi.status(): %d", WiFi.status()); + Debug.print(DBG_INFO, F("WiFi.status(): %d"), WiFi.status()); if (WiFi.status() == NETWORK_HARDWARE_ERROR) { - Debug.print(DBG_ERROR, "WiFi Hardware failure.\nMake sure you are using a WiFi enabled board/shield."); - Debug.print(DBG_ERROR, "Then reset and retry."); + Debug.print(DBG_ERROR, F("WiFi Hardware failure.\nMake sure you are using a WiFi enabled board/shield.")); + Debug.print(DBG_ERROR, F("Then reset and retry.")); return NetworkConnectionState::ERROR; } - Debug.print(DBG_ERROR, "Current WiFi Firmware: %s", WiFi.firmwareVersion()); + Debug.print(DBG_ERROR, F("Current WiFi Firmware: %s"), WiFi.firmwareVersion()); #if defined(WIFI_FIRMWARE_VERSION_REQUIRED) if (WiFi.firmwareVersion() < WIFI_FIRMWARE_VERSION_REQUIRED) { - Debug.print(DBG_ERROR, "Latest WiFi Firmware: %s", WIFI_FIRMWARE_VERSION_REQUIRED); - Debug.print(DBG_ERROR, "Please update to the latest version for best performance."); + Debug.print(DBG_ERROR, F("Latest WiFi Firmware: %s"), WIFI_FIRMWARE_VERSION_REQUIRED); + Debug.print(DBG_ERROR, F("Please update to the latest version for best performance.")); delay(5000); } #endif #else - Debug.print(DBG_ERROR, "WiFi status ESP: %d", WiFi.status()); + Debug.print(DBG_ERROR, F("WiFi status ESP: %d"), WiFi.status()); WiFi.disconnect(); delay(300); WiFi.begin(_ssid, _pass); @@ -96,13 +96,13 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() if (WiFi.status() != NETWORK_CONNECTED) { - Debug.print(DBG_ERROR, "Connection to \"%s\" failed", _ssid); - Debug.print(DBG_INFO, "Retrying in \"%d\" milliseconds", CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); + Debug.print(DBG_ERROR, F("Connection to \"%s\" failed"), _ssid); + Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); return NetworkConnectionState::CONNECTING; } else { - Debug.print(DBG_INFO, "Connected to \"%s\"", _ssid); + Debug.print(DBG_INFO, F("Connected to \"%s\""), _ssid); #ifdef BOARD_ESP8266 configTime(0, 0, "time.arduino.cc", "pool.ntp.org", "time.nist.gov"); #endif @@ -114,12 +114,12 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnected() { if (WiFi.status() != WL_CONNECTED) { - Debug.print(DBG_VERBOSE, "WiFi.status(): %d", WiFi.status()); - Debug.print(DBG_ERROR, "Connection to \"%s\" lost.", _ssid); + Debug.print(DBG_VERBOSE, F("WiFi.status(): %d"), WiFi.status()); + Debug.print(DBG_ERROR, F("Connection to \"%s\" lost."), _ssid); if (_keep_alive) { - Debug.print(DBG_ERROR, "Attempting reconnection"); + Debug.print(DBG_ERROR, F("Attempting reconnection")); } return NetworkConnectionState::DISCONNECTED; From 66da3c6c8865e22acaa4fc0cc368676dd0cfaa51 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 26 Aug 2020 10:33:46 +0200 Subject: [PATCH 004/203] Release v0.4.9 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index d491568b..8ce2af33 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.4.8 +version=0.4.9 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 93ef165cf150775f03daf17f27a8364b093c1678 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 31 Aug 2020 07:16:07 -0700 Subject: [PATCH 005/203] Add Portenta H7 boards to matrix jobs in Compile Examples CI workflow The library examples will be compiled for Portenta H7 (M7 core) and Portenta H7 (M4 core), using the Arduino mbed OS-enabled boards platform from the tip of its repository's default branch. --- .github/workflows/compile-examples.yml | 89 ++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 11 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index f5876041..4be23b63 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -18,28 +18,95 @@ jobs: env: LIBRARIES: Arduino_DebugUtils WiFi101 WiFiNINA MKRGSM MKRNB MKRWAN + ARDUINOCORE_MBED_STAGING_PATH: extras/ArduinoCore-mbed + ARDUINOCORE_API_STAGING_PATH: extras/ArduinoCore-API strategy: matrix: - fqbn: [ - "arduino:samd:mkr1000", - "arduino:samd:mkrwifi1010", - "arduino:samd:nano_33_iot", - "arduino:samd:mkrgsm1400", - "arduino:samd:mkrnb1500", - "arduino:samd:mkrwan1300", - "arduino:samd:mkrwan1310", - '"esp8266:esp8266:huzzah" "https://arduino.esp8266.com/stable/package_esp8266com_index.json"' - ] + board: + - fqbn: "arduino:samd:mkr1000" + platform-name: arduino:samd + - fqbn: "arduino:samd:mkrwifi1010" + platform-name: arduino:samd + - fqbn: "arduino:samd:nano_33_iot" + platform-name: arduino:samd + - fqbn: "arduino:samd:mkrgsm1400" + platform-name: arduino:samd + - fqbn: "arduino:samd:mkrnb1500" + platform-name: arduino:samd + - fqbn: "arduino:samd:mkrwan1300" + platform-name: arduino:samd + - fqbn: "arduino:samd:mkrwan1310" + platform-name: arduino:samd + - fqbn: "arduino-beta:mbed:envie_m7" + platform-name: arduino-beta:mbed + - fqbn: "arduino-beta:mbed:envie_m4" + platform-name: arduino-beta:mbed + - fqbn: "esp8266:esp8266:huzzah" + platform-name: esp8266:esp8266 + + # Make board type-specific customizations to the matrix jobs + include: + - board: + platform-name: arduino:samd + platforms: | + # Install Arduino SAMD Boards via Boards Manager + - name: arduino:samd + - board: + platform-name: arduino-beta:mbed + platforms: | + # Install Arduino mbed-Enabled Boards via Boards Manager for the toolchain + - name: arduino-beta:mbed + # Overwrite the Arduino mbed-Enabled Boards release version with version from the tip of the default branch (located in local path because of the need to first install ArduinoCore-API) + - source-path: extras/ArduinoCore-mbed + name: arduino-beta:mbed + - board: + platform-name: esp8266:esp8266 + platforms: | + # Install ESP8266 platform via Boards Manager + - name: esp8266:esp8266 + source-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json steps: - uses: actions/checkout@v1 with: fetch-depth: 1 + # It's necessary to checkout the platform before installing it so that the ArduinoCore-API dependency can be added + - name: Checkout ArduinoCore-mbed + # this step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used + if: matrix.board.platform-name == 'arduino-beta:mbed' + uses: actions/checkout@v2 + with: + repository: arduino/ArduinoCore-mbed + # The arduino/actions/libraries/compile-examples action will install the platform from this path + path: ${{ env.ARDUINOCORE_MBED_STAGING_PATH }} + + - name: Remove ArduinoCore-API symlink from Arduino mbed-Enabled Boards platform + # This step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used + if: matrix.board.platform-name == 'arduino-beta:mbed' + run: rm "${{ env.ARDUINOCORE_MBED_STAGING_PATH }}/cores/arduino/api" + + - name: Checkout ArduinoCore-API + # This step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used + if: matrix.board.platform-name == 'arduino-beta:mbed' + uses: actions/checkout@v2 + with: + repository: arduino/ArduinoCore-API + # As specified at https://github.com/arduino/ArduinoCore-mbed/blob/master/README.md#installation + ref: namespace_arduino + path: ${{ env.ARDUINOCORE_API_STAGING_PATH }} + + - name: Install ArduinoCore-API + # This step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used + if: matrix.board.platform-name == 'arduino-beta:mbed' + run: | + mv "${{ env.ARDUINOCORE_API_STAGING_PATH }}/api" "${{ env.ARDUINOCORE_MBED_STAGING_PATH }}/cores/arduino" + - name: Compile examples uses: arduino/actions/libraries/compile-examples@master with: - fqbn: ${{ matrix.fqbn }} + platforms: ${{ matrix.platforms }} + fqbn: ${{ matrix.board.fqbn }} libraries: ${{ env.LIBRARIES }} size-report-sketch: 'ConnectionHandlerDemo' enable-size-deltas-report: 'true' From 78e23aab0029fef61e9192ed4a811dc1339ad74b Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 15 Oct 2020 05:23:41 -0700 Subject: [PATCH 006/203] Update Portenta platform in Compile Examples CI workflow The beta phase `arduino-beta:mbed` boards platform of the Portenta H7 has been deprecated, which will cause platform installation during the compilation check CI to fail if the old name is used. --- .github/workflows/compile-examples.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 4be23b63..75855f2f 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -37,10 +37,10 @@ jobs: platform-name: arduino:samd - fqbn: "arduino:samd:mkrwan1310" platform-name: arduino:samd - - fqbn: "arduino-beta:mbed:envie_m7" - platform-name: arduino-beta:mbed - - fqbn: "arduino-beta:mbed:envie_m4" - platform-name: arduino-beta:mbed + - fqbn: "arduino:mbed:envie_m7" + platform-name: arduino:mbed + - fqbn: "arduino:mbed:envie_m4" + platform-name: arduino:mbed - fqbn: "esp8266:esp8266:huzzah" platform-name: esp8266:esp8266 @@ -52,13 +52,13 @@ jobs: # Install Arduino SAMD Boards via Boards Manager - name: arduino:samd - board: - platform-name: arduino-beta:mbed + platform-name: arduino:mbed platforms: | # Install Arduino mbed-Enabled Boards via Boards Manager for the toolchain - - name: arduino-beta:mbed + - name: arduino:mbed # Overwrite the Arduino mbed-Enabled Boards release version with version from the tip of the default branch (located in local path because of the need to first install ArduinoCore-API) - source-path: extras/ArduinoCore-mbed - name: arduino-beta:mbed + name: arduino:mbed - board: platform-name: esp8266:esp8266 platforms: | @@ -74,7 +74,7 @@ jobs: # It's necessary to checkout the platform before installing it so that the ArduinoCore-API dependency can be added - name: Checkout ArduinoCore-mbed # this step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used - if: matrix.board.platform-name == 'arduino-beta:mbed' + if: matrix.board.platform-name == 'arduino:mbed' uses: actions/checkout@v2 with: repository: arduino/ArduinoCore-mbed @@ -83,12 +83,12 @@ jobs: - name: Remove ArduinoCore-API symlink from Arduino mbed-Enabled Boards platform # This step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used - if: matrix.board.platform-name == 'arduino-beta:mbed' + if: matrix.board.platform-name == 'arduino:mbed' run: rm "${{ env.ARDUINOCORE_MBED_STAGING_PATH }}/cores/arduino/api" - name: Checkout ArduinoCore-API # This step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used - if: matrix.board.platform-name == 'arduino-beta:mbed' + if: matrix.board.platform-name == 'arduino:mbed' uses: actions/checkout@v2 with: repository: arduino/ArduinoCore-API @@ -98,7 +98,7 @@ jobs: - name: Install ArduinoCore-API # This step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used - if: matrix.board.platform-name == 'arduino-beta:mbed' + if: matrix.board.platform-name == 'arduino:mbed' run: | mv "${{ env.ARDUINOCORE_API_STAGING_PATH }}/api" "${{ env.ARDUINOCORE_MBED_STAGING_PATH }}/cores/arduino" From 43c4561d583f8352e0b5ae685c56ada1401ae0d1 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 16 Nov 2020 19:47:33 +0100 Subject: [PATCH 007/203] Add initial support for uno wifi rev2 --- src/Arduino_ConnectionHandler.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 195ab13f..8d80f2ed 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -29,7 +29,8 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED #endif -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \ + defined(ARDUINO_AVR_UNO_WIFI_REV2) #include #include From 441c04ea1c59f483f0eaaa842099d363923cc83f Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 17 Nov 2020 09:55:41 +0100 Subject: [PATCH 008/203] Release v0.5.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 8ce2af33..82cdaee2 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.4.9 +version=0.5.0 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 7421e076665683a3a8a2869f111ea40825f1c69c Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 18 Nov 2020 10:55:44 +0100 Subject: [PATCH 009/203] Disable Arduino_DebugUtils for Arduino Uno WiFi Rev 2 in order to conserve memory --- src/Arduino_ConnectionHandler.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 8d80f2ed..98a50c1e 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -118,7 +118,9 @@ INCLUDES ******************************************************************************/ -#include +#if !defined(__AVR__) +# include +#endif /****************************************************************************** TYPEDEFS From 57c21d7852f1980cc18ad0a1f9b7f2327aee0114 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 18 Nov 2020 11:12:58 +0100 Subject: [PATCH 010/203] Disable all debug output for Arduino Uno WiFi Rev. 2 to conserve flash --- src/Arduino_WiFiConnectionHandler.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 8cfb2f06..6940235a 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -55,21 +55,28 @@ unsigned long WiFiConnectionHandler::getTime() NetworkConnectionState WiFiConnectionHandler::update_handleInit() { #ifndef BOARD_ESP8266 +#if !defined(__AVR__) Debug.print(DBG_INFO, F("WiFi.status(): %d"), WiFi.status()); +#endif if (WiFi.status() == NETWORK_HARDWARE_ERROR) { +#if !defined(__AVR__) Debug.print(DBG_ERROR, F("WiFi Hardware failure.\nMake sure you are using a WiFi enabled board/shield.")); Debug.print(DBG_ERROR, F("Then reset and retry.")); +#endif return NetworkConnectionState::ERROR; } - +#if !defined(__AVR__) Debug.print(DBG_ERROR, F("Current WiFi Firmware: %s"), WiFi.firmwareVersion()); +#endif #if defined(WIFI_FIRMWARE_VERSION_REQUIRED) if (WiFi.firmwareVersion() < WIFI_FIRMWARE_VERSION_REQUIRED) { +#if !defined(__AVR__) Debug.print(DBG_ERROR, F("Latest WiFi Firmware: %s"), WIFI_FIRMWARE_VERSION_REQUIRED); Debug.print(DBG_ERROR, F("Please update to the latest version for best performance.")); +#endif delay(5000); } #endif @@ -96,13 +103,17 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() if (WiFi.status() != NETWORK_CONNECTED) { +#if !defined(__AVR__) Debug.print(DBG_ERROR, F("Connection to \"%s\" failed"), _ssid); Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); +#endif return NetworkConnectionState::CONNECTING; } else { +#if !defined(__AVR__) Debug.print(DBG_INFO, F("Connected to \"%s\""), _ssid); +#endif #ifdef BOARD_ESP8266 configTime(0, 0, "time.arduino.cc", "pool.ntp.org", "time.nist.gov"); #endif @@ -114,12 +125,15 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnected() { if (WiFi.status() != WL_CONNECTED) { +#if !defined(__AVR__) Debug.print(DBG_VERBOSE, F("WiFi.status(): %d"), WiFi.status()); Debug.print(DBG_ERROR, F("Connection to \"%s\" lost."), _ssid); - +#endif if (_keep_alive) { +#if !defined(__AVR__) Debug.print(DBG_ERROR, F("Attempting reconnection")); +#endif } return NetworkConnectionState::DISCONNECTED; From b18076ecdadcf0b27056e02e0d388dfed43414db Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 18 Nov 2020 12:35:27 +0100 Subject: [PATCH 011/203] Relase v0.5.1 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 82cdaee2..07aacc0f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.5.0 +version=0.5.1 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 730b0e2ce1dfaa98c466d4c47481a5b46c16e475 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 15 Dec 2020 01:15:58 -0800 Subject: [PATCH 012/203] Remove api symlink deletion step from CI workflow The symlink for ArduinoCore-API in the Mbed OS Boards core library has been removed. This resulted in the step of the "Compile Examples" CI workflow that removes the now non-existent symlink to fail. --- .github/workflows/compile-examples.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 75855f2f..6f731222 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -81,11 +81,6 @@ jobs: # The arduino/actions/libraries/compile-examples action will install the platform from this path path: ${{ env.ARDUINOCORE_MBED_STAGING_PATH }} - - name: Remove ArduinoCore-API symlink from Arduino mbed-Enabled Boards platform - # This step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used - if: matrix.board.platform-name == 'arduino:mbed' - run: rm "${{ env.ARDUINOCORE_MBED_STAGING_PATH }}/cores/arduino/api" - - name: Checkout ArduinoCore-API # This step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used if: matrix.board.platform-name == 'arduino:mbed' From 3b0e185cc916c2ecffe6495897e7d92d293d7661 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 15 Dec 2020 01:16:46 -0800 Subject: [PATCH 013/203] Use default branch of ArduinoCore-API in CI workflow Previously, the `namespace_arduino` branch of `arduino/ArduinoCore-API` was used in the core library of the development version of the Mbed OS Boards platform used in the "Compile Examples" CI workflow. The default branch of `arduino/ArduinoCore-API` is now the latest and greatest version, so the `namespace_arduino` branch should no longer be used for the Mbed OS Boards platform's core library. --- .github/workflows/compile-examples.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 6f731222..f36cce99 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -87,8 +87,6 @@ jobs: uses: actions/checkout@v2 with: repository: arduino/ArduinoCore-API - # As specified at https://github.com/arduino/ArduinoCore-mbed/blob/master/README.md#installation - ref: namespace_arduino path: ${{ env.ARDUINOCORE_API_STAGING_PATH }} - name: Install ArduinoCore-API From 713c835152f9b189a8dd438e966ac14174abad14 Mon Sep 17 00:00:00 2001 From: ubi Date: Sun, 10 Jan 2021 22:28:27 +0100 Subject: [PATCH 014/203] ESP32 support --- src/Arduino_ConnectionHandler.h | 11 +++++++++++ src/Arduino_WiFiConnectionHandler.cpp | 12 ++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 98a50c1e..32a8129f 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -114,6 +114,17 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED #endif +#if defined(ESP32) + #include + #include + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED + #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED + +#endif + /****************************************************************************** INCLUDES ******************************************************************************/ diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 6940235a..e1a1f12d 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -41,7 +41,7 @@ WiFiConnectionHandler::WiFiConnectionHandler(char const * ssid, char const * pas unsigned long WiFiConnectionHandler::getTime() { -#if !defined(BOARD_ESP8266) +#if !defined(BOARD_ESP8266) && !defined(ESP32) return WiFi.getTime(); #else return 0; @@ -54,7 +54,7 @@ unsigned long WiFiConnectionHandler::getTime() NetworkConnectionState WiFiConnectionHandler::update_handleInit() { -#ifndef BOARD_ESP8266 +#if !defined(BOARD_ESP8266) && !defined(ESP32) #if !defined(__AVR__) Debug.print(DBG_INFO, F("WiFi.status(): %d"), WiFi.status()); #endif @@ -87,14 +87,14 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() delay(300); WiFi.begin(_ssid, _pass); delay(1000); -#endif /* ifndef BOARD_ESP8266 */ +#endif /* #if !defined(BOARD_ESP8266) && !defined(ESP32) */ return NetworkConnectionState::CONNECTING; } NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() { -#ifndef BOARD_ESP8266 +#if !defined(BOARD_ESP8266) && !defined(ESP32) if (WiFi.status() != WL_CONNECTED) { WiFi.begin(_ssid, _pass); @@ -114,7 +114,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() #if !defined(__AVR__) Debug.print(DBG_INFO, F("Connected to \"%s\""), _ssid); #endif -#ifdef BOARD_ESP8266 +#if defined(BOARD_ESP8266) || defined(ESP32) configTime(0, 0, "time.arduino.cc", "pool.ntp.org", "time.nist.gov"); #endif return NetworkConnectionState::CONNECTED; @@ -149,7 +149,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleDisconnecting() NetworkConnectionState WiFiConnectionHandler::update_handleDisconnected() { -#ifndef BOARD_ESP8266 +#if !defined(BOARD_ESP8266) && !defined(ESP32) WiFi.end(); #endif /* ifndef BOARD_ESP8266 */ if (_keep_alive) From 61e3a2aa8cc306ee5a476024fa1289fd792373ff Mon Sep 17 00:00:00 2001 From: ubi Date: Sun, 10 Jan 2021 22:54:28 +0100 Subject: [PATCH 015/203] modified example to comply with removal of DebugUtils for AVR --- examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino index 2246fc10..b106eed6 100644 --- a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino +++ b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino @@ -34,9 +34,9 @@ void setup() { Serial.begin(9600); /* Give a few seconds for the Serial connection to be available */ delay(4000); - +#ifndef __AVR__ setDebugMessageLevel(DBG_INFO); - +#endif conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect); conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect); conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError); From 6fe3cae389e222177c8818ce67c27bd6796d4826 Mon Sep 17 00:00:00 2001 From: per1234 Date: Wed, 13 Jan 2021 00:40:57 -0800 Subject: [PATCH 016/203] Use modern version of arduino/compile-sketches action The action has been moved to a dedicated repository and the previous repository is no longer being maintained. --- .github/workflows/compile-examples.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index f36cce99..a35f557b 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -20,6 +20,7 @@ jobs: LIBRARIES: Arduino_DebugUtils WiFi101 WiFiNINA MKRGSM MKRNB MKRWAN ARDUINOCORE_MBED_STAGING_PATH: extras/ArduinoCore-mbed ARDUINOCORE_API_STAGING_PATH: extras/ArduinoCore-API + SKETCHES_REPORTS_PATH: sketches-reports strategy: matrix: board: @@ -96,17 +97,18 @@ jobs: mv "${{ env.ARDUINOCORE_API_STAGING_PATH }}/api" "${{ env.ARDUINOCORE_MBED_STAGING_PATH }}/cores/arduino" - name: Compile examples - uses: arduino/actions/libraries/compile-examples@master + uses: arduino/compile-sketches@main with: platforms: ${{ matrix.platforms }} fqbn: ${{ matrix.board.fqbn }} libraries: ${{ env.LIBRARIES }} size-report-sketch: 'ConnectionHandlerDemo' enable-size-deltas-report: 'true' + sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} - name: Save memory usage change report as artifact if: github.event_name == 'pull_request' uses: actions/upload-artifact@v1 with: - name: 'size-deltas-reports' - path: 'size-deltas-reports' + name: ${{ env.SKETCHES_REPORTS_PATH }} + path: ${{ env.SKETCHES_REPORTS_PATH }} From 0c52270dbf72ad2c2c4ac1c75825a5a519f54328 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 12 Jan 2021 20:27:52 -0800 Subject: [PATCH 017/203] Add ESP32 board to "Compile Examples" CI workflow ESP32 support has been added to the library, so the examples compilation smoke test should be done for this architecture as well. --- .github/workflows/compile-examples.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index a35f557b..1b9a50fe 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -44,6 +44,8 @@ jobs: platform-name: arduino:mbed - fqbn: "esp8266:esp8266:huzzah" platform-name: esp8266:esp8266 + - fqbn: "esp32:esp32:esp32" + platform-name: esp32:esp32 # Make board type-specific customizations to the matrix jobs include: @@ -66,6 +68,12 @@ jobs: # Install ESP8266 platform via Boards Manager - name: esp8266:esp8266 source-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json + - board: + platform-name: esp32:esp32 + platforms: | + # Install ESP32 platform via Boards Manager + - name: esp32:esp32 + source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json steps: - uses: actions/checkout@v1 @@ -96,6 +104,10 @@ jobs: run: | mv "${{ env.ARDUINOCORE_API_STAGING_PATH }}/api" "${{ env.ARDUINOCORE_MBED_STAGING_PATH }}/cores/arduino" + - name: Install ESP32 platform dependencies + if: matrix.board.platform-name == 'esp32:esp32' + run: pip3 install pyserial + - name: Compile examples uses: arduino/compile-sketches@main with: From f624fbdc598d625660b622ab7e96f7f3dc3ddbf0 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 13 Jan 2021 09:17:19 +0100 Subject: [PATCH 018/203] Fix -Wreorder error during CI build. --- src/Arduino_ConnectionHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_ConnectionHandler.cpp b/src/Arduino_ConnectionHandler.cpp index 51f63fc8..943fa1d9 100644 --- a/src/Arduino_ConnectionHandler.cpp +++ b/src/Arduino_ConnectionHandler.cpp @@ -27,8 +27,8 @@ ConnectionHandler::ConnectionHandler(bool const keep_alive) : _keep_alive{keep_alive} -, _current_net_connection_state{NetworkConnectionState::INIT} , _lastConnectionTickTime{millis()} +, _current_net_connection_state{NetworkConnectionState::INIT} { } From dc00a26b78f41dc7abdea9a18299db058e1feedb Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 13 Jan 2021 12:50:45 +0100 Subject: [PATCH 019/203] Release v0.6.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 07aacc0f..e36cdf08 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.5.1 +version=0.6.0 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 6d3570049253b25eae58e17bf64de0fb9f852665 Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 14 Jan 2021 00:27:28 -0800 Subject: [PATCH 020/203] Pin esp8266:esp8266 platform version to 2.5.0 in CI builds (#50) Previously, the most recent release of the ESP8266 boards platform (currently 2.7.4) was used in the "Compile Examples" CI workflow. Arduino Create uses 2.5.0, so it's best to use that version for testing as well. --- .github/workflows/compile-examples.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 1b9a50fe..88f07208 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -68,6 +68,7 @@ jobs: # Install ESP8266 platform via Boards Manager - name: esp8266:esp8266 source-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json + version: 2.5.0 - board: platform-name: esp32:esp32 platforms: | From e2da26ce73f1acf8a7e0ac2cc37c8ba084b2e10d Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 18 Jan 2021 06:37:06 +0100 Subject: [PATCH 021/203] Adding 'mbed' as supported library to Arduino_ConnectionHandler library (since we are already using it on Portenta H7). (#51) --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index e36cdf08..8815d06e 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethe paragraph=Originally part of ArduinoIoTCloud category=Communication url=https://github.com/arduino-libraries/Arduino_ConnectionHandler -architectures=samd,esp32,esp8266 +architectures=samd,esp32,esp8266,mbed depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN From 530502d57c58eae64f4b31117f414c93fc2ecced Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 18 Jan 2021 06:38:36 +0100 Subject: [PATCH 022/203] Release v0.6.1 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 8815d06e..d24574dc 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.6.0 +version=0.6.1 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 0d4dc8bbf18992a02a0cb9c9bf135db0ea7f2902 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Thu, 28 Jan 2021 07:47:08 +0100 Subject: [PATCH 023/203] Add megaavr to the list of supported architectures. --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index d24574dc..ee064466 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethe paragraph=Originally part of ArduinoIoTCloud category=Communication url=https://github.com/arduino-libraries/Arduino_ConnectionHandler -architectures=samd,esp32,esp8266,mbed +architectures=samd,esp32,esp8266,mbed,megaavr depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN From ef651ccfe9443dd1e9c6dbcc98e28f87aa3e6f2c Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Thu, 28 Jan 2021 07:47:46 +0100 Subject: [PATCH 024/203] Release v0.6.2 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index ee064466..7a168b5f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.6.1 +version=0.6.2 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 92c1f6fa4df14b207aa067a5df7eb0ee0d37b9ea Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 17 Mar 2021 08:31:02 +0100 Subject: [PATCH 025/203] Preeliminary rpi2040 support (#52) * Preeliminary support for RPI 2040 NANO Connect. * Adding missing closing brace. * Top-level include of solves missing macro "F()" --- src/Arduino_ConnectionHandler.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 32a8129f..6496b931 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -18,6 +18,8 @@ #ifndef ARDUINO_CONNECTION_HANDLER_H_ #define ARDUINO_CONNECTION_HANDLER_H_ +#include + #ifdef ARDUINO_SAMD_MKR1000 #include #include @@ -30,7 +32,7 @@ #endif #if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \ - defined(ARDUINO_AVR_UNO_WIFI_REV2) + defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined (ARDUINO_NANO_RP2040_CONNECT) #include #include From 862db0821fe5bcaca1cb11017bed9e336997f124 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Fri, 19 Mar 2021 10:30:42 +0100 Subject: [PATCH 026/203] Release v0.6.3. --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 7a168b5f..eff66aa2 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.6.2 +version=0.6.3 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 5e8a67523c4c13321eb634e53ba676ecfd6020d5 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 17 Apr 2021 19:24:05 -0700 Subject: [PATCH 027/203] Configure Dependabot to check for outdated actions used in workflows Dependabot will periodically check the versions of all actions used in the repository's workflows. If any are found to be outdated, it will submit a pull request to update them. NOTE: Dependabot's PRs will sometimes try to pin to the patch version of the action (e.g., updating `uses: foo/bar@v1` to `uses: foo/bar@v2.3.4`). When the action author has provided a major version ref, use that instead (e.g., `uses: foo/bar@v2`). Dependabot will automatically close its PR once the workflow has been updated. More information: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot --- .github/dependabot.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..03600dd7 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +# See: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#about-the-dependabotyml-file +version: 2 + +updates: + # Configure check for outdated GitHub Actions actions in workflows. + # See: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot + - package-ecosystem: github-actions + directory: / # Check the repository's workflows under /.github/workflows/ + schedule: + interval: daily From 0fbf80d037f15eec6c6f3241e6cb825e14451f57 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 17 Apr 2021 19:24:44 -0700 Subject: [PATCH 028/203] Add CI workflow to do Arduino project-specific linting On every push, pull request, and periodically, run Arduino Lint to check for common problems not related to the project code. --- .github/workflows/check-arduino.yml | 28 ++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 29 insertions(+) create mode 100644 .github/workflows/check-arduino.yml diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml new file mode 100644 index 00000000..0d969f6c --- /dev/null +++ b/.github/workflows/check-arduino.yml @@ -0,0 +1,28 @@ +name: Check Arduino + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + pull_request: + schedule: + # Run every Tuesday at 8 AM UTC to catch breakage caused by new rules added to Arduino Lint. + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Arduino Lint + uses: arduino/arduino-lint-action@v1 + with: + compliance: specification + library-manager: update + # Always use this setting for official repositories. Remove for 3rd party projects. + official: true + project-type: library diff --git a/README.md b/README.md index ba80cf02..3ed97ab7 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ Arduino Library for network connections management ![](https://github.com/arduino-libraries/Arduino_ConnectionHandler/workflows/Compile%20Examples/badge.svg) ![](https://github.com/arduino-libraries/Arduino_ConnectionHandler/workflows/Spell%20Check/badge.svg) +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/check-arduino.yml) Library for handling and managing network connections by providing keep-alive functionality and automatic reconnection in case of connection-loss. It supports the following boards: * **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), `ESP8266` From 990b099fe8d7b7f465322720da282023a73ecdfa Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 17 Apr 2021 19:25:37 -0700 Subject: [PATCH 029/203] Update CI workflow to check for commonly misspelled words On every push, pull request, and periodically, use the codespell-project/actions-codespell action to check for commonly misspelled words. In the event of a false positive, the problematic word should be added, in all lowercase, to the ignore-words-list field of ./.codespellrc. Regardless of the case of the word in the false positive, it must be in all lowercase in the ignore list. The ignore list is comma-separated with no spaces. --- .codespellrc | 7 +++++++ .github/workflows/spell-check.yml | 28 +++++++++++++++++--------- extras/codespell-ignore-words-list.txt | 1 - 3 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 .codespellrc delete mode 100644 extras/codespell-ignore-words-list.txt diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 00000000..15692792 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,7 @@ +# See: https://github.com/codespell-project/codespell#using-a-config-file +[codespell] +# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: +ignore-words-list = wan +check-filenames = +check-hidden = +skip = ./.git diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index b7be756a..01bee879 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -1,14 +1,22 @@ name: Spell Check -on: [push, pull_request] + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + pull_request: + schedule: + # Run every Tuesday at 8 AM UTC to catch new misspelling detections resulting from dictionary updates. + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: + jobs: - build: - runs-on: ubuntu-latest + spellcheck: + runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - with: - fetch-depth: 1 - - uses: arduino/actions/libraries/spell-check@master - with: - ignore-words-list: extras/codespell-ignore-words-list.txt + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Spell check + uses: codespell-project/actions-codespell@master diff --git a/extras/codespell-ignore-words-list.txt b/extras/codespell-ignore-words-list.txt deleted file mode 100644 index a991d7cd..00000000 --- a/extras/codespell-ignore-words-list.txt +++ /dev/null @@ -1 +0,0 @@ -wan \ No newline at end of file From 8baf23e53083b01e75ceefd73016265dc3925c42 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 17 Apr 2021 19:26:06 -0700 Subject: [PATCH 030/203] Update badges markup in readme Since the time the original badges were added, GitHub added support for referencing the workflows via file name in addition to the previous approach of using the `name` value. This links to the specific workflow's runs, rather than a search for the name which might return multiple results. It is also more lightweight in terms of syntax. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3ed97ab7..ffe7c2c6 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ Arduino Library for network connections management ================================================== -![](https://github.com/arduino-libraries/Arduino_ConnectionHandler/workflows/Compile%20Examples/badge.svg) -![](https://github.com/arduino-libraries/Arduino_ConnectionHandler/workflows/Spell%20Check/badge.svg) [![Check Arduino status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml) Library for handling and managing network connections by providing keep-alive functionality and automatic reconnection in case of connection-loss. It supports the following boards: * **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), `ESP8266` From 70c5fc56997811157df8fb418f4be90f802f132e Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 17 Apr 2021 19:27:42 -0700 Subject: [PATCH 031/203] Add additional trigger events to CI workflows The workflow_dispatch and repository_dispatch events allow manual triggering of the workflow. These can be useful when doing development and maintenance on the CI system, and do no harm when they are not needed, so it makes sense to add them. --- .github/workflows/compile-examples.yml | 5 +++++ .github/workflows/report-size-deltas.yml | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 88f07208..ffcb6b9c 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -11,6 +11,11 @@ on: - ".github/workflows/compile-examples.yml" - "examples/**" - "src/**" + schedule: + # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: jobs: build: diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml index 8af849fe..6805ac0e 100644 --- a/.github/workflows/report-size-deltas.yml +++ b/.github/workflows/report-size-deltas.yml @@ -1,8 +1,13 @@ name: Report PR Size Deltas on: + push: + paths: + - ".github/workflows/report-size-deltas.yml" schedule: - cron: '*/5 * * * *' + workflow_dispatch: + repository_dispatch: jobs: report: From 024a5db543c5dbc01107cabb878e44dfad5c2fb8 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 17 Apr 2021 19:28:15 -0700 Subject: [PATCH 032/203] Use custom matrix job names in sketch compilation CI job The "Compile Examples" GitHub Actions workflow generates a matrix job for each board. The default job name is generated from the job's matrix object. This contains the complete board data, which results in a long and somewhat cryptic job name that can make the workflow run more difficult to interpret. The only necessary information is the FQBN. A custom job name allows for only using this information in the job name. --- .github/workflows/compile-examples.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index ffcb6b9c..af8172f0 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -19,6 +19,7 @@ on: jobs: build: + name: ${{ matrix.board.fqbn }} runs-on: ubuntu-latest env: From 9fb37dedc8d066ca74b68bcad753deba2f517e3c Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 17 Apr 2021 19:28:54 -0700 Subject: [PATCH 033/203] Update GitHub Actions action versions used in workflows Previously, due to the lack of a release, the development versions of the sketch compilation actions were used. Using release versions provides a more stable CI system for the ArduinoCore-mbed project. Use of the major version ref will cause the workflow to benefit from ongoing development to the actions up until such time as a new major release of an action is made, at which time we would need to evaluate whether any changes to the workflow are required by the breaking change that triggered the major release before updating the major ref (e.g., uses: `arduino/compile-sketches@v2`). --- .github/workflows/compile-examples.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index af8172f0..d2783054 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -83,9 +83,7 @@ jobs: source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json steps: - - uses: actions/checkout@v1 - with: - fetch-depth: 1 + - uses: actions/checkout@v2 # It's necessary to checkout the platform before installing it so that the ArduinoCore-API dependency can be added - name: Checkout ArduinoCore-mbed @@ -116,7 +114,7 @@ jobs: run: pip3 install pyserial - name: Compile examples - uses: arduino/compile-sketches@main + uses: arduino/compile-sketches@v1 with: platforms: ${{ matrix.platforms }} fqbn: ${{ matrix.board.fqbn }} @@ -127,7 +125,7 @@ jobs: - name: Save memory usage change report as artifact if: github.event_name == 'pull_request' - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v2 with: name: ${{ env.SKETCHES_REPORTS_PATH }} path: ${{ env.SKETCHES_REPORTS_PATH }} From 1d47c70802cb0d8fc2e51b390f24ee79f1376111 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 17 Apr 2021 19:29:43 -0700 Subject: [PATCH 034/203] Use report size deltas action from dedicated repository The arduino/actions repository is used for hosting GitHub Actions that are in an experimental state. The report size deltas action has since been deemed valuable and mature enough to be moved to a dedicated repository. The action at the previous location is preserved for now for the sake of backwards compatibility, but is deprecated and unmaintained. All workflows should be updated to using the arduino/report-size-deltas action. --- .github/workflows/report-size-deltas.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml index 6805ac0e..274e2c1a 100644 --- a/.github/workflows/report-size-deltas.yml +++ b/.github/workflows/report-size-deltas.yml @@ -15,4 +15,4 @@ jobs: steps: - name: Comment size deltas reports to PRs - uses: arduino/actions/libraries/report-size-deltas@master + uses: arduino/report-size-deltas@v1 From 4ac8d440e8d61244223a96f4f11cfc33d202ed63 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 17 Apr 2021 19:32:35 -0700 Subject: [PATCH 035/203] Run examples compilation CI workflow on changes to library.properties The library.properties metadata file can have an impact on compilation, so the CI workflow should run when it's changed in order to assist in validation of those changes. --- .github/workflows/compile-examples.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index d2783054..ba295154 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -4,11 +4,13 @@ on: pull_request: paths: - ".github/workflows/compile-examples.yml" + - "library.properties" - "examples/**" - "src/**" push: paths: - ".github/workflows/compile-examples.yml" + - "library.properties" - "examples/**" - "src/**" schedule: From 78ab9ebb979048ad79f533b6f189b38f743d9040 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 17 Apr 2021 19:32:58 -0700 Subject: [PATCH 036/203] =?UTF-8?q?Configure=20workflow=20artifact=20uploa?= =?UTF-8?q?d=20step=20to=20fail=20if=20sketches=20report=20fi=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …le not found This event would indicate that the workflow was misconfigured. So it's a valuable notification. --- .github/workflows/compile-examples.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index ba295154..8d14e431 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -129,5 +129,6 @@ jobs: if: github.event_name == 'pull_request' uses: actions/upload-artifact@v2 with: + if-no-files-found: error name: ${{ env.SKETCHES_REPORTS_PATH }} path: ${{ env.SKETCHES_REPORTS_PATH }} From 62c13953eba3b4a9a8d9b5d3a97b3b35078eec2f Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 17 Apr 2021 19:33:31 -0700 Subject: [PATCH 037/203] Define name of sketches reports workflow artifact Even though this is already the default value, relying on the default is a bit risky due to the need to specify the artifact name to the actions/upload-artifact action in the sketch compilation workflow. --- .github/workflows/report-size-deltas.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml index 274e2c1a..91730129 100644 --- a/.github/workflows/report-size-deltas.yml +++ b/.github/workflows/report-size-deltas.yml @@ -16,3 +16,6 @@ jobs: steps: - name: Comment size deltas reports to PRs uses: arduino/report-size-deltas@v1 + with: + # The name of the workflow artifact created by the sketch compilation workflow + sketches-reports-source: sketches-reports From 6ec2ec036c641dea23a283368a0159c9f7c880dc Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 20 Apr 2021 07:22:58 +0200 Subject: [PATCH 038/203] Add Nano RP2040 Connect as target during CI compilation. (#55) --- .github/workflows/compile-examples.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 8d14e431..2beed1f3 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -54,6 +54,8 @@ jobs: platform-name: esp8266:esp8266 - fqbn: "esp32:esp32:esp32" platform-name: esp32:esp32 + - fqbn: arduino:mbed_nano:nanorp2040connect + platform-name: arduino:mbed_nano # Make board type-specific customizations to the matrix jobs include: From 83012b73ac2548bf4264499706435bd3c1aee233 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 20 Apr 2021 10:39:15 +0200 Subject: [PATCH 039/203] Add mbed_nano and mbed_portenta as supported architectures. (#56) --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index eff66aa2..7acb78b5 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethe paragraph=Originally part of ArduinoIoTCloud category=Communication url=https://github.com/arduino-libraries/Arduino_ConnectionHandler -architectures=samd,esp32,esp8266,mbed,megaavr +architectures=samd,esp32,esp8266,mbed,megaavr,mbed_nano,mbed_portenta depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN From bef77f1762bfa0f6611b6ec7d0ee9e045986ba42 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 28 Apr 2021 11:47:00 +0200 Subject: [PATCH 040/203] Feed watchdog a bit more often when initializing MKR GSM 1400/NB 1500 modems - this takes a bit of time. --- src/Arduino_GSMConnectionHandler.cpp | 18 ++++++++++++++++++ src/Arduino_NBConnectionHandler.cpp | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/Arduino_GSMConnectionHandler.cpp b/src/Arduino_GSMConnectionHandler.cpp index 67afa14f..fd65ba9c 100644 --- a/src/Arduino_GSMConnectionHandler.cpp +++ b/src/Arduino_GSMConnectionHandler.cpp @@ -29,6 +29,18 @@ static int const GSM_TIMEOUT = 30000; +/****************************************************************************** + FUNCTION DEFINITION + ******************************************************************************/ + +__attribute__((weak)) void mkr_gsm_feed_watchdog() +{ + /* This function can be overwritten by a "strong" implementation + * in a higher level application, such as the ArduinoIoTCloud + * firmware stack. + */ +} + /****************************************************************************** CTOR/DTOR ******************************************************************************/ @@ -58,15 +70,21 @@ unsigned long GSMConnectionHandler::getTime() NetworkConnectionState GSMConnectionHandler::update_handleInit() { + mkr_gsm_feed_watchdog(); + if (_gsm.begin(_pin) != GSM_READY) { Debug.print(DBG_ERROR, F("SIM not present or wrong PIN")); return NetworkConnectionState::ERROR; } + mkr_gsm_feed_watchdog(); + Debug.print(DBG_INFO, F("SIM card ok")); _gsm.setTimeout(GSM_TIMEOUT); + mkr_gsm_feed_watchdog(); + GSM3_NetworkStatus_t const network_status = _gprs.attachGPRS(_apn, _login, _pass, true); Debug.print(DBG_DEBUG, F("GPRS.attachGPRS(): %d"), network_status); if (network_status == GSM3_NetworkStatus_t::ERROR) diff --git a/src/Arduino_NBConnectionHandler.cpp b/src/Arduino_NBConnectionHandler.cpp index a4d8765b..8c747edf 100644 --- a/src/Arduino_NBConnectionHandler.cpp +++ b/src/Arduino_NBConnectionHandler.cpp @@ -29,6 +29,18 @@ static int const NB_TIMEOUT = 30000; +/****************************************************************************** + FUNCTION DEFINITION + ******************************************************************************/ + +__attribute__((weak)) void mkr_nb_feed_watchdog() +{ + /* This function can be overwritten by a "strong" implementation + * in a higher level application, such as the ArduinoIoTCloud + * firmware stack. + */ +} + /****************************************************************************** CTOR/DTOR ******************************************************************************/ @@ -69,6 +81,8 @@ unsigned long NBConnectionHandler::getTime() NetworkConnectionState NBConnectionHandler::update_handleInit() { + mkr_nb_feed_watchdog(); + if (_nb.begin(_pin, _apn, _login, _pass) == NB_READY) { Debug.print(DBG_INFO, F("SIM card ok")); From 24721830235d205f1f49e4b11d1270540ba0f6e5 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Thu, 29 Apr 2021 07:14:56 +0200 Subject: [PATCH 041/203] Release v0.6.4 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 7acb78b5..7944e434 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.6.3 +version=0.6.4 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 9e12f60d66a3493368da1332dddb1d138913f925 Mon Sep 17 00:00:00 2001 From: Kody Rogers Date: Fri, 21 May 2021 12:55:04 -0600 Subject: [PATCH 042/203] Add GPRS timeout for GSM connections. --- src/Arduino_GSMConnectionHandler.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Arduino_GSMConnectionHandler.cpp b/src/Arduino_GSMConnectionHandler.cpp index fd65ba9c..3bf8b908 100644 --- a/src/Arduino_GSMConnectionHandler.cpp +++ b/src/Arduino_GSMConnectionHandler.cpp @@ -28,6 +28,7 @@ ******************************************************************************/ static int const GSM_TIMEOUT = 30000; +static int const GPRS_TIMEOUT = 30000; /****************************************************************************** FUNCTION DEFINITION @@ -82,6 +83,7 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit() Debug.print(DBG_INFO, F("SIM card ok")); _gsm.setTimeout(GSM_TIMEOUT); + _gprs.setTimeout(GPRS_TIMEOUT); mkr_gsm_feed_watchdog(); From 54146f11e6d0a5fdad9c5ef82bad4ec104641c2d Mon Sep 17 00:00:00 2001 From: ilcato Date: Fri, 8 Oct 2021 10:57:25 +0200 Subject: [PATCH 043/203] Expose Lora modem getters --- src/Arduino_LoRaConnectionHandler.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Arduino_LoRaConnectionHandler.h b/src/Arduino_LoRaConnectionHandler.h index a0cff734..49717568 100644 --- a/src/Arduino_LoRaConnectionHandler.h +++ b/src/Arduino_LoRaConnectionHandler.h @@ -39,6 +39,20 @@ class LoRaConnectionHandler : public ConnectionHandler virtual int read() override; virtual bool available() override; + inline String getVersion() { return _modem.version(); } + inline String getDeviceEUI() { return _modem.deviceEUI(); } + inline int getChannelMaskSize(_lora_band band) { return _modem.getChannelMaskSize(band); } + inline String getChannelMask() { return _modem.getChannelMask(); } + inline int isChannelEnabled(int pos) { return _modem.isChannelEnabled(pos); } + inline int getDataRate() { return _modem.getDataRate(); } + inline int getADR() { return _modem.getADR(); } + inline String getDevAddr() { return _modem.getDevAddr(); } + inline String getNwkSKey() { return _modem.getNwkSKey(); } + inline String getAppSKey() { return _modem.getAppSKey(); } + inline int getRX2DR() { return _modem.getRX2DR(); } + inline uint32_t getRX2Freq() { return _modem.getRX2Freq(); } + inline int32_t getFCU() { return _modem.getFCU(); } + inline int32_t getFCD() { return _modem.getFCD(); } protected: From cdd2dd666a7deaa2ba9dab5df2c86c6c4dd70335 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 17 Oct 2021 03:49:47 -0700 Subject: [PATCH 044/203] Use modern API of `arduino/compile-sketches` action The API of the `arduino/compile-sketches` GitHub Actions action used to compile the library's example sketches in the "Compile Examples" CI workflow has evolved over time. Although measures were taken to provide backwards compatibility for the old API, it turns out that the GitHub Actions behavior of creating environment variables for arbitrary input names relied upon for still recognizing the old inputs is not consistent across action types. It works fine for the Docker container action type originally used by `arduino/compile-sketches`, but not for the new "Composite Run Steps" action type we switched to. This change resulted in sketch data deltas no longer being generated due to the workflow's use of the unsupported input name `enable-size-deltas-report` (which was changed to the more appropriate `enable-deltas-report` last year). This resulted in failed runs of the "Report Size Deltas" due to the reports not having the required deltas data. The fix is simply to update to the new input name in the "Compile Examples" GitHub Actions workflow that uses the `arduino/compile-sketches` action. I also updated the contents of the action's `libraries` input to the new YAML array style. This was not mandatory because there is still backwards compatibility for the old API in this case due to the input name not having changed, but only the data format. However, the old data format is deprecated so it's safest to update. I also removed the no longer used `size-report-sketch` input. This input was removed at the time the action was changed to report on all compilations --- .github/workflows/compile-examples.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 2beed1f3..bd7849e2 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -25,7 +25,15 @@ jobs: runs-on: ubuntu-latest env: - LIBRARIES: Arduino_DebugUtils WiFi101 WiFiNINA MKRGSM MKRNB MKRWAN + LIBRARIES: | + # Install the Arduino_ConnectionHandler library from the repository + - source-path: ./ + - name: Arduino_DebugUtils + - name: WiFi101 + - name: WiFiNINA + - name: MKRGSM + - name: MKRNB + - name: MKRWAN ARDUINOCORE_MBED_STAGING_PATH: extras/ArduinoCore-mbed ARDUINOCORE_API_STAGING_PATH: extras/ArduinoCore-API SKETCHES_REPORTS_PATH: sketches-reports @@ -123,8 +131,7 @@ jobs: platforms: ${{ matrix.platforms }} fqbn: ${{ matrix.board.fqbn }} libraries: ${{ env.LIBRARIES }} - size-report-sketch: 'ConnectionHandlerDemo' - enable-size-deltas-report: 'true' + enable-deltas-report: 'true' sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} - name: Save memory usage change report as artifact From 45f17abc0a4d1b5c6cc48423c24c302ee1bf5e9a Mon Sep 17 00:00:00 2001 From: ilcato Date: Mon, 18 Oct 2021 15:09:11 +0200 Subject: [PATCH 045/203] Added subfrequency band index parameter and managed it --- src/Arduino_LoRaConnectionHandler.cpp | 16 ++++++++++++++-- src/Arduino_LoRaConnectionHandler.h | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Arduino_LoRaConnectionHandler.cpp b/src/Arduino_LoRaConnectionHandler.cpp index c0183e3e..3c1e184e 100644 --- a/src/Arduino_LoRaConnectionHandler.cpp +++ b/src/Arduino_LoRaConnectionHandler.cpp @@ -43,12 +43,12 @@ typedef enum /****************************************************************************** CTOR/DTOR ******************************************************************************/ - -LoRaConnectionHandler::LoRaConnectionHandler(char const * appeui, char const * appkey, _lora_band const band, _lora_class const device_class) +LoRaConnectionHandler::LoRaConnectionHandler(char const * appeui, char const * appkey, _lora_band const band, uint8_t const sub_band_id, _lora_class const device_class) : ConnectionHandler{false} , _appeui(appeui) , _appkey(appkey) , _band(band) +, _sub_band_id(sub_band_id) , _device_class(device_class) { @@ -106,6 +106,18 @@ NetworkConnectionState LoRaConnectionHandler::update_handleInit() { Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry.")); return NetworkConnectionState::ERROR; + } + // Set channelmask based on frequency sub band index + if (_sub_band_id) { + String mask; + for (int i = 12; i > 0; i--) { + if (i == _sub_band_id) { + mask.concat("FF"); + } else { + mask.concat("00"); + } + } + _modem.sendMask(mask); } //A delay is required between _modem.begin(band) and _modem.joinOTAA(appeui, appkey) in order to let the chip to be correctly initialized before the connection attempt delay(100); diff --git a/src/Arduino_LoRaConnectionHandler.h b/src/Arduino_LoRaConnectionHandler.h index 49717568..2b6dc38e 100644 --- a/src/Arduino_LoRaConnectionHandler.h +++ b/src/Arduino_LoRaConnectionHandler.h @@ -32,8 +32,7 @@ class LoRaConnectionHandler : public ConnectionHandler { public: - LoRaConnectionHandler(char const * appeui, char const * appkey, _lora_band const band = _lora_band::EU868, _lora_class const device_class = _lora_class::CLASS_A); - + LoRaConnectionHandler(char const * appeui, char const * appkey, _lora_band const band = _lora_band::EU868, uint8_t const sub_band_id = 0, _lora_class const device_class = _lora_class::CLASS_A); virtual int write(const uint8_t *buf, size_t size) override; virtual int read() override; @@ -68,6 +67,7 @@ class LoRaConnectionHandler : public ConnectionHandler char const * _appeui; char const * _appkey; _lora_band _band; + uint8_t _sub_band_id; _lora_class _device_class; LoRaModem _modem; }; From 832f180ece5aaf1ddf797deecc22cc6095be9795 Mon Sep 17 00:00:00 2001 From: ilcato Date: Sat, 23 Oct 2021 10:09:35 +0200 Subject: [PATCH 046/203] Channel mask instead of sub band ID. --- src/Arduino_LoRaConnectionHandler.cpp | 18 +++++------------- src/Arduino_LoRaConnectionHandler.h | 4 ++-- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/Arduino_LoRaConnectionHandler.cpp b/src/Arduino_LoRaConnectionHandler.cpp index 3c1e184e..e34092b0 100644 --- a/src/Arduino_LoRaConnectionHandler.cpp +++ b/src/Arduino_LoRaConnectionHandler.cpp @@ -43,12 +43,12 @@ typedef enum /****************************************************************************** CTOR/DTOR ******************************************************************************/ -LoRaConnectionHandler::LoRaConnectionHandler(char const * appeui, char const * appkey, _lora_band const band, uint8_t const sub_band_id, _lora_class const device_class) +LoRaConnectionHandler::LoRaConnectionHandler(char const * appeui, char const * appkey, _lora_band const band, char const * channelMask, _lora_class const device_class) : ConnectionHandler{false} , _appeui(appeui) , _appkey(appkey) , _band(band) -, _sub_band_id(sub_band_id) +, _channelMask(channelMask) , _device_class(device_class) { @@ -107,17 +107,9 @@ NetworkConnectionState LoRaConnectionHandler::update_handleInit() Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry.")); return NetworkConnectionState::ERROR; } - // Set channelmask based on frequency sub band index - if (_sub_band_id) { - String mask; - for (int i = 12; i > 0; i--) { - if (i == _sub_band_id) { - mask.concat("FF"); - } else { - mask.concat("00"); - } - } - _modem.sendMask(mask); + // Set channelmask based on configuration + if (_channelMask) { + _modem.sendMask(_channelMask); } //A delay is required between _modem.begin(band) and _modem.joinOTAA(appeui, appkey) in order to let the chip to be correctly initialized before the connection attempt delay(100); diff --git a/src/Arduino_LoRaConnectionHandler.h b/src/Arduino_LoRaConnectionHandler.h index 2b6dc38e..2d76cb34 100644 --- a/src/Arduino_LoRaConnectionHandler.h +++ b/src/Arduino_LoRaConnectionHandler.h @@ -32,7 +32,7 @@ class LoRaConnectionHandler : public ConnectionHandler { public: - LoRaConnectionHandler(char const * appeui, char const * appkey, _lora_band const band = _lora_band::EU868, uint8_t const sub_band_id = 0, _lora_class const device_class = _lora_class::CLASS_A); + LoRaConnectionHandler(char const * appeui, char const * appkey, _lora_band const band = _lora_band::EU868, char const * channelMask = NULL, _lora_class const device_class = _lora_class::CLASS_A); virtual int write(const uint8_t *buf, size_t size) override; virtual int read() override; @@ -67,7 +67,7 @@ class LoRaConnectionHandler : public ConnectionHandler char const * _appeui; char const * _appkey; _lora_band _band; - uint8_t _sub_band_id; + char const * _channelMask; _lora_class _device_class; LoRaModem _modem; }; From 6319f10b98111315d9f4f813174eda0ba0a70176 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 2 Nov 2021 10:48:08 +0100 Subject: [PATCH 047/203] Release 0.6.5 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 7944e434..0bc96e75 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.6.4 +version=0.6.5 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 28fc65b7492b6223a2b6dcc6fcfcc4ada12c79da Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 10 Jan 2022 00:46:49 -0800 Subject: [PATCH 048/203] Add GitHub Actions workflow to synchronize with shared repository labels (#72) On every push that changes relevant files, and periodically, configure the repository's issue and pull request labels according to the universal, shared, and local label configuration files. --- .github/dependabot.yml | 2 + .github/workflows/sync-labels.yml | 138 ++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 .github/workflows/sync-labels.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 03600dd7..fa738ec4 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,3 +8,5 @@ updates: directory: / # Check the repository's workflows under /.github/workflows/ schedule: interval: daily + labels: + - "topic: infrastructure" diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml new file mode 100644 index 00000000..3ee6febd --- /dev/null +++ b/.github/workflows/sync-labels.yml @@ -0,0 +1,138 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md +name: Sync Labels + +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + pull_request: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + schedule: + # Run daily at 8 AM UTC to sync with changes to shared label configurations. + - cron: "0 8 * * *" + workflow_dispatch: + repository_dispatch: + +env: + CONFIGURATIONS_FOLDER: .github/label-configuration-files + CONFIGURATIONS_ARTIFACT: label-configuration-files + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Download JSON schema for labels configuration file + id: download-schema + uses: carlosperate/download-file-action@v1 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json + location: ${{ runner.temp }}/label-configuration-schema + + - name: Install JSON schema validator + run: | + sudo npm install \ + --global \ + ajv-cli \ + ajv-formats + + - name: Validate local labels configuration + run: | + # See: https://github.com/ajv-validator/ajv-cli#readme + ajv validate \ + --all-errors \ + -c ajv-formats \ + -s "${{ steps.download-schema.outputs.file-path }}" \ + -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" + + download: + needs: check + runs-on: ubuntu-latest + + strategy: + matrix: + filename: + # Filenames of the shared configurations to apply to the repository in addition to the local configuration. + # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels + - universal.yml + + steps: + - name: Download + uses: carlosperate/download-file-action@v1 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} + + - name: Pass configuration files to next job via workflow artifact + uses: actions/upload-artifact@v2 + with: + path: | + *.yaml + *.yml + if-no-files-found: error + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + sync: + needs: download + runs-on: ubuntu-latest + + steps: + - name: Set environment variables + run: | + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable + echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" + + - name: Determine whether to dry run + id: dry-run + if: > + github.event_name == 'pull_request' || + ( + ( + github.event_name == 'push' || + github.event_name == 'workflow_dispatch' + ) && + github.ref != format('refs/heads/{0}', github.event.repository.default_branch) + ) + run: | + # Use of this flag in the github-label-sync command will cause it to only check the validity of the + # configuration. + echo "::set-output name=flag::--dry-run" + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Download configuration files artifact + uses: actions/download-artifact@v2 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + path: ${{ env.CONFIGURATIONS_FOLDER }} + + - name: Remove unneeded artifact + uses: geekyeggo/delete-artifact@v1 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + - name: Merge label configuration files + run: | + # Merge all configuration files + shopt -s extglob + cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" + + - name: Install github-label-sync + run: sudo npm install --global github-label-sync + + - name: Sync labels + env: + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # See: https://github.com/Financial-Times/github-label-sync + github-label-sync \ + --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ + ${{ steps.dry-run.outputs.flag }} \ + ${{ github.repository }} From f5481d2827c3b4414005998bd1894e9c16471272 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Mar 2022 13:14:06 +0000 Subject: [PATCH 049/203] Bump actions/checkout from 2 to 3 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/check-arduino.yml | 2 +- .github/workflows/compile-examples.yml | 6 +++--- .github/workflows/spell-check.yml | 2 +- .github/workflows/sync-labels.yml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index 0d969f6c..3e0d26c9 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Arduino Lint uses: arduino/arduino-lint-action@v1 diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index bd7849e2..1b2530be 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -95,13 +95,13 @@ jobs: source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 # It's necessary to checkout the platform before installing it so that the ArduinoCore-API dependency can be added - name: Checkout ArduinoCore-mbed # this step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used if: matrix.board.platform-name == 'arduino:mbed' - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: arduino/ArduinoCore-mbed # The arduino/actions/libraries/compile-examples action will install the platform from this path @@ -110,7 +110,7 @@ jobs: - name: Checkout ArduinoCore-API # This step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used if: matrix.board.platform-name == 'arduino:mbed' - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: arduino/ArduinoCore-API path: ${{ env.ARDUINOCORE_API_STAGING_PATH }} diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 01bee879..3f6b03fb 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Spell check uses: codespell-project/actions-codespell@master diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 3ee6febd..4ea57559 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Download JSON schema for labels configuration file id: download-schema @@ -105,7 +105,7 @@ jobs: echo "::set-output name=flag::--dry-run" - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Download configuration files artifact uses: actions/download-artifact@v2 From 6dd64fb8b869c646ef4c99db24abe32089299849 Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 4 Mar 2022 12:27:22 +0100 Subject: [PATCH 050/203] Add support for ARDUINO_NICLA_VISION --- src/Arduino_ConnectionHandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 6496b931..145467dc 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -43,7 +43,7 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION #endif -#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) +#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_NICLA_VISION) #include #include From 1ae66070ffdfa0cebbd057c0fa69dcde76d2021f Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 7 Mar 2022 17:03:15 +0100 Subject: [PATCH 051/203] Add mbed_nicla to supported platforms --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 0bc96e75..e3fad4a6 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethe 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 +architectures=samd,esp32,esp8266,mbed,megaavr,mbed_nano,mbed_portenta,mbed_nicla depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN From 5a2c103f1e64d71b2c9dc8151c6f8f3e8e7cbb30 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 8 Mar 2022 12:17:20 +0100 Subject: [PATCH 052/203] Add nicla_vision to compile-examples workflow --- .github/workflows/compile-examples.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index bd7849e2..24102953 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -64,6 +64,8 @@ jobs: platform-name: esp32:esp32 - fqbn: arduino:mbed_nano:nanorp2040connect platform-name: arduino:mbed_nano + - fqbn: arduino:mbed_nicla:nicla_vision + platform-name: arduino:mbed_nicla # Make board type-specific customizations to the matrix jobs include: From d5a578a9b800628fa1f0678e428d0b81c4338bf9 Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Tue, 8 Mar 2022 16:38:52 +0100 Subject: [PATCH 053/203] Update README adding missing boards --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ffe7c2c6..17eef2e6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Arduino Library for network connections management [![Spell Check status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml) Library for handling and managing network connections by providing keep-alive functionality and automatic reconnection in case of connection-loss. It supports the following boards: -* **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), `ESP8266` +* **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/products/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), `ESP8266` * **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415) * **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413) * **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) From 98db5e61bfde16e8f0be1aca008749cc106a7745 Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Tue, 8 Mar 2022 17:03:19 +0100 Subject: [PATCH 054/203] Release v0.6.6 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index e3fad4a6..12eb186f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.6.5 +version=0.6.6 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From c897c65e75128efabaf0b208ed1552550389beb2 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 9 Mar 2022 12:04:48 +0100 Subject: [PATCH 055/203] Remove ARDUINO_PORTENTA_H7_M4 form supported build options --- src/Arduino_ConnectionHandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 145467dc..5d9736c2 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -43,7 +43,7 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION #endif -#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_NICLA_VISION) +#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) #include #include From 8a52bf4adab308ef74f9f65caefc87b5bb73a995 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 9 Mar 2022 12:05:20 +0100 Subject: [PATCH 056/203] Remove envie_m4 from compile examples workflow --- .github/workflows/compile-examples.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 826ad3e0..1f235cac 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -56,8 +56,6 @@ jobs: platform-name: arduino:samd - fqbn: "arduino:mbed:envie_m7" platform-name: arduino:mbed - - fqbn: "arduino:mbed:envie_m4" - platform-name: arduino:mbed - fqbn: "esp8266:esp8266:huzzah" platform-name: esp8266:esp8266 - fqbn: "esp32:esp32:esp32" From 5578b942819350bc73d3918d5b0362f0fa735043 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Apr 2022 13:34:23 +0000 Subject: [PATCH 057/203] Bump actions/upload-artifact from 2 to 3 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2 to 3. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/compile-examples.yml | 2 +- .github/workflows/sync-labels.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 826ad3e0..cca40d77 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -138,7 +138,7 @@ jobs: - name: Save memory usage change report as artifact if: github.event_name == 'pull_request' - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: if-no-files-found: error name: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 4ea57559..1d969d57 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -70,7 +70,7 @@ jobs: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} - name: Pass configuration files to next job via workflow artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: path: | *.yaml From 83ce35aee172bfb745e364b24226714850c04a82 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Apr 2022 13:34:26 +0000 Subject: [PATCH 058/203] Bump actions/download-artifact from 2 to 3 Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 2 to 3. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 4ea57559..e84e803e 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -108,7 +108,7 @@ jobs: uses: actions/checkout@v3 - name: Download configuration files artifact - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} path: ${{ env.CONFIGURATIONS_FOLDER }} From 78b21c29ef651e252f044af8c4ca1951e1759d84 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 14 Jul 2022 10:48:49 +0200 Subject: [PATCH 059/203] Use generic ARDUINO_ARCH_ESP8226 instead of board specific defines --- src/Arduino_ConnectionHandler.h | 33 +-------------------------- src/Arduino_WiFiConnectionHandler.cpp | 16 ++++++------- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 5d9736c2..5b17e3e9 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -74,38 +74,7 @@ #define BOARD_HAS_LORA #endif -#if defined(ARDUINO_ESP8266_ESP12) \ - || defined(ESP8266) \ - || defined(ESP8266_ESP01) \ - || defined(ESP8266_ESP13) \ - || defined(ESP8266_GENERIC) \ - || defined(ESP8266_ESPRESSO_LITE_V1) \ - || defined(ESP8266_ESPRESSO_LITE_V2) \ - || defined(ESP8266_PHOENIX_V1) \ - || defined(ESP8266_PHOENIX_V2) \ - || defined(ESP8266_NODEMCU) \ - || defined(MOD_WIFI_ESP8266) \ - || defined(ESP8266_THING) \ - || defined(ESP8266_THING_DEV) \ - || defined(ESP8266_ESP210) \ - || defined(ESP8266_WEMOS_D1MINI) \ - || defined(ESP8266_WEMOS_D1MINIPRO) \ - || defined(ESP8266_WEMOS_D1MINILITE) \ - || defined(ESP8266_WEMOS_D1R1) \ - || defined(ESP8266_ESP12) \ - || defined(WIFINFO) \ - || defined(ESP8266_ARDUINO) \ - || defined(GEN4_IOD) \ - || defined(ESP8266_OAK) \ - || defined(WIFIDUINO_ESP8266) \ - || defined(AMPERKA_WIFI_SLOT) \ - || defined(ESP8266_WIO_LINK) \ - || defined(ESP8266_ESPECTRO_CORE) - - #define BOARD_ESP8266 -#endif - -#if defined(BOARD_ESP8266) +#if defined(ARDUINO_ARCH_ESP8266) #include #include diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index e1a1f12d..82722fc1 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -41,7 +41,7 @@ WiFiConnectionHandler::WiFiConnectionHandler(char const * ssid, char const * pas unsigned long WiFiConnectionHandler::getTime() { -#if !defined(BOARD_ESP8266) && !defined(ESP32) +#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ESP32) return WiFi.getTime(); #else return 0; @@ -54,7 +54,7 @@ unsigned long WiFiConnectionHandler::getTime() NetworkConnectionState WiFiConnectionHandler::update_handleInit() { -#if !defined(BOARD_ESP8266) && !defined(ESP32) +#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ESP32) #if !defined(__AVR__) Debug.print(DBG_INFO, F("WiFi.status(): %d"), WiFi.status()); #endif @@ -87,19 +87,19 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() delay(300); WiFi.begin(_ssid, _pass); delay(1000); -#endif /* #if !defined(BOARD_ESP8266) && !defined(ESP32) */ +#endif /* #if !defined(ARDUINO_ARCH_ESP8266) && !defined(ESP32) */ return NetworkConnectionState::CONNECTING; } NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() { -#if !defined(BOARD_ESP8266) && !defined(ESP32) +#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ESP32) if (WiFi.status() != WL_CONNECTED) { WiFi.begin(_ssid, _pass); } -#endif /* ifndef BOARD_ESP8266 */ +#endif /* ifndef ARDUINO_ARCH_ESP8266 */ if (WiFi.status() != NETWORK_CONNECTED) { @@ -114,7 +114,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() #if !defined(__AVR__) Debug.print(DBG_INFO, F("Connected to \"%s\""), _ssid); #endif -#if defined(BOARD_ESP8266) || defined(ESP32) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ESP32) configTime(0, 0, "time.arduino.cc", "pool.ntp.org", "time.nist.gov"); #endif return NetworkConnectionState::CONNECTED; @@ -149,9 +149,9 @@ NetworkConnectionState WiFiConnectionHandler::update_handleDisconnecting() NetworkConnectionState WiFiConnectionHandler::update_handleDisconnected() { -#if !defined(BOARD_ESP8266) && !defined(ESP32) +#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ESP32) WiFi.end(); -#endif /* ifndef BOARD_ESP8266 */ +#endif /* ifndef ARDUINO_ARCH_ESP8266 */ if (_keep_alive) { return NetworkConnectionState::INIT; From f47688482af960f4532a8c8a1296bab95c50054f Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 14 Jul 2022 10:52:32 +0200 Subject: [PATCH 060/203] Use ARDUINO_ARCH_ESP32 instead of ESP32 to align defines strategy --- src/Arduino_ConnectionHandler.h | 18 +++++++++--------- src/Arduino_WiFiConnectionHandler.cpp | 16 ++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 5b17e3e9..cc70f5fe 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -85,15 +85,15 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED #endif -#if defined(ESP32) - #include - #include - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED - #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED - +#if defined(ARDUINO_ARCH_ESP32) + #include + #include + + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED + #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED #endif /****************************************************************************** diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 82722fc1..45a23b99 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -41,7 +41,7 @@ WiFiConnectionHandler::WiFiConnectionHandler(char const * ssid, char const * pas unsigned long WiFiConnectionHandler::getTime() { -#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ESP32) +#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) return WiFi.getTime(); #else return 0; @@ -54,7 +54,7 @@ unsigned long WiFiConnectionHandler::getTime() NetworkConnectionState WiFiConnectionHandler::update_handleInit() { -#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ESP32) +#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) #if !defined(__AVR__) Debug.print(DBG_INFO, F("WiFi.status(): %d"), WiFi.status()); #endif @@ -87,19 +87,19 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() delay(300); WiFi.begin(_ssid, _pass); delay(1000); -#endif /* #if !defined(ARDUINO_ARCH_ESP8266) && !defined(ESP32) */ +#endif /* #if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) */ return NetworkConnectionState::CONNECTING; } NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() { -#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ESP32) +#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) if (WiFi.status() != WL_CONNECTED) { WiFi.begin(_ssid, _pass); } -#endif /* ifndef ARDUINO_ARCH_ESP8266 */ +#endif /* #if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) */ if (WiFi.status() != NETWORK_CONNECTED) { @@ -114,7 +114,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() #if !defined(__AVR__) Debug.print(DBG_INFO, F("Connected to \"%s\""), _ssid); #endif -#if defined(ARDUINO_ARCH_ESP8266) || defined(ESP32) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) configTime(0, 0, "time.arduino.cc", "pool.ntp.org", "time.nist.gov"); #endif return NetworkConnectionState::CONNECTED; @@ -149,9 +149,9 @@ NetworkConnectionState WiFiConnectionHandler::update_handleDisconnecting() NetworkConnectionState WiFiConnectionHandler::update_handleDisconnected() { -#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ESP32) +#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) WiFi.end(); -#endif /* ifndef ARDUINO_ARCH_ESP8266 */ +#endif /* #if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) */ if (_keep_alive) { return NetworkConnectionState::INIT; From 7ab21acea7a014a71f875e75b685bfa89f20164c Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 14 Jul 2022 12:03:14 +0200 Subject: [PATCH 061/203] Add EthernetConnectionHandler --- keywords.txt | 1 + src/Arduino_ConnectionHandler.h | 6 +- src/Arduino_EthernetConnectionHandler.cpp | 82 +++++++++++++++++++++++ src/Arduino_EthernetConnectionHandler.h | 61 +++++++++++++++++ 4 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 src/Arduino_EthernetConnectionHandler.cpp create mode 100644 src/Arduino_EthernetConnectionHandler.h diff --git a/keywords.txt b/keywords.txt index 8d9e9434..4ac67251 100644 --- a/keywords.txt +++ b/keywords.txt @@ -10,6 +10,7 @@ WiFiConnectionHandler KEYWORD1 GSMConnectionHandler KEYWORD1 NBConnectionHandler KEYWORD1 LoRaConnectionHandler KEYWORD1 +EthernetConnectionHandler KEYWORD1 #################################################### # Methods and Functions (KEYWORD2) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index cc70f5fe..abe3f9ea 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -153,7 +153,7 @@ class ConnectionHandler { NetworkConnectionState check(); - #if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) + #if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) virtual unsigned long getTime() = 0; virtual Client &getClient() = 0; virtual UDP &getUDP() = 0; @@ -207,4 +207,8 @@ class ConnectionHandler { #include "Arduino_LoRaConnectionHandler.h" #endif +#if defined(BOARD_HAS_ETHERNET) + #include "Arduino_EthernetConnectionHandler.h" +#endif + #endif /* CONNECTION_HANDLER_H_ */ diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp new file mode 100644 index 00000000..fff9d052 --- /dev/null +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -0,0 +1,82 @@ +/* + This file is part of ArduinoIoTCloud. + Copyright 2020 ARDUINO SA (http://www.arduino.cc/) + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +/****************************************************************************** + INCLUDE + ******************************************************************************/ + +#include "Arduino_EthernetConnectionHandler.h" + +#ifdef BOARD_HAS_ETHERNET /* Only compile if the board has ethernet */ + +/****************************************************************************** + CTOR/DTOR + ******************************************************************************/ + +EthernetConnectionHandler::EthernetConnectionHandler(uint8_t * mac, bool const keep_alive) +: ConnectionHandler{keep_alive} +, _mac{mac} +{ + +} + +/****************************************************************************** + PROTECTED MEMBER FUNCTIONS + ******************************************************************************/ + +NetworkConnectionState EthernetConnectionHandler::update_handleInit() +{ + if (Ethernet.begin(const_cast(_mac)) == 0) { + Debug.print(DBG_ERROR, F("Failed to configure Ethernet using DHCP")); + + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Debug.print(DBG_ERROR, F("Error, ethernet shield was not found.")); + return NetworkConnectionState::ERROR; + } + + if (Ethernet.linkStatus() == LinkOFF) { + Debug.print(DBG_ERROR, F("Error, ethernet cable is not connected.")); + return NetworkConnectionState::ERROR; + } + + return NetworkConnectionState::ERROR; + } + + return NetworkConnectionState::CONNECTING; +} + +NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() +{ + return NetworkConnectionState::CONNECTED; +} + +NetworkConnectionState EthernetConnectionHandler::update_handleConnected() +{ + if (Ethernet.linkStatus() == LinkON) + return NetworkConnectionState::CONNECTED; + else + return NetworkConnectionState::DISCONNECTED; +} + +NetworkConnectionState EthernetConnectionHandler::update_handleDisconnecting() +{ + return NetworkConnectionState::DISCONNECTED; +} + +NetworkConnectionState EthernetConnectionHandler::update_handleDisconnected() +{ + return NetworkConnectionState::INIT; +} + +#endif /* #ifdef BOARD_HAS_ETHERNET */ diff --git a/src/Arduino_EthernetConnectionHandler.h b/src/Arduino_EthernetConnectionHandler.h new file mode 100644 index 00000000..3c36caea --- /dev/null +++ b/src/Arduino_EthernetConnectionHandler.h @@ -0,0 +1,61 @@ +/* + This file is part of ArduinoIoTCloud. + Copyright 2020 ARDUINO SA (http://www.arduino.cc/) + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#ifndef ARDUINO_ETHERNET_CONNECTION_HANDLER_H_ +#define ARDUINO_ETHERNET_CONNECTION_HANDLER_H_ + +/****************************************************************************** + INCLUDE + ******************************************************************************/ + +#include "Arduino_ConnectionHandler.h" + +#ifdef BOARD_HAS_ETHERNET /* Only compile if the board has ethernet */ + +/****************************************************************************** + CLASS DECLARATION + ******************************************************************************/ + +class EthernetConnectionHandler : public ConnectionHandler +{ + public: + + EthernetConnectionHandler(uint8_t * mac, bool const keep_alive = true); + + + virtual unsigned long getTime() override { return 0; } + virtual Client & getClient() override{ return _eth_client; } + virtual UDP & getUDP() override { return _eth_udp; } + + + protected: + + virtual NetworkConnectionState update_handleInit () override; + virtual NetworkConnectionState update_handleConnecting () override; + virtual NetworkConnectionState update_handleConnected () override; + virtual NetworkConnectionState update_handleDisconnecting() override; + virtual NetworkConnectionState update_handleDisconnected () override; + + private: + + uint8_t const * _mac; + + EthernetUDP _eth_udp; + EthernetClient _eth_client; + +}; + +#endif /* #ifdef BOARD_HAS_ETHERNET */ + +#endif /* ARDUINO_ETHERNET_CONNECTION_HANDLER_H_ */ From d47a687fde51a6e714934f44aeb1363631531f2f Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 14 Jul 2022 12:07:19 +0200 Subject: [PATCH 062/203] Enable Ethernet support for Portenta H7. Needs Vision shield --- src/Arduino_ConnectionHandler.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index abe3f9ea..8f028684 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -43,7 +43,18 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION #endif -#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) +#if defined(ARDUINO_PORTENTA_H7_M7) + #include + #include + + #define BOARD_HAS_WIFI + #define BOARD_HAS_PORTENTA_VISION_SHIELD + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + +#if defined(ARDUINO_NICLA_VISION) #include #include @@ -96,6 +107,12 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED #endif +#if defined(BOARD_HAS_PORTENTA_VISION_SHIELD) + #define BOARD_HAS_ETHERNET + + #include +#endif + /****************************************************************************** INCLUDES ******************************************************************************/ From 9cb7f992163cea2ee32c2f02c84004f6f7e6de61 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 21 Jul 2022 11:19:58 +0200 Subject: [PATCH 063/203] Remove MAC address configuration --- src/Arduino_EthernetConnectionHandler.cpp | 5 ++--- src/Arduino_EthernetConnectionHandler.h | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp index fff9d052..cdb6b2de 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -24,9 +24,8 @@ CTOR/DTOR ******************************************************************************/ -EthernetConnectionHandler::EthernetConnectionHandler(uint8_t * mac, bool const keep_alive) +EthernetConnectionHandler::EthernetConnectionHandler(bool const keep_alive) : ConnectionHandler{keep_alive} -, _mac{mac} { } @@ -37,7 +36,7 @@ EthernetConnectionHandler::EthernetConnectionHandler(uint8_t * mac, bool const k NetworkConnectionState EthernetConnectionHandler::update_handleInit() { - if (Ethernet.begin(const_cast(_mac)) == 0) { + if (Ethernet.begin() == 0) { Debug.print(DBG_ERROR, F("Failed to configure Ethernet using DHCP")); if (Ethernet.hardwareStatus() == EthernetNoHardware) { diff --git a/src/Arduino_EthernetConnectionHandler.h b/src/Arduino_EthernetConnectionHandler.h index 3c36caea..92b44179 100644 --- a/src/Arduino_EthernetConnectionHandler.h +++ b/src/Arduino_EthernetConnectionHandler.h @@ -31,7 +31,7 @@ class EthernetConnectionHandler : public ConnectionHandler { public: - EthernetConnectionHandler(uint8_t * mac, bool const keep_alive = true); + EthernetConnectionHandler(bool const keep_alive = true); virtual unsigned long getTime() override { return 0; } @@ -49,8 +49,6 @@ class EthernetConnectionHandler : public ConnectionHandler private: - uint8_t const * _mac; - EthernetUDP _eth_udp; EthernetClient _eth_client; From 37758d37af1b21ef8c54e3041dc039b1dba13cf8 Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 22 Jul 2022 15:57:13 +0200 Subject: [PATCH 064/203] Add function to get the hardware network interface type used for connection --- src/Arduino_ConnectionHandler.cpp | 3 ++- src/Arduino_ConnectionHandler.h | 15 ++++++++++++++- src/Arduino_EthernetConnectionHandler.cpp | 2 +- src/Arduino_GSMConnectionHandler.cpp | 2 +- src/Arduino_LoRaConnectionHandler.cpp | 2 +- src/Arduino_NBConnectionHandler.cpp | 2 +- src/Arduino_WiFiConnectionHandler.cpp | 2 +- 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Arduino_ConnectionHandler.cpp b/src/Arduino_ConnectionHandler.cpp index 943fa1d9..ab83fa08 100644 --- a/src/Arduino_ConnectionHandler.cpp +++ b/src/Arduino_ConnectionHandler.cpp @@ -25,8 +25,9 @@ CONSTRUCTOR/DESTRUCTOR ******************************************************************************/ -ConnectionHandler::ConnectionHandler(bool const keep_alive) +ConnectionHandler::ConnectionHandler(bool const keep_alive, NetworkAdapter interface) : _keep_alive{keep_alive} +, _interface{interface} , _lastConnectionTickTime{millis()} , _current_net_connection_state{NetworkConnectionState::INIT} { diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 8f028684..b55954f4 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -141,6 +141,14 @@ enum class NetworkConnectionEvent { ERROR }; +enum class NetworkAdapter { + WIFI, + ETHERNET, + NB, + GSM, + LORA +}; + typedef void (*OnNetworkEventCallback)(); /****************************************************************************** @@ -165,7 +173,7 @@ static unsigned int const CHECK_INTERVAL_TABLE[] = class ConnectionHandler { public: - ConnectionHandler(bool const keep_alive); + ConnectionHandler(bool const keep_alive, NetworkAdapter interface); NetworkConnectionState check(); @@ -186,6 +194,10 @@ class ConnectionHandler { return _current_net_connection_state; } + NetworkAdapter getInterface() { + return _interface; + } + void connect(); void disconnect(); @@ -197,6 +209,7 @@ class ConnectionHandler { protected: bool _keep_alive; + NetworkAdapter _interface; virtual NetworkConnectionState update_handleInit () = 0; virtual NetworkConnectionState update_handleConnecting () = 0; diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp index cdb6b2de..c9c205c8 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -25,7 +25,7 @@ ******************************************************************************/ EthernetConnectionHandler::EthernetConnectionHandler(bool const keep_alive) -: ConnectionHandler{keep_alive} +: ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} { } diff --git a/src/Arduino_GSMConnectionHandler.cpp b/src/Arduino_GSMConnectionHandler.cpp index 3bf8b908..e57a7201 100644 --- a/src/Arduino_GSMConnectionHandler.cpp +++ b/src/Arduino_GSMConnectionHandler.cpp @@ -47,7 +47,7 @@ __attribute__((weak)) void mkr_gsm_feed_watchdog() ******************************************************************************/ GSMConnectionHandler::GSMConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, bool const keep_alive) -: ConnectionHandler{keep_alive} +: ConnectionHandler{keep_alive, NetworkAdapter::GSM} , _pin(pin) , _apn(apn) , _login(login) diff --git a/src/Arduino_LoRaConnectionHandler.cpp b/src/Arduino_LoRaConnectionHandler.cpp index e34092b0..886c7e3f 100644 --- a/src/Arduino_LoRaConnectionHandler.cpp +++ b/src/Arduino_LoRaConnectionHandler.cpp @@ -44,7 +44,7 @@ typedef enum CTOR/DTOR ******************************************************************************/ LoRaConnectionHandler::LoRaConnectionHandler(char const * appeui, char const * appkey, _lora_band const band, char const * channelMask, _lora_class const device_class) -: ConnectionHandler{false} +: ConnectionHandler{false, NetworkAdapter::LORA} , _appeui(appeui) , _appkey(appkey) , _band(band) diff --git a/src/Arduino_NBConnectionHandler.cpp b/src/Arduino_NBConnectionHandler.cpp index 8c747edf..ae74a238 100644 --- a/src/Arduino_NBConnectionHandler.cpp +++ b/src/Arduino_NBConnectionHandler.cpp @@ -57,7 +57,7 @@ NBConnectionHandler::NBConnectionHandler(char const * pin, char const * apn, boo } NBConnectionHandler::NBConnectionHandler(char const * pin, char const * apn, char const * login, char const * pass, bool const keep_alive) -: ConnectionHandler{keep_alive} +: ConnectionHandler{keep_alive, NetworkAdapter::NB} , _pin(pin) , _apn(apn) , _login(login) diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 45a23b99..eb897450 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -28,7 +28,7 @@ ******************************************************************************/ WiFiConnectionHandler::WiFiConnectionHandler(char const * ssid, char const * pass, bool const keep_alive) -: ConnectionHandler{keep_alive} +: ConnectionHandler{keep_alive, NetworkAdapter::WIFI} , _ssid{ssid} , _pass{pass} { From a3af901c5b83e5c93318e93697aa4f50d1e4d8d5 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 25 Jul 2022 13:45:27 +0200 Subject: [PATCH 065/203] Handle automatic retries on connect/disconnect --- src/Arduino_EthernetConnectionHandler.cpp | 51 +++++++++++++++-------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp index c9c205c8..374b9c5c 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -36,46 +36,61 @@ EthernetConnectionHandler::EthernetConnectionHandler(bool const keep_alive) NetworkConnectionState EthernetConnectionHandler::update_handleInit() { - if (Ethernet.begin() == 0) { - Debug.print(DBG_ERROR, F("Failed to configure Ethernet using DHCP")); - - if (Ethernet.hardwareStatus() == EthernetNoHardware) { - Debug.print(DBG_ERROR, F("Error, ethernet shield was not found.")); - return NetworkConnectionState::ERROR; - } - - if (Ethernet.linkStatus() == LinkOFF) { - Debug.print(DBG_ERROR, F("Error, ethernet cable is not connected.")); - return NetworkConnectionState::ERROR; - } - + if (Ethernet.hardwareStatus() == EthernetNoHardware) { +#if !defined(__AVR__) + Debug.print(DBG_ERROR, F("Error, ethernet shield was not found.")); +#endif return NetworkConnectionState::ERROR; } - return NetworkConnectionState::CONNECTING; } NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() { + if (Ethernet.begin(nullptr, 15000, 4000) == 0) { +#if !defined(__AVR__) + Debug.print(DBG_ERROR, F("Waiting Ethernet configuration from DHCP server, check cable connection")); +#endif + return NetworkConnectionState::CONNECTING; + } return NetworkConnectionState::CONNECTED; } NetworkConnectionState EthernetConnectionHandler::update_handleConnected() { - if (Ethernet.linkStatus() == LinkON) - return NetworkConnectionState::CONNECTED; - else + if (Ethernet.linkStatus() == LinkOFF) { +#if !defined(__AVR__) + Debug.print(DBG_VERBOSE, F("Ethernet.status(): %d"), Ethernet.status()); + Debug.print(DBG_ERROR, F("Connection lost.")); +#endif + if (_keep_alive) + { +#if !defined(__AVR__) + Debug.print(DBG_ERROR, F("Attempting reconnection")); +#endif + } return NetworkConnectionState::DISCONNECTED; + } + return NetworkConnectionState::CONNECTED; } NetworkConnectionState EthernetConnectionHandler::update_handleDisconnecting() { + Ethernet.disconnect(); return NetworkConnectionState::DISCONNECTED; } NetworkConnectionState EthernetConnectionHandler::update_handleDisconnected() { - return NetworkConnectionState::INIT; + Ethernet.end(); + if (_keep_alive) + { + return NetworkConnectionState::INIT; + } + else + { + return NetworkConnectionState::CLOSED; + } } #endif /* #ifdef BOARD_HAS_ETHERNET */ From 349cee21261c50a95414c980d5190c38b6910791 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 26 Jul 2022 14:41:13 +0200 Subject: [PATCH 066/203] Add CTOR and logic for static IP configuration --- src/Arduino_EthernetConnectionHandler.cpp | 29 ++++++++++++++++++++--- src/Arduino_EthernetConnectionHandler.h | 6 +++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp index 374b9c5c..71382603 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -26,6 +26,20 @@ EthernetConnectionHandler::EthernetConnectionHandler(bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} +,_ip{INADDR_NONE} +,_dns{INADDR_NONE} +,_gateway{INADDR_NONE} +,_subnet{INADDR_NONE} +{ + +} + +EthernetConnectionHandler::EthernetConnectionHandler(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, bool const keep_alive) +: ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} +,_ip{ip} +,_dns{dns} +,_gateway{gateway} +,_subnet{subnet} { } @@ -47,11 +61,20 @@ NetworkConnectionState EthernetConnectionHandler::update_handleInit() NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() { - if (Ethernet.begin(nullptr, 15000, 4000) == 0) { + if (_ip != INADDR_NONE) { + if (Ethernet.begin(nullptr, _ip, _dns, _gateway, _subnet, 15000, 4000) == 0) { #if !defined(__AVR__) - Debug.print(DBG_ERROR, F("Waiting Ethernet configuration from DHCP server, check cable connection")); + Debug.print(DBG_ERROR, F("Failed to configure Ethernet, check cable connection")); #endif - return NetworkConnectionState::CONNECTING; + return NetworkConnectionState::CONNECTING; + } + } else { + if (Ethernet.begin(nullptr, 15000, 4000) == 0) { +#if !defined(__AVR__) + Debug.print(DBG_ERROR, F("Waiting Ethernet configuration from DHCP server, check cable connection")); +#endif + return NetworkConnectionState::CONNECTING; + } } return NetworkConnectionState::CONNECTED; } diff --git a/src/Arduino_EthernetConnectionHandler.h b/src/Arduino_EthernetConnectionHandler.h index 92b44179..f9074e74 100644 --- a/src/Arduino_EthernetConnectionHandler.h +++ b/src/Arduino_EthernetConnectionHandler.h @@ -32,6 +32,7 @@ class EthernetConnectionHandler : public ConnectionHandler public: EthernetConnectionHandler(bool const keep_alive = true); + EthernetConnectionHandler(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, bool const keep_alive = true); virtual unsigned long getTime() override { return 0; } @@ -49,6 +50,11 @@ class EthernetConnectionHandler : public ConnectionHandler private: + IPAddress _ip; + IPAddress _dns; + IPAddress _gateway; + IPAddress _subnet; + EthernetUDP _eth_udp; EthernetClient _eth_client; From 328bd83be8424f2093ab6936a7f13db7825c87e2 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 3 Aug 2022 08:44:57 +0200 Subject: [PATCH 067/203] Use more detailed define to enable ethernet support Otherwise we cannot distinguish between LoRa/Ethernet Vision Shield --- src/Arduino_ConnectionHandler.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index b55954f4..aaade80e 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -48,7 +48,7 @@ #include #define BOARD_HAS_WIFI - #define BOARD_HAS_PORTENTA_VISION_SHIELD + #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD #define NETWORK_IDLE_STATUS WL_IDLE_STATUS #define NETWORK_CONNECTED WL_CONNECTED @@ -107,7 +107,7 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED #endif -#if defined(BOARD_HAS_PORTENTA_VISION_SHIELD) +#if defined(BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET) #define BOARD_HAS_ETHERNET #include From 9b74bb698d91b51d51a42dfe564e0126a6f938c6 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 14 Sep 2022 09:38:48 +0200 Subject: [PATCH 068/203] Add missing include file --- src/Arduino_ConnectionHandler.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index aaade80e..f622834b 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -54,6 +54,13 @@ #define NETWORK_CONNECTED WL_CONNECTED #endif +#if defined(BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET) + #include + #include + + #define BOARD_HAS_ETHERNET +#endif + #if defined(ARDUINO_NICLA_VISION) #include #include @@ -107,12 +114,6 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED #endif -#if defined(BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET) - #define BOARD_HAS_ETHERNET - - #include -#endif - /****************************************************************************** INCLUDES ******************************************************************************/ From dafc31b36a03b30c6d2106d16791d5581fe0b246 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 14 Sep 2022 09:43:01 +0200 Subject: [PATCH 069/203] Remove useless call to Ethernet.end() --- src/Arduino_EthernetConnectionHandler.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp index 71382603..2b71319d 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -105,7 +105,6 @@ NetworkConnectionState EthernetConnectionHandler::update_handleDisconnecting() NetworkConnectionState EthernetConnectionHandler::update_handleDisconnected() { - Ethernet.end(); if (_keep_alive) { return NetworkConnectionState::INIT; From 8f0b5946e78e85241b96fb706723634d47073386 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 14 Sep 2022 10:12:02 +0200 Subject: [PATCH 070/203] Simplify debug prints --- src/Arduino_EthernetConnectionHandler.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp index 2b71319d..75450fe8 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -83,8 +83,7 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnected() { if (Ethernet.linkStatus() == LinkOFF) { #if !defined(__AVR__) - Debug.print(DBG_VERBOSE, F("Ethernet.status(): %d"), Ethernet.status()); - Debug.print(DBG_ERROR, F("Connection lost.")); + Debug.print(DBG_ERROR, F("Ethernet link OFF, connection lost.")); #endif if (_keep_alive) { From a3fee7ea58599c77e7639857e7b9ee9cf831666f Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 14 Sep 2022 16:43:14 +0200 Subject: [PATCH 071/203] Drop #if !defined(__AVR__) statements --- src/Arduino_EthernetConnectionHandler.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp index 75450fe8..8c129c7e 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -51,9 +51,7 @@ EthernetConnectionHandler::EthernetConnectionHandler(IPAddress ip, IPAddress dns NetworkConnectionState EthernetConnectionHandler::update_handleInit() { if (Ethernet.hardwareStatus() == EthernetNoHardware) { -#if !defined(__AVR__) Debug.print(DBG_ERROR, F("Error, ethernet shield was not found.")); -#endif return NetworkConnectionState::ERROR; } return NetworkConnectionState::CONNECTING; @@ -63,33 +61,26 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() { if (_ip != INADDR_NONE) { if (Ethernet.begin(nullptr, _ip, _dns, _gateway, _subnet, 15000, 4000) == 0) { -#if !defined(__AVR__) Debug.print(DBG_ERROR, F("Failed to configure Ethernet, check cable connection")); -#endif return NetworkConnectionState::CONNECTING; } } else { if (Ethernet.begin(nullptr, 15000, 4000) == 0) { -#if !defined(__AVR__) Debug.print(DBG_ERROR, F("Waiting Ethernet configuration from DHCP server, check cable connection")); -#endif return NetworkConnectionState::CONNECTING; } } + return NetworkConnectionState::CONNECTED; } NetworkConnectionState EthernetConnectionHandler::update_handleConnected() { if (Ethernet.linkStatus() == LinkOFF) { -#if !defined(__AVR__) Debug.print(DBG_ERROR, F("Ethernet link OFF, connection lost.")); -#endif if (_keep_alive) { -#if !defined(__AVR__) Debug.print(DBG_ERROR, F("Attempting reconnection")); -#endif } return NetworkConnectionState::DISCONNECTED; } From 11467efaa3075fb86734c98a11a34071cab295b6 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 13 Oct 2022 09:14:32 +0200 Subject: [PATCH 072/203] WiFi debug: Switch WiFi status ESP and WiFi Firmware debug prints from ERROR to INFO --- src/Arduino_WiFiConnectionHandler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 45a23b99..1f4ab885 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -67,7 +67,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() return NetworkConnectionState::ERROR; } #if !defined(__AVR__) - Debug.print(DBG_ERROR, F("Current WiFi Firmware: %s"), WiFi.firmwareVersion()); + Debug.print(DBG_INFO, F("Current WiFi Firmware: %s"), WiFi.firmwareVersion()); #endif #if defined(WIFI_FIRMWARE_VERSION_REQUIRED) @@ -82,7 +82,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() #endif #else - Debug.print(DBG_ERROR, F("WiFi status ESP: %d"), WiFi.status()); + Debug.print(DBG_INFO, F("WiFi status ESP: %d"), WiFi.status()); WiFi.disconnect(); delay(300); WiFi.begin(_ssid, _pass); From 5e2279b04d3ae7b1b8680be25afe4c86c0e33e22 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 13 Oct 2022 09:18:40 +0200 Subject: [PATCH 073/203] WiFi debug: Switch "Attempting reconnection" debug print from ERROR to INFO --- src/Arduino_WiFiConnectionHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 1f4ab885..f2ef7b11 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -132,7 +132,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnected() if (_keep_alive) { #if !defined(__AVR__) - Debug.print(DBG_ERROR, F("Attempting reconnection")); + Debug.print(DBG_INFO, F("Attempting reconnection")); #endif } From 68fd649f4b5966da19422828c49cad710ca1a687 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 Oct 2022 13:10:38 +0000 Subject: [PATCH 074/203] Bump geekyeggo/delete-artifact from 1 to 2 Bumps [geekyeggo/delete-artifact](https://github.com/geekyeggo/delete-artifact) from 1 to 2. - [Release notes](https://github.com/geekyeggo/delete-artifact/releases) - [Commits](https://github.com/geekyeggo/delete-artifact/compare/v1...v2) --- updated-dependencies: - dependency-name: geekyeggo/delete-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 986bda6f..10abaeac 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -114,7 +114,7 @@ jobs: path: ${{ env.CONFIGURATIONS_FOLDER }} - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v1 + uses: geekyeggo/delete-artifact@v2 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} From 1026b98034d2dc5b22ca317ab327a9483ae4babd Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 20 Oct 2022 13:33:26 +0200 Subject: [PATCH 075/203] Simplify ethernet support for portenta based boards --- src/Arduino_ConnectionHandler.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index f622834b..9a5d6961 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -46,21 +46,17 @@ #if defined(ARDUINO_PORTENTA_H7_M7) #include #include + #include + #include #define BOARD_HAS_WIFI + #define BOARD_HAS_ETHERNET #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD #define NETWORK_IDLE_STATUS WL_IDLE_STATUS #define NETWORK_CONNECTED WL_CONNECTED #endif -#if defined(BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET) - #include - #include - - #define BOARD_HAS_ETHERNET -#endif - #if defined(ARDUINO_NICLA_VISION) #include #include From 1f3b9a54d695960021a4b91528f0dd30a7868db5 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 20 Oct 2022 13:36:28 +0200 Subject: [PATCH 076/203] Rename parameter and internal variables from subnet to netmask --- src/Arduino_EthernetConnectionHandler.cpp | 8 ++++---- src/Arduino_EthernetConnectionHandler.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp index 8c129c7e..1e85894b 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -29,17 +29,17 @@ EthernetConnectionHandler::EthernetConnectionHandler(bool const keep_alive) ,_ip{INADDR_NONE} ,_dns{INADDR_NONE} ,_gateway{INADDR_NONE} -,_subnet{INADDR_NONE} +,_netmask{INADDR_NONE} { } -EthernetConnectionHandler::EthernetConnectionHandler(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, bool const keep_alive) +EthernetConnectionHandler::EthernetConnectionHandler(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress netmask, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} ,_ip{ip} ,_dns{dns} ,_gateway{gateway} -,_subnet{subnet} +,_netmask{netmask} { } @@ -60,7 +60,7 @@ NetworkConnectionState EthernetConnectionHandler::update_handleInit() NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() { if (_ip != INADDR_NONE) { - if (Ethernet.begin(nullptr, _ip, _dns, _gateway, _subnet, 15000, 4000) == 0) { + if (Ethernet.begin(nullptr, _ip, _dns, _gateway, _netmask, 15000, 4000) == 0) { Debug.print(DBG_ERROR, F("Failed to configure Ethernet, check cable connection")); return NetworkConnectionState::CONNECTING; } diff --git a/src/Arduino_EthernetConnectionHandler.h b/src/Arduino_EthernetConnectionHandler.h index f9074e74..ed4ab1dc 100644 --- a/src/Arduino_EthernetConnectionHandler.h +++ b/src/Arduino_EthernetConnectionHandler.h @@ -32,7 +32,7 @@ class EthernetConnectionHandler : public ConnectionHandler public: EthernetConnectionHandler(bool const keep_alive = true); - EthernetConnectionHandler(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet, bool const keep_alive = true); + EthernetConnectionHandler(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress netmask, bool const keep_alive = true); virtual unsigned long getTime() override { return 0; } @@ -53,7 +53,7 @@ class EthernetConnectionHandler : public ConnectionHandler IPAddress _ip; IPAddress _dns; IPAddress _gateway; - IPAddress _subnet; + IPAddress _netmask; EthernetUDP _eth_udp; EthernetClient _eth_client; From b53dd950dd92e1a8a176f473662d254cec62cf76 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 20 Oct 2022 13:40:07 +0200 Subject: [PATCH 077/203] Add constructor to handle string parameters --- src/Arduino_EthernetConnectionHandler.cpp | 21 +++++++++++++++++++++ src/Arduino_EthernetConnectionHandler.h | 1 + 2 files changed, 22 insertions(+) diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp index 1e85894b..cf0c6f6c 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -44,6 +44,27 @@ EthernetConnectionHandler::EthernetConnectionHandler(IPAddress ip, IPAddress dns } +EthernetConnectionHandler::EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, bool const keep_alive) +: ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} +,_ip{INADDR_NONE} +,_dns{INADDR_NONE} +,_gateway{INADDR_NONE} +,_netmask{INADDR_NONE} +{ + if(!_ip.fromString(ip)) { + _ip = INADDR_NONE; + } + if(!_dns.fromString(dns)) { + _dns = INADDR_NONE; + } + if(!_gateway.fromString(gateway)) { + _gateway = INADDR_NONE; + } + if(!_netmask.fromString(netmask)) { + _netmask = INADDR_NONE; + } +} + /****************************************************************************** PROTECTED MEMBER FUNCTIONS ******************************************************************************/ diff --git a/src/Arduino_EthernetConnectionHandler.h b/src/Arduino_EthernetConnectionHandler.h index ed4ab1dc..6110a3bf 100644 --- a/src/Arduino_EthernetConnectionHandler.h +++ b/src/Arduino_EthernetConnectionHandler.h @@ -33,6 +33,7 @@ class EthernetConnectionHandler : public ConnectionHandler EthernetConnectionHandler(bool const keep_alive = true); EthernetConnectionHandler(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress netmask, bool const keep_alive = true); + EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, bool const keep_alive = true); virtual unsigned long getTime() override { return 0; } From 2462ec0f8ea84058e9db9c1549ad8384670ca123 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 20 Oct 2022 13:43:17 +0200 Subject: [PATCH 078/203] Use const attribute for IPAddress parameters --- src/Arduino_EthernetConnectionHandler.cpp | 2 +- src/Arduino_EthernetConnectionHandler.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp index cf0c6f6c..0753eb23 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -34,7 +34,7 @@ EthernetConnectionHandler::EthernetConnectionHandler(bool const keep_alive) } -EthernetConnectionHandler::EthernetConnectionHandler(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress netmask, bool const keep_alive) +EthernetConnectionHandler::EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} ,_ip{ip} ,_dns{dns} diff --git a/src/Arduino_EthernetConnectionHandler.h b/src/Arduino_EthernetConnectionHandler.h index 6110a3bf..bac7bf45 100644 --- a/src/Arduino_EthernetConnectionHandler.h +++ b/src/Arduino_EthernetConnectionHandler.h @@ -32,7 +32,7 @@ class EthernetConnectionHandler : public ConnectionHandler public: EthernetConnectionHandler(bool const keep_alive = true); - EthernetConnectionHandler(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress netmask, bool const keep_alive = true); + EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, bool const keep_alive = true); EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, bool const keep_alive = true); From 0a772828c25916c2848fe20b68219cfa7b42c8e2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Oct 2022 13:11:39 +0000 Subject: [PATCH 079/203] Bump carlosperate/download-file-action from 1 to 2 Bumps [carlosperate/download-file-action](https://github.com/carlosperate/download-file-action) from 1 to 2. - [Release notes](https://github.com/carlosperate/download-file-action/releases) - [Commits](https://github.com/carlosperate/download-file-action/compare/v1...v2) --- updated-dependencies: - dependency-name: carlosperate/download-file-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 10abaeac..94938f35 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -31,7 +31,7 @@ jobs: - name: Download JSON schema for labels configuration file id: download-schema - uses: carlosperate/download-file-action@v1 + uses: carlosperate/download-file-action@v2 with: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json location: ${{ runner.temp }}/label-configuration-schema @@ -65,7 +65,7 @@ jobs: steps: - name: Download - uses: carlosperate/download-file-action@v1 + uses: carlosperate/download-file-action@v2 with: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} From 4e68980d80c5c17a0068c10fa62ac107de7a0dde Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 2 Nov 2022 15:43:33 +0100 Subject: [PATCH 080/203] Extend example adding ethernet connection handler --- .../ConnectionHandlerDemo.ino | 15 ++++++++++++++- examples/ConnectionHandlerDemo/arduino_secrets.h | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino index b106eed6..4c364a51 100644 --- a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino +++ b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino @@ -14,13 +14,26 @@ * If using a MKR NB1500 you'll need a NBConnectionHandler object as follows * * NBConnectionHandler conMan(SECRET_PIN); + * + * If using a Portenta + Ethernet shield you'll need a EthernetConnectionHandler object as follows: + * + * DHCP mode + * EthernetConnectionHandler conMan(); + * + * Manual configuration + * EthernetConnectionHandler conMan(SECRET_IP, SECRET_DNS, SECRET_GATEWAY, SECRET_NETMASK); + * + * Manual configuration will fallback on DHCP mode if SECRET_IP is invalid or equal to INADDR_NONE. + * */ #include "arduino_secrets.h" #include -#if defined(BOARD_HAS_WIFI) +#if defined(BOARD_HAS_ETHERNET) +EthernetConnectionHandler conMan(SECRET_IP, SECRET_DNS, SECRET_GATEWAY, SECRET_NETMASK); +#elif defined(BOARD_HAS_WIFI) WiFiConnectionHandler conMan(SECRET_SSID, SECRET_PASS); #elif defined(BOARD_HAS_GSM) GSMConnectionHandler conMan(SECRET_APN, SECRET_PIN, SECRET_GSM_USER, SECRET_GSM_PASS); diff --git a/examples/ConnectionHandlerDemo/arduino_secrets.h b/examples/ConnectionHandlerDemo/arduino_secrets.h index 0a2a2fe6..5836270e 100644 --- a/examples/ConnectionHandlerDemo/arduino_secrets.h +++ b/examples/ConnectionHandlerDemo/arduino_secrets.h @@ -8,3 +8,8 @@ const char SECRET_GSM_PASS[] = "GSM PASSWORD"; const char SECRET_APP_EUI[] = "APP_EUI"; const char SECRET_APP_KEY[] = "APP_KEY"; + +const char SECRET_IP[] = "IP ADDRESS"; +const char SECRET_DNS[] = "DNS ADDRESS"; +const char SECRET_GATEWAY[] = "GATEWAY ADDRESS"; +const char SECRET_NETMASK[] = "NETWORK MASK"; From f7cc6b62e369376c7d9be08f5dfd99bf36bf9463 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 3 Nov 2022 10:48:42 +0100 Subject: [PATCH 081/203] Fix typo in example sketch comments --- examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino index 4c364a51..ad250971 100644 --- a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino +++ b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino @@ -18,7 +18,7 @@ * If using a Portenta + Ethernet shield you'll need a EthernetConnectionHandler object as follows: * * DHCP mode - * EthernetConnectionHandler conMan(); + * EthernetConnectionHandler conMan; * * Manual configuration * EthernetConnectionHandler conMan(SECRET_IP, SECRET_DNS, SECRET_GATEWAY, SECRET_NETMASK); From 615bab50827a1e4d82e8709894d6620cd5abc76d Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 3 Nov 2022 11:01:34 +0100 Subject: [PATCH 082/203] Add Ethernet boards --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 17eef2e6..141175c1 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Library for handling and managing network connections by providing keep-alive fu * **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415) * **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413) * **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) +* **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Breakout`](https://store.arduino.cc/products/arduino-portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/products/arduino-portenta-machine-control) ### How-to-use From 1617b677beedb47af3c9571772bcb5874ead87d7 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 3 Nov 2022 11:02:46 +0100 Subject: [PATCH 083/203] Add EthernetConnectionHandler inside How-to-use section --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 141175c1..5600a1bf 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ Library for handling and managing network connections by providing keep-alive fu ```C++ #include /* ... */ -#if defined(BOARD_HAS_WIFI) +#if defined(BOARD_HAS_ETHERNET) +EthernetConnectionHandler conMan; +#elif defined(BOARD_HAS_WIFI) WiFiConnectionHandler conMan("SECRET_SSID", "SECRET_PASS"); #elif defined(BOARD_HAS_GSM) GSMConnectionHandler conMan("SECRET_PIN", "SECRET_APN", "SECRET_GSM_LOGIN", "SECRET_GSM_PASS"); From d39737e1fbd4247fa6e2030ee211282ef5b46064 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 3 Nov 2022 11:10:09 +0100 Subject: [PATCH 084/203] Add ESP32 boards with link to the core --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5600a1bf..cb46303b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Arduino Library for network connections management [![Spell Check status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml) Library for handling and managing network connections by providing keep-alive functionality and automatic reconnection in case of connection-loss. It supports the following boards: -* **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/products/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), `ESP8266` +* **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/products/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32) * **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415) * **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413) * **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) From ffdb90ae5e5ac76df12e15cb27557bf81b2ce007 Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Thu, 3 Nov 2022 12:23:10 +0100 Subject: [PATCH 085/203] Release v0.7.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 12eb186f..cdd24804 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.6.6 +version=0.7.0 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 40e7e8cf86682a736bc00b261a8fe50aa0bfa154 Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 4 Nov 2022 13:08:18 +0100 Subject: [PATCH 086/203] Only force WIFI_STA mode during init --- src/Arduino_WiFiConnectionHandler.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index cc6727cf..582de02e 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -80,13 +80,8 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() delay(5000); } #endif - #else - Debug.print(DBG_INFO, F("WiFi status ESP: %d"), WiFi.status()); - WiFi.disconnect(); - delay(300); - WiFi.begin(_ssid, _pass); - delay(1000); + WiFi.mode(WIFI_STA); #endif /* #if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) */ return NetworkConnectionState::CONNECTING; From 7d541f92ee1ffcd69a3dff8900f2b0ce21dbf5aa Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 4 Nov 2022 13:09:38 +0100 Subject: [PATCH 087/203] Print same WiFi status string for all boards --- src/Arduino_WiFiConnectionHandler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 582de02e..40612b86 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -54,10 +54,11 @@ unsigned long WiFiConnectionHandler::getTime() NetworkConnectionState WiFiConnectionHandler::update_handleInit() { -#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) #if !defined(__AVR__) Debug.print(DBG_INFO, F("WiFi.status(): %d"), WiFi.status()); #endif + +#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) if (WiFi.status() == NETWORK_HARDWARE_ERROR) { #if !defined(__AVR__) From 99dd1a4712102852679c726b8bca36f1b9fbebfd Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 4 Nov 2022 13:10:47 +0100 Subject: [PATCH 088/203] Call waitForConnectResult after WiFi.begin() - On ESP32 the call will block execution up to 1s - On ESP8266 the call will block execution up to 30s --- src/Arduino_WiFiConnectionHandler.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 40612b86..255eabc8 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -90,12 +90,16 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() { -#if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) if (WiFi.status() != WL_CONNECTED) { WiFi.begin(_ssid, _pass); +#if defined(ARDUINO_ARCH_ESP8266) + WiFi.waitForConnectResult(); +#endif +#if defined(ARDUINO_ARCH_ESP32) + WiFi.waitForConnectResult(1000); +#endif } -#endif /* #if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) */ if (WiFi.status() != NETWORK_CONNECTED) { From 0cac574e8dd5ff5f99280951527bfea6ea73e76f Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 4 Nov 2022 13:19:28 +0100 Subject: [PATCH 089/203] Increase connecting interval for ESP32 to allow reconnection --- src/Arduino_ConnectionHandler.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 9a5d6961..87f5cc77 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -155,7 +155,11 @@ typedef void (*OnNetworkEventCallback)(); static unsigned int const CHECK_INTERVAL_TABLE[] = { /* INIT */ 100, +#if defined(ARDUINO_ARCH_ESP32) + /* CONNECTING */ 2000, +#else /* CONNECTING */ 500, +#endif /* CONNECTED */ 10000, /* DISCONNECTING */ 100, /* DISCONNECTED */ 1000, From 208ae9bb721729fd3eb685ccffcf1b4c75f20b5c Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 4 Nov 2022 15:24:44 +0100 Subject: [PATCH 090/203] Wait for connection. Implement timeout for ESP8266 - On ESP8266 the call will block execution up to 3s --- src/Arduino_WiFiConnectionHandler.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 255eabc8..cf20e343 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -23,6 +23,15 @@ #ifdef BOARD_HAS_WIFI /* Only compile if the board has WiFi */ +/****************************************************************************** + CONSTANTS + ******************************************************************************/ +#if defined(ARDUINO_ARCH_ESP8266) +static int const ESP_WIFI_CONNECTION_TIMEOUT = 3000; +#elif defined(ARDUINO_ARCH_ESP32) +static int const ESP_WIFI_CONNECTION_TIMEOUT = 1000; +#endif + /****************************************************************************** CTOR/DTOR ******************************************************************************/ @@ -93,12 +102,14 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() if (WiFi.status() != WL_CONNECTED) { WiFi.begin(_ssid, _pass); -#if defined(ARDUINO_ARCH_ESP8266) - WiFi.waitForConnectResult(); -#endif -#if defined(ARDUINO_ARCH_ESP32) - WiFi.waitForConnectResult(1000); +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) + /* Wait connection otherwise board won't connect */ + unsigned long start = millis(); + while((WiFi.status() != WL_CONNECTED) && (millis() - start) < ESP_WIFI_CONNECTION_TIMEOUT) { + delay(100); + } #endif + } if (WiFi.status() != NETWORK_CONNECTED) From 016b3b83e6b3f5ee7e7a692928d4d457c28b592f Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 4 Nov 2022 15:26:09 +0100 Subject: [PATCH 091/203] Use same check interval for ESP32 and ESP8266 --- src/Arduino_ConnectionHandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 87f5cc77..79758066 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -155,7 +155,7 @@ typedef void (*OnNetworkEventCallback)(); static unsigned int const CHECK_INTERVAL_TABLE[] = { /* INIT */ 100, -#if defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) /* CONNECTING */ 2000, #else /* CONNECTING */ 500, From 91f734574689818ad7653bcbcd26c4dfaae8509e Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 4 Nov 2022 18:01:23 +0100 Subject: [PATCH 092/203] Wait connection only if ESP8266 board --- src/Arduino_WiFiConnectionHandler.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index cf20e343..3eadcca2 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -28,8 +28,6 @@ ******************************************************************************/ #if defined(ARDUINO_ARCH_ESP8266) static int const ESP_WIFI_CONNECTION_TIMEOUT = 3000; -#elif defined(ARDUINO_ARCH_ESP32) -static int const ESP_WIFI_CONNECTION_TIMEOUT = 1000; #endif /****************************************************************************** @@ -93,7 +91,6 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() #else WiFi.mode(WIFI_STA); #endif /* #if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) */ - return NetworkConnectionState::CONNECTING; } @@ -102,7 +99,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() if (WiFi.status() != WL_CONNECTED) { WiFi.begin(_ssid, _pass); -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP8266) /* Wait connection otherwise board won't connect */ unsigned long start = millis(); while((WiFi.status() != WL_CONNECTED) && (millis() - start) < ESP_WIFI_CONNECTION_TIMEOUT) { From f56b1b9b19c73a91f4fe6e595b02255c8a4126e9 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 14 Nov 2022 16:26:50 +0100 Subject: [PATCH 093/203] Fix required firmware version check --- src/Arduino_WiFiConnectionHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index cc6727cf..9bd5818a 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -71,7 +71,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() #endif #if defined(WIFI_FIRMWARE_VERSION_REQUIRED) - if (WiFi.firmwareVersion() < WIFI_FIRMWARE_VERSION_REQUIRED) + if (String(WiFi.firmwareVersion()) < String(WIFI_FIRMWARE_VERSION_REQUIRED)) { #if !defined(__AVR__) Debug.print(DBG_ERROR, F("Latest WiFi Firmware: %s"), WIFI_FIRMWARE_VERSION_REQUIRED); From a2746dc27745d005a07d2b2b4e91f0563475884e Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 22 Nov 2022 12:53:00 +0100 Subject: [PATCH 094/203] LoRa: joinOTAA(...) or die trying --- src/Arduino_LoRaConnectionHandler.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Arduino_LoRaConnectionHandler.cpp b/src/Arduino_LoRaConnectionHandler.cpp index 886c7e3f..fa06e595 100644 --- a/src/Arduino_LoRaConnectionHandler.cpp +++ b/src/Arduino_LoRaConnectionHandler.cpp @@ -124,8 +124,9 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnecting() bool const network_status = _modem.joinOTAA(_appeui, _appkey); if (network_status != true) { - Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry.")); - return NetworkConnectionState::ERROR; + Debug.print(DBG_ERROR, F("Connection to the network failed")); + Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); + return NetworkConnectionState::INIT; } else { From 8afb854354442607d67d622d3595e8cd05fc945a Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Tue, 13 Dec 2022 09:26:49 +0100 Subject: [PATCH 095/203] Release v0.7.1 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index cdd24804..5e940190 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.7.0 +version=0.7.1 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From f56bab72b5a9ca389b8650754627204f1ac67d4f Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 2 Aug 2022 09:36:15 +0200 Subject: [PATCH 096/203] Add support for opta board --- library.properties | 2 +- src/Arduino_ConnectionHandler.h | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 5e940190..3a69f452 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethe 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 +architectures=samd,esp32,esp8266,mbed,megaavr,mbed_nano,mbed_portenta,mbed_nicla,mbed_opta depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 79758066..225f58ce 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -67,6 +67,19 @@ #define NETWORK_CONNECTED WL_CONNECTED #endif +#if defined(ARDUINO_OPTA) + #include + #include + #include + #include + + #define BOARD_HAS_WIFI + #define BOARD_HAS_ETHERNET + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + #ifdef ARDUINO_SAMD_MKRGSM1400 #include #define BOARD_HAS_GSM From 3c2c4610cd32558062e0f89da55090e615a8234a Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 19 Dec 2022 11:23:57 +0100 Subject: [PATCH 097/203] Add opta compile example workflow --- .github/workflows/compile-examples.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 25aaafbe..d3d07ac5 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -64,6 +64,8 @@ jobs: platform-name: arduino:mbed_nano - fqbn: arduino:mbed_nicla:nicla_vision platform-name: arduino:mbed_nicla + - fqbn: arduino:mbed_opta:opta + platform-name: arduino:mbed_opta # Make board type-specific customizations to the matrix jobs include: From 1be796763f78434081f086b9c4ea80e9e5c1ba2a Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 20 Dec 2022 16:10:55 +0100 Subject: [PATCH 098/203] ESP: Increase connecting interval --- src/Arduino_ConnectionHandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 79758066..85b39d37 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -156,7 +156,7 @@ static unsigned int const CHECK_INTERVAL_TABLE[] = { /* INIT */ 100, #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - /* CONNECTING */ 2000, + /* CONNECTING */ 4000, #else /* CONNECTING */ 500, #endif From 980f09601f5f9da35f0bb69b70f3e8dce2601483 Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Wed, 21 Dec 2022 11:55:34 +0100 Subject: [PATCH 099/203] Release v0.7.2 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 5e940190..08db85a8 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.7.1 +version=0.7.2 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 0140c5fa09aa2813cc4733bb0b0fcc7d07e90e1f Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Mon, 9 Jan 2023 11:18:18 +0100 Subject: [PATCH 100/203] Release v0.7.3 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index b393dee8..b526da69 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.7.2 +version=0.7.3 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 665e9055fe81c8e9f59ea3a1272ec0a2e09bb9e5 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 8 Sep 2022 11:46:10 +0200 Subject: [PATCH 101/203] Add support for giga board --- library.properties | 2 +- src/Arduino_ConnectionHandler.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/library.properties b/library.properties index b526da69..0febe105 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethe 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 +architectures=samd,esp32,esp8266,mbed,megaavr,mbed_nano,mbed_portenta,mbed_nicla,mbed_opta,mbed_giga depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 126eaa59..2c2567e1 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -80,6 +80,16 @@ #define NETWORK_CONNECTED WL_CONNECTED #endif +#if defined(ARDUINO_GIGA) + #include + #include + + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + #ifdef ARDUINO_SAMD_MKRGSM1400 #include #define BOARD_HAS_GSM From 51a8c8c5cf8206687df09ba9a5b06be23a5ca06d Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 2 Mar 2023 13:43:06 +0100 Subject: [PATCH 102/203] Enable CI for GIGA --- .github/workflows/compile-examples.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index d3d07ac5..9e11ff63 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -66,6 +66,8 @@ jobs: platform-name: arduino:mbed_nicla - fqbn: arduino:mbed_opta:opta platform-name: arduino:mbed_opta + - fqbn: arduino:mbed_giga:giga + platform-name: arduino:mbed_giga # Make board type-specific customizations to the matrix jobs include: From f9e2e9280d1365c116ce4753c551105e03b1adce Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Thu, 2 Mar 2023 15:40:01 +0100 Subject: [PATCH 103/203] Release v0.7.4 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 0febe105..bd690c2f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.7.3 +version=0.7.4 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 07469d6cc68993e6548c47c2505290fa8b2bf185 Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Fri, 3 Mar 2023 10:16:30 +0100 Subject: [PATCH 104/203] README: boards update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cb46303b..3ef7250a 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ Arduino Library for network connections management [![Spell Check status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml) Library for handling and managing network connections by providing keep-alive functionality and automatic reconnection in case of connection-loss. It supports the following boards: -* **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/products/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32) +* **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/products/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`OPTA`](https://store.arduino.cc/products/opta-wifi), [`GIGA R1 WiFi`](https://store.arduino.cc/products/giga-r1-wifi), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32) * **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415) * **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413) * **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) -* **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Breakout`](https://store.arduino.cc/products/arduino-portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/products/arduino-portenta-machine-control) +* **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Breakout`](https://store.arduino.cc/products/arduino-portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/products/arduino-portenta-machine-control), [`OPTA`](https://store.arduino.cc/products/opta-lite) ### How-to-use From 0d60de98758792fb2e65387192a48c907467bf3b Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Fri, 3 Mar 2023 11:34:50 +0100 Subject: [PATCH 105/203] README: Use full product name Co-authored-by: Alexander Entinger --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3ef7250a..a3b2d016 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ Arduino Library for network connections management [![Spell Check status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml) Library for handling and managing network connections by providing keep-alive functionality and automatic reconnection in case of connection-loss. It supports the following boards: -* **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/products/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`OPTA`](https://store.arduino.cc/products/opta-wifi), [`GIGA R1 WiFi`](https://store.arduino.cc/products/giga-r1-wifi), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32) +* **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/products/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`GIGA R1 WiFi`](https://store.arduino.cc/products/giga-r1-wifi), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32) * **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415) * **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413) * **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) -* **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Breakout`](https://store.arduino.cc/products/arduino-portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/products/arduino-portenta-machine-control), [`OPTA`](https://store.arduino.cc/products/opta-lite) +* **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Breakout`](https://store.arduino.cc/products/arduino-portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/products/arduino-portenta-machine-control), [`OPTA Lite`](https://store.arduino.cc/products/opta-lite) ### How-to-use From cdb97a2db0162ae6e454c35ced9093dcdaedbcf9 Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 3 Mar 2023 11:38:37 +0100 Subject: [PATCH 106/203] README: List all Opta models supporting ethernet --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a3b2d016..a4cda748 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Library for handling and managing network connections by providing keep-alive fu * **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415) * **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413) * **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) -* **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Breakout`](https://store.arduino.cc/products/arduino-portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/products/arduino-portenta-machine-control), [`OPTA Lite`](https://store.arduino.cc/products/opta-lite) +* **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Breakout`](https://store.arduino.cc/products/arduino-portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/products/arduino-portenta-machine-control), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`OPTA RS485`](https://store.arduino.cc/products/opta-rs485), [`OPTA Lite`](https://store.arduino.cc/products/opta-lite) ### How-to-use From a26758897eab59a1524595be095b363c9cbe84a3 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 2 May 2023 17:24:20 +0200 Subject: [PATCH 107/203] Add support for PORTENTA C33 --- library.properties | 2 +- src/Arduino_ConnectionHandler.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/library.properties b/library.properties index bd690c2f..9baaf522 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethe 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 +architectures=samd,esp32,esp8266,mbed,megaavr,mbed_nano,mbed_portenta,mbed_nicla,mbed_opta,mbed_giga,renesas depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 2c2567e1..e0dced4c 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -57,6 +57,20 @@ #define NETWORK_CONNECTED WL_CONNECTED #endif +#if defined(ARDUINO_PORTENTA_C33) + #include + #include + #include + #include + + #define BOARD_HAS_WIFI + #define BOARD_HAS_ETHERNET + #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + #if defined(ARDUINO_NICLA_VISION) #include #include From 8bff077b290b463ec138f57a00371e79b1536d8d Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 22 Jun 2023 15:22:48 +0200 Subject: [PATCH 108/203] Update library.properties --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 9baaf522..132cd600 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethe 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 +architectures=samd,esp32,esp8266,mbed,megaavr,mbed_nano,mbed_portenta,mbed_nicla,mbed_opta,mbed_giga,renesas_portenta depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN From 865637fe3005c2219d8551f052722e674333918d Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 22 Jun 2023 15:23:30 +0200 Subject: [PATCH 109/203] Release 0.7.5 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 132cd600..721f98ca 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.7.4 +version=0.7.5 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From a172ee432971002a812df46b760d081f6dc00852 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 26 Jun 2023 13:32:03 +0200 Subject: [PATCH 110/203] CI: add Portenta C33 to compile examples workflow --- .github/workflows/compile-examples.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 9e11ff63..afe8a367 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -68,6 +68,8 @@ jobs: platform-name: arduino:mbed_opta - fqbn: arduino:mbed_giga:giga platform-name: arduino:mbed_giga + - fqbn: arduino:renesas_portenta:portenta_c33 + platform-name: arduino:renesas_portenta # Make board type-specific customizations to the matrix jobs include: @@ -84,6 +86,11 @@ jobs: # Overwrite the Arduino mbed-Enabled Boards release version with version from the tip of the default branch (located in local path because of the need to first install ArduinoCore-API) - source-path: extras/ArduinoCore-mbed name: arduino:mbed + - board: + platform-name: arduino:renesas_portenta + platforms: | + # Install Arduino Renesas portenta Boards via Boards Manager + - name: arduino:renesas_portenta - board: platform-name: esp8266:esp8266 platforms: | From 0e2db05d4756609da9db07a0e038cce3fd06c426 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 27 Jun 2023 10:06:26 +0200 Subject: [PATCH 111/203] Add UNO R4 WiFi support --- src/Arduino_ConnectionHandler.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index e0dced4c..107c8ddd 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -147,6 +147,16 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED #endif +#if defined(ARDUINO_UNOR4_WIFI) + #include + + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED + #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION +#endif + /****************************************************************************** INCLUDES ******************************************************************************/ From bfca781b5a5c0f0f1ad0ea7feb2475873936976c Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 27 Jun 2023 10:06:43 +0200 Subject: [PATCH 112/203] Add renesas_uno architecture --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 721f98ca..ad9e824f 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethe 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 +architectures=samd,esp32,esp8266,mbed,megaavr,mbed_nano,mbed_portenta,mbed_nicla,mbed_opta,mbed_giga,renesas_portenta,renesas_uno depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN From ec456d068d83ebe254253b0728edf64241336dcf Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 27 Jun 2023 10:07:14 +0200 Subject: [PATCH 113/203] Enable compile example workflow for UNO R4 WiFi --- .github/workflows/compile-examples.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index afe8a367..e6d883db 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -70,6 +70,8 @@ jobs: platform-name: arduino:mbed_giga - fqbn: arduino:renesas_portenta:portenta_c33 platform-name: arduino:renesas_portenta + - fqbn: arduino:renesas_uno:unor4wifi + platform-name: arduino:renesas_uno # Make board type-specific customizations to the matrix jobs include: @@ -91,6 +93,11 @@ jobs: platforms: | # Install Arduino Renesas portenta Boards via Boards Manager - name: arduino:renesas_portenta + - board: + platform-name: arduino:renesas_uno + platforms: | + # Install Arduino Renesas uno Boards via Boards Manager + - name: arduino:renesas_uno - board: platform-name: esp8266:esp8266 platforms: | From 27a65e8ee466e977e1ddedec597c1fa47b7dff8e Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Wed, 28 Jun 2023 09:49:56 +0200 Subject: [PATCH 114/203] Release 0.7.6 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index ad9e824f..2835b768 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.7.5 +version=0.7.6 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From a66474539dbadd133bc40262a52e509862e3d147 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 25 Jul 2023 10:07:57 +0200 Subject: [PATCH 115/203] Add Compile examples workflow for Arduino NANO ESP23 --- .github/workflows/compile-examples.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index e6d883db..d719bd3b 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -72,6 +72,8 @@ jobs: platform-name: arduino:renesas_portenta - fqbn: arduino:renesas_uno:unor4wifi platform-name: arduino:renesas_uno + - fqbn: arduino:esp32:nano_nora + platform-name: arduino:esp32 # Make board type-specific customizations to the matrix jobs include: @@ -98,6 +100,11 @@ jobs: platforms: | # Install Arduino Renesas uno Boards via Boards Manager - name: arduino:renesas_uno + - board: + platform-name: arduino:esp32 + platforms: | + # Install Arduino ESP32 Boards via Boards Manager + - name: arduino:esp32 - board: platform-name: esp8266:esp8266 platforms: | From 5553f6bf9bd9536e78d3d53523e683477e6e781e Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 25 Jul 2023 10:18:58 +0200 Subject: [PATCH 116/203] README: Add links to new boards --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a4cda748..c2759ac3 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ Arduino Library for network connections management [![Spell Check status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml) Library for handling and managing network connections by providing keep-alive functionality and automatic reconnection in case of connection-loss. It supports the following boards: -* **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/products/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`GIGA R1 WiFi`](https://store.arduino.cc/products/giga-r1-wifi), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32) +* **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/products/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`GIGA R1 WiFi`](https://store.arduino.cc/products/giga-r1-wifi), [`Portenta C33`](https://store.arduino.cc/products/portenta-c33), [`UNO R4 WiFi`](https://store.arduino.cc/products/uno-r4-wifi), [`Nano ESP32`](https://store.arduino.cc/products/nano-esp32), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32) * **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415) * **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413) * **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) -* **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Breakout`](https://store.arduino.cc/products/arduino-portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/products/arduino-portenta-machine-control), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`OPTA RS485`](https://store.arduino.cc/products/opta-rs485), [`OPTA Lite`](https://store.arduino.cc/products/opta-lite) +* **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Breakout`](https://store.arduino.cc/products/arduino-portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/products/arduino-portenta-machine-control), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`OPTA RS485`](https://store.arduino.cc/products/opta-rs485), [`OPTA Lite`](https://store.arduino.cc/products/opta-lite), [`Portenta C33`](https://store.arduino.cc/products/portenta-c33) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet) ### How-to-use From 34066fd57e207998b84982bde228037badc837f9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 13:28:50 +0000 Subject: [PATCH 117/203] Bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/check-arduino.yml | 2 +- .github/workflows/compile-examples.yml | 6 +++--- .github/workflows/spell-check.yml | 2 +- .github/workflows/sync-labels.yml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index 3e0d26c9..adb330f8 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Arduino Lint uses: arduino/arduino-lint-action@v1 diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index e6d883db..585b0ba0 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -113,13 +113,13 @@ jobs: source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # It's necessary to checkout the platform before installing it so that the ArduinoCore-API dependency can be added - name: Checkout ArduinoCore-mbed # this step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used if: matrix.board.platform-name == 'arduino:mbed' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: arduino/ArduinoCore-mbed # The arduino/actions/libraries/compile-examples action will install the platform from this path @@ -128,7 +128,7 @@ jobs: - name: Checkout ArduinoCore-API # This step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used if: matrix.board.platform-name == 'arduino:mbed' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: arduino/ArduinoCore-API path: ${{ env.ARDUINOCORE_API_STAGING_PATH }} diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 3f6b03fb..ef7d8941 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Spell check uses: codespell-project/actions-codespell@master diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 94938f35..9cde1acc 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download JSON schema for labels configuration file id: download-schema @@ -105,7 +105,7 @@ jobs: echo "::set-output name=flag::--dry-run" - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download configuration files artifact uses: actions/download-artifact@v3 From 8d245fee2b4e60c73a4b71f57136103c122e5191 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 23 Oct 2023 16:04:25 +0200 Subject: [PATCH 118/203] Fix build NB_NetworkStatus_t::ERROR has been renamed to NB_NetworkStatus_t::NB_ERROR in MKRNB library release 1.6.0 --- src/Arduino_NBConnectionHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_NBConnectionHandler.cpp b/src/Arduino_NBConnectionHandler.cpp index ae74a238..344e104f 100644 --- a/src/Arduino_NBConnectionHandler.cpp +++ b/src/Arduino_NBConnectionHandler.cpp @@ -100,7 +100,7 @@ NetworkConnectionState NBConnectionHandler::update_handleConnecting() { NB_NetworkStatus_t const network_status = _nb_gprs.attachGPRS(true); Debug.print(DBG_DEBUG, F("GPRS.attachGPRS(): %d"), network_status); - if (network_status == NB_NetworkStatus_t::ERROR) + if (network_status == NB_NetworkStatus_t::NB_ERROR) { Debug.print(DBG_ERROR, F("GPRS.attachGPRS() failed")); return NetworkConnectionState::ERROR; From bda78b781fbedc2aab4af663f4b3266be9f3f4d6 Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Mon, 23 Oct 2023 16:27:08 +0200 Subject: [PATCH 119/203] Release 0.7.7 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 2835b768..fdf2b9b4 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.7.6 +version=0.7.7 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 90b1aca9624925cc9b45b2cea7db9cb14f8b4467 Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 11 Oct 2023 16:03:30 +0200 Subject: [PATCH 120/203] Add CatM1 ConnectionHandler to support Portenta CAT.M1/NB IoT GNSS Shield --- keywords.txt | 1 + src/Arduino_CatM1ConnectionHandler.cpp | 99 ++++++++++++++++++++++++++ src/Arduino_CatM1ConnectionHandler.h | 71 ++++++++++++++++++ src/Arduino_ConnectionHandler.h | 12 +++- 4 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 src/Arduino_CatM1ConnectionHandler.cpp create mode 100644 src/Arduino_CatM1ConnectionHandler.h diff --git a/keywords.txt b/keywords.txt index 4ac67251..ef5227f0 100644 --- a/keywords.txt +++ b/keywords.txt @@ -11,6 +11,7 @@ GSMConnectionHandler KEYWORD1 NBConnectionHandler KEYWORD1 LoRaConnectionHandler KEYWORD1 EthernetConnectionHandler KEYWORD1 +CatM1ConnectionHandler KEYWORD1 #################################################### # Methods and Functions (KEYWORD2) diff --git a/src/Arduino_CatM1ConnectionHandler.cpp b/src/Arduino_CatM1ConnectionHandler.cpp new file mode 100644 index 00000000..59d47fe9 --- /dev/null +++ b/src/Arduino_CatM1ConnectionHandler.cpp @@ -0,0 +1,99 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +/****************************************************************************** + INCLUDE + ******************************************************************************/ + +#include "Arduino_CatM1ConnectionHandler.h" + +#ifdef BOARD_HAS_CATM1_NBIOT /* Only compile if the board has CatM1 BN-IoT */ + +/****************************************************************************** + CTOR/DTOR + ******************************************************************************/ + +CatM1ConnectionHandler::CatM1ConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, RadioAccessTechnologyType rat, uint32_t band, bool const keep_alive) +: ConnectionHandler{keep_alive, NetworkAdapter::GSM} +, _pin(pin) +, _apn(apn) +, _login(login) +, _pass(pass) +, _rat(rat) +, _band(band) +{ + +} + +/****************************************************************************** + PUBLIC MEMBER FUNCTIONS + ******************************************************************************/ + +unsigned long CatM1ConnectionHandler::getTime() +{ + return GSM.getTime(); +} + +/****************************************************************************** + PROTECTED MEMBER FUNCTIONS + ******************************************************************************/ + +NetworkConnectionState CatM1ConnectionHandler::update_handleInit() +{ + return NetworkConnectionState::CONNECTING; +} + +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; + } + Debug.print(DBG_INFO, F("Connected to Network")); + return NetworkConnectionState::CONNECTED; +} + +NetworkConnectionState CatM1ConnectionHandler::update_handleConnected() +{ + int const is_gsm_access_alive = GSM.isConnected(); + if (is_gsm_access_alive != 1) + { + return NetworkConnectionState::DISCONNECTED; + } + return NetworkConnectionState::CONNECTED; +} + +NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnecting() +{ + GSM.disconnect(); + return NetworkConnectionState::DISCONNECTED; +} + +NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnected() +{ + if (_keep_alive) + { + return NetworkConnectionState::INIT; + } + else + { + return NetworkConnectionState::CLOSED; + } +} + +#endif /* #ifdef BOARD_HAS_CATM1_NBIOT */ diff --git a/src/Arduino_CatM1ConnectionHandler.h b/src/Arduino_CatM1ConnectionHandler.h new file mode 100644 index 00000000..de5fd01f --- /dev/null +++ b/src/Arduino_CatM1ConnectionHandler.h @@ -0,0 +1,71 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#ifndef ARDUINO_CATM1_CONNECTION_HANDLER_H_ +#define ARDUINO_CATM1_CONNECTION_HANDLER_H_ + +/****************************************************************************** + INCLUDE + ******************************************************************************/ + +#include "Arduino_ConnectionHandler.h" + + +#ifdef BOARD_HAS_CATM1_NBIOT /* Only compile if the board has CatM1 BN-IoT */ + +/****************************************************************************** + CLASS DECLARATION + ******************************************************************************/ + +class CatM1ConnectionHandler : public ConnectionHandler +{ + public: + + CatM1ConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, RadioAccessTechnologyType rat = CATM1, uint32_t band = BAND_3 | BAND_20 | BAND_19, bool const keep_alive = true); + + + virtual unsigned long getTime() override; + virtual Client & getClient() override { return _gsm_client; }; + virtual UDP & getUDP() override { return _gsm_udp; }; + + + protected: + + virtual NetworkConnectionState update_handleInit () override; + virtual NetworkConnectionState update_handleConnecting () override; + virtual NetworkConnectionState update_handleConnected () override; + virtual NetworkConnectionState update_handleDisconnecting() override; + virtual NetworkConnectionState update_handleDisconnected () override; + + + private: + + const char * _pin; + const char * _apn; + const char * _login; + const char * _pass; + + RadioAccessTechnologyType _rat; + uint32_t _band; + + GSMUDP _gsm_udp; + GSMClient _gsm_client; +}; + +#endif /* #ifdef BOARD_HAS_CATM1_NBIOT */ + +#endif /* #ifndef ARDUINO_CATM1_CONNECTION_HANDLER_H_ */ diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 107c8ddd..96d7be73 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -48,9 +48,12 @@ #include #include #include + #include #define BOARD_HAS_WIFI #define BOARD_HAS_ETHERNET + #define BOARD_HAS_CATM1_NBIOT + #define BOARD_HAS_PORTENTA_CATM1_NBIOT_SHIELD #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD #define NETWORK_IDLE_STATUS WL_IDLE_STATUS @@ -190,7 +193,8 @@ enum class NetworkAdapter { ETHERNET, NB, GSM, - LORA + LORA, + CATM1 }; typedef void (*OnNetworkEventCallback)(); @@ -226,7 +230,7 @@ class ConnectionHandler { NetworkConnectionState check(); - #if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) + #if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT) virtual unsigned long getTime() = 0; virtual Client &getClient() = 0; virtual UDP &getUDP() = 0; @@ -289,4 +293,8 @@ class ConnectionHandler { #include "Arduino_EthernetConnectionHandler.h" #endif +#if defined(BOARD_HAS_CATM1_NBIOT) + #include "Arduino_CatM1ConnectionHandler.h" +#endif + #endif /* CONNECTION_HANDLER_H_ */ From d7f1222da6fec39736c9166fe1eb2087d265c324 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 21 Nov 2023 13:04:16 +0100 Subject: [PATCH 121/203] Update ConnectionHandlerDemo example adding CatM1 handler --- examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino index ad250971..a5be6a7e 100644 --- a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino +++ b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino @@ -41,6 +41,8 @@ GSMConnectionHandler conMan(SECRET_APN, SECRET_PIN, SECRET_GSM_USER, SECRET_GSM_ NBConnectionHandler conMan(SECRET_PIN); #elif defined(BOARD_HAS_LORA) LoRaConnectionHandler conMan(SECRET_APP_EUI, SECRET_APP_KEY); +#elif defined(BOARD_HAS_CATM1_NBIOT) +CatM1ConnectionHandler conMan(SECRET_APN, SECRET_PIN, SECRET_GSM_USER, SECRET_GSM_PASS); #endif void setup() { From 1d6fcb95b8409947bd62f9881b13483f2f7dd661 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 23 Nov 2023 13:52:00 +0100 Subject: [PATCH 122/203] Move Arduino_DebugUtils include on top of file * This is a temporary workaround to avoid a library discovery issue caused by __has_include() preprocessor macro in mbed GSM library. Without this change Arduino_DebugUtils is not included in the build. --- src/Arduino_ConnectionHandler.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 96d7be73..dc97ca77 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -18,6 +18,14 @@ #ifndef ARDUINO_CONNECTION_HANDLER_H_ #define ARDUINO_CONNECTION_HANDLER_H_ +/****************************************************************************** + INCLUDES + ******************************************************************************/ + +#if !defined(__AVR__) +# include +#endif + #include #ifdef ARDUINO_SAMD_MKR1000 @@ -160,14 +168,6 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION #endif -/****************************************************************************** - INCLUDES - ******************************************************************************/ - -#if !defined(__AVR__) -# include -#endif - /****************************************************************************** TYPEDEFS ******************************************************************************/ From f6c1b06718d701614ff8e265331dedc92b0c11f5 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 23 Nov 2023 15:56:59 +0100 Subject: [PATCH 123/203] CI: add compile example check using latest released portenta core --- .github/workflows/compile-examples.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index b100eafb..835966f8 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -56,6 +56,8 @@ jobs: platform-name: arduino:samd - fqbn: "arduino:mbed:envie_m7" platform-name: arduino:mbed + - fqbn: "arduino:mbed_portenta:envie_m7" + platform-name: arduino:mbed_portenta - fqbn: "esp8266:esp8266:huzzah" platform-name: esp8266:esp8266 - fqbn: "esp32:esp32:esp32" From e88417e61b2c8b2bfa8be31336b593e2642cc499 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 13 Nov 2023 10:35:16 +0100 Subject: [PATCH 124/203] Edge Control: add support for CatM1 Connection Handler --- src/Arduino_ConnectionHandler.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index dc97ca77..37f99fe0 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -168,6 +168,13 @@ #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION #endif +#ifdef ARDUINO_EDGE_CONTROL + #include + #define BOARD_HAS_CATM1_NBIOT + #define BOARD_HAS_PORTENTA_CATM1_NBIOT_SHIELD + #define NETWORK_HARDWARE_ERROR +#endif + /****************************************************************************** TYPEDEFS ******************************************************************************/ From 17b49afd2ec72f1c46f819be889fbd5e6ee0de6d Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 21 Nov 2023 12:47:36 +0100 Subject: [PATCH 125/203] Edge Control: provide modem power supply through maker slot 2 --- src/Arduino_CatM1ConnectionHandler.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Arduino_CatM1ConnectionHandler.cpp b/src/Arduino_CatM1ConnectionHandler.cpp index 59d47fe9..9843a09e 100644 --- a/src/Arduino_CatM1ConnectionHandler.cpp +++ b/src/Arduino_CatM1ConnectionHandler.cpp @@ -54,6 +54,10 @@ unsigned long CatM1ConnectionHandler::getTime() NetworkConnectionState CatM1ConnectionHandler::update_handleInit() { +#if defined (ARDUINO_EDGE_CONTROL) + pinMode(ON_MKR2, OUTPUT); + digitalWrite(ON_MKR2, HIGH); +#endif return NetworkConnectionState::CONNECTING; } From 1eace9b59875c49503c1f67db49cc85b2f33a77b Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 21 Nov 2023 12:48:04 +0100 Subject: [PATCH 126/203] WiFi: add missing space --- src/Arduino_WiFiConnectionHandler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_WiFiConnectionHandler.h b/src/Arduino_WiFiConnectionHandler.h index 56670793..bf16fa06 100644 --- a/src/Arduino_WiFiConnectionHandler.h +++ b/src/Arduino_WiFiConnectionHandler.h @@ -38,7 +38,7 @@ class WiFiConnectionHandler : public ConnectionHandler virtual unsigned long getTime() override; - virtual Client & getClient() override{ return _wifi_client; } + virtual Client & getClient() override { return _wifi_client; } virtual UDP & getUDP() override { return _wifi_udp; } From 15caaf23fb9619df837875a85e1cd5de58be08af Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 21 Nov 2023 13:04:54 +0100 Subject: [PATCH 127/203] Add mbed_edge architecture in library.properties file --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index fdf2b9b4..bcd31936 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethe 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 +architectures=samd,esp32,esp8266,mbed,megaavr,mbed_nano,mbed_portenta,mbed_nicla,mbed_opta,mbed_giga,renesas_portenta,renesas_uno,mbed_edge depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN From e02e0855ebf746b978431f2e399fb094f7d08248 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 21 Nov 2023 13:05:31 +0100 Subject: [PATCH 128/203] Add mbed_edge to compile examples workflow --- .github/workflows/compile-examples.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 835966f8..87aaa450 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -76,6 +76,8 @@ jobs: platform-name: arduino:renesas_uno - fqbn: arduino:esp32:nano_nora platform-name: arduino:esp32 + - fqbn: arduino:mbed_edge:edge_control + platform-name: arduino:mbed_edge # Make board type-specific customizations to the matrix jobs include: From d7aa0959e3a5291a6c37a4a573cff060cef277a5 Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Mon, 27 Nov 2023 10:37:37 +0100 Subject: [PATCH 129/203] Release 0.8.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index bcd31936..bfe9f5f7 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.7.7 +version=0.8.0 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From e71ffd0c60f1e411af371f91bc9fe0fdee652de5 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 27 Nov 2023 13:51:48 +0100 Subject: [PATCH 130/203] CatM1ConnectionHandler: fix NetworkAdapter initialization --- src/Arduino_CatM1ConnectionHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_CatM1ConnectionHandler.cpp b/src/Arduino_CatM1ConnectionHandler.cpp index 9843a09e..0b99716d 100644 --- a/src/Arduino_CatM1ConnectionHandler.cpp +++ b/src/Arduino_CatM1ConnectionHandler.cpp @@ -28,7 +28,7 @@ ******************************************************************************/ CatM1ConnectionHandler::CatM1ConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, RadioAccessTechnologyType rat, uint32_t band, bool const keep_alive) -: ConnectionHandler{keep_alive, NetworkAdapter::GSM} +: ConnectionHandler{keep_alive, NetworkAdapter::CATM1} , _pin(pin) , _apn(apn) , _login(login) From 1c5fb9b625080b2f5b700a6693115dc005b17094 Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Mon, 27 Nov 2023 14:40:19 +0100 Subject: [PATCH 131/203] Release 0.8.1 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index bfe9f5f7..7739c63f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.8.0 +version=0.8.1 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino.cc sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From 36aa0080e9ecd699e8fc53157f9ea00e2c957639 Mon Sep 17 00:00:00 2001 From: Giampaolo Mancini Date: Wed, 13 Dec 2023 13:06:49 +0100 Subject: [PATCH 132/203] Add support for custom Ethernet timeouts --- src/Arduino_EthernetConnectionHandler.cpp | 18 +++++++++++++----- src/Arduino_EthernetConnectionHandler.h | 9 ++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp index 0753eb23..0fa2e254 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -24,32 +24,38 @@ CTOR/DTOR ******************************************************************************/ -EthernetConnectionHandler::EthernetConnectionHandler(bool const keep_alive) +EthernetConnectionHandler::EthernetConnectionHandler(unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} ,_ip{INADDR_NONE} ,_dns{INADDR_NONE} ,_gateway{INADDR_NONE} ,_netmask{INADDR_NONE} +,_timeout{timeout} +,_response_timeout{responseTimeout} { } -EthernetConnectionHandler::EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, bool const keep_alive) +EthernetConnectionHandler::EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} ,_ip{ip} ,_dns{dns} ,_gateway{gateway} ,_netmask{netmask} +,_timeout{timeout} +,_response_timeout{responseTimeout} { } -EthernetConnectionHandler::EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, bool const keep_alive) +EthernetConnectionHandler::EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} ,_ip{INADDR_NONE} ,_dns{INADDR_NONE} ,_gateway{INADDR_NONE} ,_netmask{INADDR_NONE} +,_timeout{timeout} +,_response_timeout{responseTimeout} { if(!_ip.fromString(ip)) { _ip = INADDR_NONE; @@ -81,13 +87,15 @@ NetworkConnectionState EthernetConnectionHandler::update_handleInit() NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() { if (_ip != INADDR_NONE) { - if (Ethernet.begin(nullptr, _ip, _dns, _gateway, _netmask, 15000, 4000) == 0) { + if (Ethernet.begin(nullptr, _ip, _dns, _gateway, _netmask, _timeout, _response_timeout) == 0) { Debug.print(DBG_ERROR, F("Failed to configure Ethernet, check cable connection")); + Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", _timeout, _response_timeout); return NetworkConnectionState::CONNECTING; } } else { - if (Ethernet.begin(nullptr, 15000, 4000) == 0) { + if (Ethernet.begin(nullptr, _timeout, _response_timeout) == 0) { Debug.print(DBG_ERROR, F("Waiting Ethernet configuration from DHCP server, check cable connection")); + Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", _timeout, _response_timeout); return NetworkConnectionState::CONNECTING; } } diff --git a/src/Arduino_EthernetConnectionHandler.h b/src/Arduino_EthernetConnectionHandler.h index bac7bf45..cc22bfee 100644 --- a/src/Arduino_EthernetConnectionHandler.h +++ b/src/Arduino_EthernetConnectionHandler.h @@ -31,9 +31,9 @@ class EthernetConnectionHandler : public ConnectionHandler { public: - EthernetConnectionHandler(bool const keep_alive = true); - EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, bool const keep_alive = true); - EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, bool const keep_alive = true); + EthernetConnectionHandler(unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true); + EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true); + EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true); virtual unsigned long getTime() override { return 0; } @@ -56,6 +56,9 @@ class EthernetConnectionHandler : public ConnectionHandler IPAddress _gateway; IPAddress _netmask; + unsigned long _timeout; + unsigned long _response_timeout; + EthernetUDP _eth_udp; EthernetClient _eth_client; From a0168cf103259c48db45e334de862a1d58db5377 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 29 Feb 2024 05:28:45 +0100 Subject: [PATCH 133/203] Bump actions/download-artifact from 3 to 4 (#108) Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 3 to 4. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 9cde1acc..885a8ac0 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -108,7 +108,7 @@ jobs: uses: actions/checkout@v4 - name: Download configuration files artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} path: ${{ env.CONFIGURATIONS_FOLDER }} From 03005ac1f57681ca298807f95f5666ed4db390b5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 29 Feb 2024 05:29:16 +0100 Subject: [PATCH 134/203] Bump actions/upload-artifact from 3 to 4 (#109) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/compile-examples.yml | 2 +- .github/workflows/sync-labels.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 87aaa450..0d1f6fd3 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -165,7 +165,7 @@ jobs: - name: Save memory usage change report as artifact if: github.event_name == 'pull_request' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: if-no-files-found: error name: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 885a8ac0..2e1d6e05 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -70,7 +70,7 @@ jobs: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} - name: Pass configuration files to next job via workflow artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: path: | *.yaml From 3e21ace643838f7fcebfb79033bea8116d4e77df Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 29 Feb 2024 05:29:28 +0100 Subject: [PATCH 135/203] Bump geekyeggo/delete-artifact from 2 to 4 (#110) Bumps [geekyeggo/delete-artifact](https://github.com/geekyeggo/delete-artifact) from 2 to 4. - [Release notes](https://github.com/geekyeggo/delete-artifact/releases) - [Changelog](https://github.com/GeekyEggo/delete-artifact/blob/main/CHANGELOG.md) - [Commits](https://github.com/geekyeggo/delete-artifact/compare/v2...v4) --- updated-dependencies: - dependency-name: geekyeggo/delete-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 2e1d6e05..47ac50a4 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -114,7 +114,7 @@ jobs: path: ${{ env.CONFIGURATIONS_FOLDER }} - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v2 + uses: geekyeggo/delete-artifact@v4 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} From 2b21c3c361428f38b95b9a3f506a4cf7e7a85c87 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 4 Mar 2024 06:02:21 +0100 Subject: [PATCH 136/203] Fix regression re report-size-deltas after updating actions/upload-artifact. (#113) For more information see https://github.com/arduino/report-size-deltas/blob/main/docs/FAQ.md#size-deltas-report-workflow-triggered-by-schedule-event . --- .github/workflows/compile-examples.yml | 21 ++++++++++++++++++++- .github/workflows/report-size-deltas.yml | 4 ++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 0d1f6fd3..dc94e2ab 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -42,42 +42,61 @@ jobs: board: - fqbn: "arduino:samd:mkr1000" platform-name: arduino:samd + artifact-name-suffix: arduino-samd-mkr1000 - fqbn: "arduino:samd:mkrwifi1010" platform-name: arduino:samd + artifact-name-suffix: arduino-samd-mkrwifi1010 - fqbn: "arduino:samd:nano_33_iot" platform-name: arduino:samd + artifact-name-suffix: arduino-samd-nano_33_iot - fqbn: "arduino:samd:mkrgsm1400" platform-name: arduino:samd + artifact-name-suffix: arduino-samd-mkrgsm1400 - fqbn: "arduino:samd:mkrnb1500" platform-name: arduino:samd + artifact-name-suffix: arduino-samd-mkrnb1500 - fqbn: "arduino:samd:mkrwan1300" platform-name: arduino:samd + artifact-name-suffix: arduino-samd-mkrwan1300 - fqbn: "arduino:samd:mkrwan1310" platform-name: arduino:samd + artifact-name-suffix: arduino-samd-mkrwan1310 - fqbn: "arduino:mbed:envie_m7" platform-name: arduino:mbed + artifact-name-suffix: arduino-mbed-envie_m7 - fqbn: "arduino:mbed_portenta:envie_m7" platform-name: arduino:mbed_portenta + artifact-name-suffix: arduino-mbed_portenta-envie_m7 - fqbn: "esp8266:esp8266:huzzah" platform-name: esp8266:esp8266 + artifact-name-suffix: esp8266-esp8266-huzzah - fqbn: "esp32:esp32:esp32" platform-name: esp32:esp32 + artifact-name-suffix: esp32-esp32-esp32 - fqbn: arduino:mbed_nano:nanorp2040connect platform-name: arduino:mbed_nano + artifact-name-suffix: arduino-mbed_nano-nanorp2040connect - fqbn: arduino:mbed_nicla:nicla_vision platform-name: arduino:mbed_nicla + artifact-name-suffix: arduino-mbed_nicla-nicla_vision - fqbn: arduino:mbed_opta:opta platform-name: arduino:mbed_opta + artifact-name-suffix: arduino-mbed_opta-opta - fqbn: arduino:mbed_giga:giga platform-name: arduino:mbed_giga + artifact-name-suffix: arduino-mbed_giga-giga - fqbn: arduino:renesas_portenta:portenta_c33 platform-name: arduino:renesas_portenta + artifact-name-suffix: arduino-renesas_portenta-portenta_c33 - fqbn: arduino:renesas_uno:unor4wifi platform-name: arduino:renesas_uno + artifact-name-suffix: arduino-renesas_uno-unor4wifi - fqbn: arduino:esp32:nano_nora platform-name: arduino:esp32 + artifact-name-suffix: arduino-esp32-nano_nora - fqbn: arduino:mbed_edge:edge_control platform-name: arduino:mbed_edge + artifact-name-suffix: arduino-mbed_edge-edge_control # Make board type-specific customizations to the matrix jobs include: @@ -168,5 +187,5 @@ jobs: uses: actions/upload-artifact@v4 with: if-no-files-found: error - name: ${{ env.SKETCHES_REPORTS_PATH }} + name: sketches-report-${{ matrix.board.artifact-name-suffix }} path: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml index 91730129..d7b942ed 100644 --- a/.github/workflows/report-size-deltas.yml +++ b/.github/workflows/report-size-deltas.yml @@ -17,5 +17,5 @@ jobs: - name: Comment size deltas reports to PRs uses: arduino/report-size-deltas@v1 with: - # The name of the workflow artifact created by the sketch compilation workflow - sketches-reports-source: sketches-reports + # Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow + sketches-reports-source: ^sketches-report-.+ From 53db2d588895165b2fc87e254889369b3f640026 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 15:00:01 +0100 Subject: [PATCH 137/203] Bump geekyeggo/delete-artifact from 4 to 5 (#117) Bumps [geekyeggo/delete-artifact](https://github.com/geekyeggo/delete-artifact) from 4 to 5. - [Release notes](https://github.com/geekyeggo/delete-artifact/releases) - [Changelog](https://github.com/GeekyEggo/delete-artifact/blob/main/CHANGELOG.md) - [Commits](https://github.com/geekyeggo/delete-artifact/compare/v4...v5) --- updated-dependencies: - dependency-name: geekyeggo/delete-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 47ac50a4..53a9f54f 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -114,7 +114,7 @@ jobs: path: ${{ env.CONFIGURATIONS_FOLDER }} - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v4 + uses: geekyeggo/delete-artifact@v5 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} From 8d09c724a83df5adba864584d3833e014883e9e6 Mon Sep 17 00:00:00 2001 From: "Zachary J. Fields" Date: Tue, 6 Feb 2024 10:27:27 -0600 Subject: [PATCH 138/203] chore: Clarify secret usage with comments --- examples/ConnectionHandlerDemo/arduino_secrets.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/ConnectionHandlerDemo/arduino_secrets.h b/examples/ConnectionHandlerDemo/arduino_secrets.h index 5836270e..4d9fb7c8 100644 --- a/examples/ConnectionHandlerDemo/arduino_secrets.h +++ b/examples/ConnectionHandlerDemo/arduino_secrets.h @@ -1,14 +1,18 @@ +// Required for WiFiConnectionHandler const char SECRET_SSID[] = "NETWORK NAME"; const char SECRET_PASS[] = "NETWORK PASSWORD"; +// Required for GSMConnectionHandler const char SECRET_APN[] = "MOBILE PROVIDER APN ADDRESS"; -const char SECRET_PIN[] = "0000"; +const char SECRET_PIN[] = "0000"; // Required for NBConnectionHandler const char SECRET_GSM_USER[] = "GSM USERNAME"; const char SECRET_GSM_PASS[] = "GSM PASSWORD"; +// Required for LoRaConnectionHandler const char SECRET_APP_EUI[] = "APP_EUI"; const char SECRET_APP_KEY[] = "APP_KEY"; +// Required for EthernetConnectionHandler (without DHCP mode) const char SECRET_IP[] = "IP ADDRESS"; const char SECRET_DNS[] = "DNS ADDRESS"; const char SECRET_GATEWAY[] = "GATEWAY ADDRESS"; From 54fe98c93856723da8983a569a80131aa971a371 Mon Sep 17 00:00:00 2001 From: "Zachary J. Fields" Date: Fri, 9 Feb 2024 11:28:51 -0600 Subject: [PATCH 139/203] chore: LoRa to use BOARD_HAS_LORA Follows precedent established by Wi-Fi implementation. --- src/Arduino_LoRaConnectionHandler.cpp | 6 +++--- src/Arduino_LoRaConnectionHandler.h | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Arduino_LoRaConnectionHandler.cpp b/src/Arduino_LoRaConnectionHandler.cpp index fa06e595..cf1deaf0 100644 --- a/src/Arduino_LoRaConnectionHandler.cpp +++ b/src/Arduino_LoRaConnectionHandler.cpp @@ -19,10 +19,10 @@ INCLUDE ******************************************************************************/ -#if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) /* Only compile if the board has LoRa */ - #include "Arduino_LoRaConnectionHandler.h" +#if defined(BOARD_HAS_LORA) /* Only compile if the board has LoRa */ + /****************************************************************************** TYPEDEF ******************************************************************************/ @@ -106,7 +106,7 @@ NetworkConnectionState LoRaConnectionHandler::update_handleInit() { Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry.")); return NetworkConnectionState::ERROR; - } + } // Set channelmask based on configuration if (_channelMask) { _modem.sendMask(_channelMask); diff --git a/src/Arduino_LoRaConnectionHandler.h b/src/Arduino_LoRaConnectionHandler.h index 2d76cb34..aa769ab5 100644 --- a/src/Arduino_LoRaConnectionHandler.h +++ b/src/Arduino_LoRaConnectionHandler.h @@ -24,6 +24,8 @@ #include "Arduino_ConnectionHandler.h" +#ifdef BOARD_HAS_LORA /* Only compile if the board has LoRa */ + /****************************************************************************** CLASS DECLARATION ******************************************************************************/ @@ -72,4 +74,6 @@ class LoRaConnectionHandler : public ConnectionHandler LoRaModem _modem; }; +#endif /* #ifdef BOARD_HAS_LORA */ + #endif /* ARDUINO_LORA_CONNECTION_HANDLER_H_ */ From d689119b41c094cde528bf2ff499c62a70a5ab7e Mon Sep 17 00:00:00 2001 From: Ali Jahangiri <75624145+aliphys@users.noreply.github.com> Date: Thu, 11 Apr 2024 16:47:17 +0200 Subject: [PATCH 140/203] Change maintainer to `Arduino ` --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 7739c63f..1bb985e3 100644 --- a/library.properties +++ b/library.properties @@ -1,7 +1,7 @@ name=Arduino_ConnectionHandler version=0.8.1 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. -maintainer=Arduino.cc +maintainer=Arduino sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) paragraph=Originally part of ArduinoIoTCloud category=Communication From f4551983ceb167744527fa3b67567dfed9d5c840 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 2 May 2024 16:34:27 +0200 Subject: [PATCH 141/203] Add CellularConnectionHandler --- src/Arduino_CellularConnectionHandler.cpp | 89 +++++++++++++++++++++++ src/Arduino_CellularConnectionHandler.h | 62 ++++++++++++++++ src/Arduino_ConnectionHandler.h | 16 ++-- 3 files changed, 161 insertions(+), 6 deletions(-) create mode 100644 src/Arduino_CellularConnectionHandler.cpp create mode 100644 src/Arduino_CellularConnectionHandler.h diff --git a/src/Arduino_CellularConnectionHandler.cpp b/src/Arduino_CellularConnectionHandler.cpp new file mode 100644 index 00000000..372bdd24 --- /dev/null +++ b/src/Arduino_CellularConnectionHandler.cpp @@ -0,0 +1,89 @@ +/* + This file is part of the Arduino_ConnectionHandler library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + + +/****************************************************************************** + INCLUDE + ******************************************************************************/ + +#include "Arduino_CellularConnectionHandler.h" + +#ifdef BOARD_HAS_CELLULAR /* Only compile if the board has Cellular */ + +/****************************************************************************** + CTOR/DTOR + ******************************************************************************/ + +CellularConnectionHandler::CellularConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, bool const keep_alive) +: ConnectionHandler{keep_alive, NetworkAdapter::CELL} +, _pin(pin) +, _apn(apn) +, _login(login) +, _pass(pass) +{ + +} + +/****************************************************************************** + PUBLIC MEMBER FUNCTIONS + ******************************************************************************/ + +unsigned long CellularConnectionHandler::getTime() +{ + return _cellular.getCellularTime().getUNIXTimestamp(); +} + +/****************************************************************************** + PROTECTED MEMBER FUNCTIONS + ******************************************************************************/ + +NetworkConnectionState CellularConnectionHandler::update_handleInit() +{ + _cellular.begin(); + _cellular.setDebugStream(Serial); + if (String(_pin).length() > 0 && !_cellular.unlockSIM(_pin)) { + Debug.print(DBG_ERROR, F("SIM not present or wrong PIN")); + return NetworkConnectionState::ERROR; + } + return NetworkConnectionState::CONNECTING; +} + +NetworkConnectionState CellularConnectionHandler::update_handleConnecting() +{ + if (!_cellular.connect(_apn, _login, _pass)) { + Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); + return NetworkConnectionState::ERROR; + } + Debug.print(DBG_INFO, F("Connected to Network")); + return NetworkConnectionState::CONNECTED; +} + +NetworkConnectionState CellularConnectionHandler::update_handleConnected() +{ + if (!_cellular.isConnectedToInternet()) { + return NetworkConnectionState::DISCONNECTED; + } + return NetworkConnectionState::CONNECTED; +} + +NetworkConnectionState CellularConnectionHandler::update_handleDisconnecting() +{ + return NetworkConnectionState::DISCONNECTED; +} + +NetworkConnectionState CellularConnectionHandler::update_handleDisconnected() +{ + if (_keep_alive) { + return NetworkConnectionState::INIT; + } + return NetworkConnectionState::CLOSED; +} + +#endif /* #ifdef BOARD_HAS_CELLULAR */ diff --git a/src/Arduino_CellularConnectionHandler.h b/src/Arduino_CellularConnectionHandler.h new file mode 100644 index 00000000..6270d188 --- /dev/null +++ b/src/Arduino_CellularConnectionHandler.h @@ -0,0 +1,62 @@ +/* + This file is part of the Arduino_ConnectionHandler library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + + +#ifndef ARDUINO_CELLULAR_CONNECTION_HANDLER_H_ +#define ARDUINO_CELLULAR_CONNECTION_HANDLER_H_ + +/****************************************************************************** + INCLUDE + ******************************************************************************/ + +#include "Arduino_ConnectionHandler.h" + + +#ifdef BOARD_HAS_CELLULAR /* Only compile if the board has Cellular */ + +/****************************************************************************** + CLASS DECLARATION + ******************************************************************************/ + +class CellularConnectionHandler : public ConnectionHandler +{ + public: + + CellularConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, bool const keep_alive = true); + + + virtual unsigned long getTime() override; + virtual Client & getClient() override { return _gsm_client; }; + virtual UDP & getUDP() override { } __attribute__((error("CellularConnectionHandler has no UDP support"))); + + + protected: + + virtual NetworkConnectionState update_handleInit () override; + virtual NetworkConnectionState update_handleConnecting () override; + virtual NetworkConnectionState update_handleConnected () override; + virtual NetworkConnectionState update_handleDisconnecting() override; + virtual NetworkConnectionState update_handleDisconnected () override; + + + private: + + const char * _pin; + const char * _apn; + const char * _login; + const char * _pass; + + ArduinoCellular _cellular; + TinyGsmClient _gsm_client = _cellular.getNetworkClient(); +}; + +#endif /* #ifdef BOARD_HAS_CELLULAR */ + +#endif /* #ifndef ARDUINO_CELLULAR_CONNECTION_HANDLER_H_ */ diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 37f99fe0..d3230a01 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -57,6 +57,7 @@ #include #include #include + #include #define BOARD_HAS_WIFI #define BOARD_HAS_ETHERNET @@ -150,7 +151,7 @@ #if defined(ARDUINO_ARCH_ESP32) #include #include - + #define BOARD_HAS_WIFI #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD #define NETWORK_IDLE_STATUS WL_IDLE_STATUS @@ -201,7 +202,8 @@ enum class NetworkAdapter { NB, GSM, LORA, - CATM1 + CATM1, + CELL }; typedef void (*OnNetworkEventCallback)(); @@ -237,13 +239,11 @@ class ConnectionHandler { NetworkConnectionState check(); - #if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT) + #if !defined(BOARD_HAS_LORA) virtual unsigned long getTime() = 0; virtual Client &getClient() = 0; virtual UDP &getUDP() = 0; - #endif - - #if defined(BOARD_HAS_LORA) + #else virtual int write(const uint8_t *buf, size_t size) = 0; virtual int read() = 0; virtual bool available() = 0; @@ -304,4 +304,8 @@ class ConnectionHandler { #include "Arduino_CatM1ConnectionHandler.h" #endif +#if defined(BOARD_HAS_CELLULAR) + #include "Arduino_CellularConnectionHandler.h" +#endif + #endif /* CONNECTION_HANDLER_H_ */ From eb559db9772d123ddba8767008b413e5cc22f3dd Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 24 May 2024 14:25:56 +0200 Subject: [PATCH 142/203] Add Cellular support to PORTENTA_H7 through Portenta Mid Carrier --- src/Arduino_ConnectionHandler.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index d3230a01..89c12c03 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -62,6 +62,7 @@ #define BOARD_HAS_WIFI #define BOARD_HAS_ETHERNET #define BOARD_HAS_CATM1_NBIOT + #define BOARD_HAS_CELLULAR #define BOARD_HAS_PORTENTA_CATM1_NBIOT_SHIELD #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD From 353fd2534672943b2968862b9b34b8cfbbe81216 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 2 May 2024 16:37:00 +0200 Subject: [PATCH 143/203] Add Cellular support to PORTENTA_C33 through Portenta Mid Carrier --- src/Arduino_ConnectionHandler.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 89c12c03..b4f8e315 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -75,9 +75,11 @@ #include #include #include + #include #define BOARD_HAS_WIFI #define BOARD_HAS_ETHERNET + #define BOARD_HAS_CELLULAR #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD #define NETWORK_IDLE_STATUS WL_IDLE_STATUS From 3ac5c054577481f5cc99c36bc87467b2b998d144 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 2 May 2024 16:43:19 +0200 Subject: [PATCH 144/203] Examples: add Cellular support --- .github/workflows/compile-examples.yml | 1 + examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index dc94e2ab..878d5669 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -34,6 +34,7 @@ jobs: - name: MKRGSM - name: MKRNB - name: MKRWAN + - name: Arduino_Cellular ARDUINOCORE_MBED_STAGING_PATH: extras/ArduinoCore-mbed ARDUINOCORE_API_STAGING_PATH: extras/ArduinoCore-API SKETCHES_REPORTS_PATH: sketches-reports diff --git a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino index a5be6a7e..960bfe00 100644 --- a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino +++ b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino @@ -43,6 +43,8 @@ NBConnectionHandler conMan(SECRET_PIN); LoRaConnectionHandler conMan(SECRET_APP_EUI, SECRET_APP_KEY); #elif defined(BOARD_HAS_CATM1_NBIOT) CatM1ConnectionHandler conMan(SECRET_APN, SECRET_PIN, SECRET_GSM_USER, SECRET_GSM_PASS); +#elif defined(BOARD_HAS_CELLULAR) +CellularConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); #endif void setup() { From 075c689a1c00d3eb18eb175aa736db9868ec0786 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 3 Jun 2024 16:15:11 +0200 Subject: [PATCH 145/203] CellularConnectionHandler: Generate runtime error if getUDP() is called __attribute__((error)) not working on virtual functions --- src/Arduino_CellularConnectionHandler.cpp | 6 ++++++ src/Arduino_CellularConnectionHandler.h | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Arduino_CellularConnectionHandler.cpp b/src/Arduino_CellularConnectionHandler.cpp index 372bdd24..7e543b0e 100644 --- a/src/Arduino_CellularConnectionHandler.cpp +++ b/src/Arduino_CellularConnectionHandler.cpp @@ -40,6 +40,12 @@ unsigned long CellularConnectionHandler::getTime() return _cellular.getCellularTime().getUNIXTimestamp(); } +UDP & CellularConnectionHandler::getUDP() +{ + Debug.print(DBG_ERROR, F("CellularConnectionHandler has no UDP support")); + while(1) {}; +} + /****************************************************************************** PROTECTED MEMBER FUNCTIONS ******************************************************************************/ diff --git a/src/Arduino_CellularConnectionHandler.h b/src/Arduino_CellularConnectionHandler.h index 6270d188..0c4d5f89 100644 --- a/src/Arduino_CellularConnectionHandler.h +++ b/src/Arduino_CellularConnectionHandler.h @@ -18,7 +18,6 @@ #include "Arduino_ConnectionHandler.h" - #ifdef BOARD_HAS_CELLULAR /* Only compile if the board has Cellular */ /****************************************************************************** @@ -34,7 +33,7 @@ class CellularConnectionHandler : public ConnectionHandler virtual unsigned long getTime() override; virtual Client & getClient() override { return _gsm_client; }; - virtual UDP & getUDP() override { } __attribute__((error("CellularConnectionHandler has no UDP support"))); + virtual UDP & getUDP() override; protected: From 0f3c9c5cc98a5071b09ef7138f96211b7cafd762 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 4 Jun 2024 08:35:48 +0200 Subject: [PATCH 146/203] Example fix params order for GSMConnectionHandler and CatM1ConnectionHandler --- examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino index 960bfe00..13ad117c 100644 --- a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino +++ b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino @@ -36,13 +36,13 @@ EthernetConnectionHandler conMan(SECRET_IP, SECRET_DNS, SECRET_GATEWAY, SECRET_N #elif defined(BOARD_HAS_WIFI) WiFiConnectionHandler conMan(SECRET_SSID, SECRET_PASS); #elif defined(BOARD_HAS_GSM) -GSMConnectionHandler conMan(SECRET_APN, SECRET_PIN, SECRET_GSM_USER, SECRET_GSM_PASS); +GSMConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); #elif defined(BOARD_HAS_NB) NBConnectionHandler conMan(SECRET_PIN); #elif defined(BOARD_HAS_LORA) LoRaConnectionHandler conMan(SECRET_APP_EUI, SECRET_APP_KEY); #elif defined(BOARD_HAS_CATM1_NBIOT) -CatM1ConnectionHandler conMan(SECRET_APN, SECRET_PIN, SECRET_GSM_USER, SECRET_GSM_PASS); +CatM1ConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); #elif defined(BOARD_HAS_CELLULAR) CellularConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); #endif From d05d54c89780ac7820b4361a4004e3faa064c73b Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Mon, 10 Jun 2024 08:50:43 +0200 Subject: [PATCH 147/203] Release 0.9.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 1bb985e3..16239e46 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.8.1 +version=0.9.0 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) From f2b100a866875110ed5de9c5dd183d385f8e1c11 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 5 Jun 2024 13:48:25 +0200 Subject: [PATCH 148/203] splitting src/Arduino_ConnectionHandler.h into multiple files to avoid cyclic includes --- src/Arduino_ConnectionHandler.h | 270 +----------------- src/Arduino_ConnectionHandlerDefinitions.h | 185 ++++++++++++ ...=> Arduino_ConnectionHandlerInterface.cpp} | 2 +- src/Arduino_ConnectionHandlerInterface.h | 99 +++++++ 4 files changed, 293 insertions(+), 263 deletions(-) create mode 100644 src/Arduino_ConnectionHandlerDefinitions.h rename src/{Arduino_ConnectionHandler.cpp => Arduino_ConnectionHandlerInterface.cpp} (99%) create mode 100644 src/Arduino_ConnectionHandlerInterface.h diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index b4f8e315..ee79dc3a 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -27,275 +27,21 @@ #endif #include +#include "Arduino_ConnectionHandlerDefinitions.h" -#ifdef ARDUINO_SAMD_MKR1000 - #include - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED - #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED -#endif - -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \ - defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined (ARDUINO_NANO_RP2040_CONNECT) - #include - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_MODULE - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED - #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION -#endif - -#if defined(ARDUINO_PORTENTA_H7_M7) - #include - #include - #include - #include - #include - #include - - #define BOARD_HAS_WIFI - #define BOARD_HAS_ETHERNET - #define BOARD_HAS_CATM1_NBIOT - #define BOARD_HAS_CELLULAR - #define BOARD_HAS_PORTENTA_CATM1_NBIOT_SHIELD - #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED -#endif - -#if defined(ARDUINO_PORTENTA_C33) - #include - #include - #include - #include - #include - - #define BOARD_HAS_WIFI - #define BOARD_HAS_ETHERNET - #define BOARD_HAS_CELLULAR - #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED -#endif - -#if defined(ARDUINO_NICLA_VISION) - #include - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED -#endif - -#if defined(ARDUINO_OPTA) - #include - #include - #include - #include - - #define BOARD_HAS_WIFI - #define BOARD_HAS_ETHERNET - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED -#endif - -#if defined(ARDUINO_GIGA) - #include - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED -#endif - -#ifdef ARDUINO_SAMD_MKRGSM1400 - #include - #define BOARD_HAS_GSM - #define NETWORK_HARDWARE_ERROR GPRS_PING_ERROR - #define NETWORK_IDLE_STATUS GSM3_NetworkStatus_t::IDLE - #define NETWORK_CONNECTED GSM3_NetworkStatus_t::GPRS_READY -#endif - -#ifdef ARDUINO_SAMD_MKRNB1500 - #include - #define BOARD_HAS_NB - #define NETWORK_HARDWARE_ERROR - #define NETWORK_IDLE_STATUS NB_NetworkStatus_t::IDLE - #define NETWORK_CONNECTED NB_NetworkStatus_t::GPRS_READY -#endif - -#if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) - #include - #define BOARD_HAS_LORA -#endif - -#if defined(ARDUINO_ARCH_ESP8266) - #include - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED - #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED -#endif - -#if defined(ARDUINO_ARCH_ESP32) - #include - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED - #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED -#endif - -#if defined(ARDUINO_UNOR4_WIFI) - #include - - #define BOARD_HAS_WIFI - #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD - #define NETWORK_IDLE_STATUS WL_IDLE_STATUS - #define NETWORK_CONNECTED WL_CONNECTED - #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION +#if defined(BOARD_HAS_WIFI) + #include "Arduino_WiFiConnectionHandler.h" #endif -#ifdef ARDUINO_EDGE_CONTROL - #include - #define BOARD_HAS_CATM1_NBIOT - #define BOARD_HAS_PORTENTA_CATM1_NBIOT_SHIELD - #define NETWORK_HARDWARE_ERROR +#if defined(BOARD_HAS_GSM) + #include "Arduino_GSMConnectionHandler.h" #endif -/****************************************************************************** - TYPEDEFS - ******************************************************************************/ - -enum class NetworkConnectionState : unsigned int { - INIT = 0, - CONNECTING = 1, - CONNECTED = 2, - DISCONNECTING = 3, - DISCONNECTED = 4, - CLOSED = 5, - ERROR = 6 -}; - -enum class NetworkConnectionEvent { - CONNECTED, - DISCONNECTED, - ERROR -}; - -enum class NetworkAdapter { - WIFI, - ETHERNET, - NB, - GSM, - LORA, - CATM1, - CELL -}; - -typedef void (*OnNetworkEventCallback)(); - -/****************************************************************************** - CONSTANTS - ******************************************************************************/ - -static unsigned int const CHECK_INTERVAL_TABLE[] = -{ - /* INIT */ 100, -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - /* CONNECTING */ 4000, -#else - /* CONNECTING */ 500, +#if defined(BOARD_HAS_NB) + #include "Arduino_NBConnectionHandler.h" #endif - /* CONNECTED */ 10000, - /* DISCONNECTING */ 100, - /* DISCONNECTED */ 1000, - /* CLOSED */ 1000, - /* ERROR */ 1000 -}; - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - -class ConnectionHandler { - public: - - ConnectionHandler(bool const keep_alive, NetworkAdapter interface); - - NetworkConnectionState check(); - - #if !defined(BOARD_HAS_LORA) - virtual unsigned long getTime() = 0; - virtual Client &getClient() = 0; - virtual UDP &getUDP() = 0; - #else - virtual int write(const uint8_t *buf, size_t size) = 0; - virtual int read() = 0; - virtual bool available() = 0; - #endif - - NetworkConnectionState getStatus() __attribute__((deprecated)) { - return _current_net_connection_state; - } - - NetworkAdapter getInterface() { - return _interface; - } - - void connect(); - void disconnect(); - - void addCallback(NetworkConnectionEvent const event, OnNetworkEventCallback callback); - void addConnectCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); - void addDisconnectCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); - void addErrorCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); - - protected: - - bool _keep_alive; - NetworkAdapter _interface; - - virtual NetworkConnectionState update_handleInit () = 0; - virtual NetworkConnectionState update_handleConnecting () = 0; - virtual NetworkConnectionState update_handleConnected () = 0; - virtual NetworkConnectionState update_handleDisconnecting() = 0; - virtual NetworkConnectionState update_handleDisconnected () = 0; - - - private: - - unsigned long _lastConnectionTickTime; - NetworkConnectionState _current_net_connection_state; - OnNetworkEventCallback _on_connect_event_callback = NULL, - _on_disconnect_event_callback = NULL, - _on_error_event_callback = NULL; -}; - -#if defined(BOARD_HAS_WIFI) - #include "Arduino_WiFiConnectionHandler.h" -#elif defined(BOARD_HAS_GSM) - #include "Arduino_GSMConnectionHandler.h" -#elif defined(BOARD_HAS_NB) - #include "Arduino_NBConnectionHandler.h" -#elif defined(BOARD_HAS_LORA) +#if defined(BOARD_HAS_LORA) #include "Arduino_LoRaConnectionHandler.h" #endif diff --git a/src/Arduino_ConnectionHandlerDefinitions.h b/src/Arduino_ConnectionHandlerDefinitions.h new file mode 100644 index 00000000..74212d3e --- /dev/null +++ b/src/Arduino_ConnectionHandlerDefinitions.h @@ -0,0 +1,185 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#pragma once + +/****************************************************************************** + INCLUDES + ******************************************************************************/ + +#include + +#ifdef ARDUINO_SAMD_MKR1000 + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED + #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED +#endif + +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \ + defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined (ARDUINO_NANO_RP2040_CONNECT) + + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_MODULE + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED + #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION +#endif + +#if defined(ARDUINO_PORTENTA_H7_M7) + #define BOARD_HAS_WIFI + #define BOARD_HAS_ETHERNET + #define BOARD_HAS_CATM1_NBIOT + #define BOARD_HAS_CELLULAR + #define BOARD_HAS_PORTENTA_CATM1_NBIOT_SHIELD + #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + +#if defined(ARDUINO_PORTENTA_C33) + #define BOARD_HAS_WIFI + #define BOARD_HAS_ETHERNET + #define BOARD_HAS_CELLULAR + #define BOARD_HAS_PORTENTA_VISION_SHIELD_ETHERNET + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + +#if defined(ARDUINO_NICLA_VISION) + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + +#if defined(ARDUINO_OPTA) + #define BOARD_HAS_WIFI + #define BOARD_HAS_ETHERNET + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + +#if defined(ARDUINO_GIGA) + + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + +#ifdef ARDUINO_SAMD_MKRGSM1400 + #define BOARD_HAS_GSM + #define NETWORK_HARDWARE_ERROR GPRS_PING_ERROR + #define NETWORK_IDLE_STATUS GSM3_NetworkStatus_t::IDLE + #define NETWORK_CONNECTED GSM3_NetworkStatus_t::GPRS_READY +#endif + +#ifdef ARDUINO_SAMD_MKRNB1500 + #define BOARD_HAS_NB + #define NETWORK_HARDWARE_ERROR + #define NETWORK_IDLE_STATUS NB_NetworkStatus_t::IDLE + #define NETWORK_CONNECTED NB_NetworkStatus_t::GPRS_READY +#endif + +#if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) + #define BOARD_HAS_LORA +#endif + +#if defined(ARDUINO_ARCH_ESP8266) + + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED + #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED +#endif + +#if defined(ARDUINO_ARCH_ESP32) + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED + #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED +#endif + +#if defined(ARDUINO_UNOR4_WIFI) + + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED + #define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_LATEST_VERSION +#endif + +#ifdef ARDUINO_EDGE_CONTROL + #define BOARD_HAS_CATM1_NBIOT + #define BOARD_HAS_PORTENTA_CATM1_NBIOT_SHIELD + #define NETWORK_HARDWARE_ERROR +#endif + +/****************************************************************************** + TYPEDEFS + ******************************************************************************/ + +enum class NetworkConnectionState : unsigned int { + INIT = 0, + CONNECTING = 1, + CONNECTED = 2, + DISCONNECTING = 3, + DISCONNECTED = 4, + CLOSED = 5, + ERROR = 6 +}; + +enum class NetworkConnectionEvent { + CONNECTED, + DISCONNECTED, + ERROR +}; + +enum class NetworkAdapter { + WIFI, + ETHERNET, + NB, + GSM, + LORA, + CATM1 +}; + +/****************************************************************************** + CONSTANTS + ******************************************************************************/ + +static unsigned int const CHECK_INTERVAL_TABLE[] = +{ + /* INIT */ 100, +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) + /* CONNECTING */ 4000, +#else + /* CONNECTING */ 500, +#endif + /* CONNECTED */ 10000, + /* DISCONNECTING */ 100, + /* DISCONNECTED */ 1000, + /* CLOSED */ 1000, + /* ERROR */ 1000 +}; diff --git a/src/Arduino_ConnectionHandler.cpp b/src/Arduino_ConnectionHandlerInterface.cpp similarity index 99% rename from src/Arduino_ConnectionHandler.cpp rename to src/Arduino_ConnectionHandlerInterface.cpp index ab83fa08..ccfc4df9 100644 --- a/src/Arduino_ConnectionHandler.cpp +++ b/src/Arduino_ConnectionHandlerInterface.cpp @@ -19,7 +19,7 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" +#include "Arduino_ConnectionHandlerInterface.h" /****************************************************************************** CONSTRUCTOR/DESTRUCTOR diff --git a/src/Arduino_ConnectionHandlerInterface.h b/src/Arduino_ConnectionHandlerInterface.h new file mode 100644 index 00000000..52a09bd5 --- /dev/null +++ b/src/Arduino_ConnectionHandlerInterface.h @@ -0,0 +1,99 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#pragma once + +/****************************************************************************** + INCLUDES + ******************************************************************************/ + +#if !defined(__AVR__) +# include +#endif + +#include +#include +#include +#include "Arduino_ConnectionHandlerDefinitions.h" + +/****************************************************************************** + TYPEDEFS + ******************************************************************************/ + +typedef void (*OnNetworkEventCallback)(); + +/****************************************************************************** + CLASS DECLARATION + ******************************************************************************/ + +class ConnectionHandler { + public: + + ConnectionHandler(bool const keep_alive, NetworkAdapter interface); + + + NetworkConnectionState check(); + + #if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT) + virtual unsigned long getTime() = 0; + virtual Client &getClient() = 0; + virtual UDP &getUDP() = 0; + #endif + + #if defined(BOARD_HAS_LORA) + virtual int write(const uint8_t *buf, size_t size) = 0; + virtual int read() = 0; + virtual bool available() = 0; + #endif + + NetworkConnectionState getStatus() __attribute__((deprecated)) { + return _current_net_connection_state; + } + + NetworkAdapter getInterface() { + return _interface; + } + + void connect(); + void disconnect(); + + void addCallback(NetworkConnectionEvent const event, OnNetworkEventCallback callback); + void addConnectCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); + void addDisconnectCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); + void addErrorCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); + + protected: + + bool _keep_alive; + NetworkAdapter _interface; + + virtual NetworkConnectionState update_handleInit () = 0; + virtual NetworkConnectionState update_handleConnecting () = 0; + virtual NetworkConnectionState update_handleConnected () = 0; + virtual NetworkConnectionState update_handleDisconnecting() = 0; + virtual NetworkConnectionState update_handleDisconnected () = 0; + + + private: + + unsigned long _lastConnectionTickTime; + NetworkConnectionState _current_net_connection_state; + OnNetworkEventCallback _on_connect_event_callback = NULL, + _on_disconnect_event_callback = NULL, + _on_error_event_callback = NULL; +}; + From f39958c8899828e3503cfa337afaea66cd2e791c Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 5 Jun 2024 13:48:52 +0200 Subject: [PATCH 149/203] readapting implementations to the new include structure --- src/Arduino_CatM1ConnectionHandler.cpp | 5 ++-- src/Arduino_CatM1ConnectionHandler.h | 9 +++---- src/Arduino_CellularConnectionHandler.cpp | 3 ++- src/Arduino_CellularConnectionHandler.h | 7 ++--- src/Arduino_ConnectionHandlerDefinitions.h | 3 ++- src/Arduino_EthernetConnectionHandler.cpp | 3 ++- src/Arduino_EthernetConnectionHandler.h | 17 ++++++++---- src/Arduino_GSMConnectionHandler.cpp | 3 ++- src/Arduino_GSMConnectionHandler.h | 9 +++---- src/Arduino_LoRaConnectionHandler.cpp | 3 ++- src/Arduino_LoRaConnectionHandler.h | 6 ++++- src/Arduino_NBConnectionHandler.cpp | 3 ++- src/Arduino_NBConnectionHandler.h | 8 +++--- src/Arduino_WiFiConnectionHandler.cpp | 5 ++-- src/Arduino_WiFiConnectionHandler.h | 30 ++++++++++++++++++---- 15 files changed, 76 insertions(+), 38 deletions(-) diff --git a/src/Arduino_CatM1ConnectionHandler.cpp b/src/Arduino_CatM1ConnectionHandler.cpp index 0b99716d..46553730 100644 --- a/src/Arduino_CatM1ConnectionHandler.cpp +++ b/src/Arduino_CatM1ConnectionHandler.cpp @@ -19,9 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_CatM1ConnectionHandler.h" +#include "Arduino_ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_CATM1_NBIOT /* Only compile if the board has CatM1 BN-IoT */ +#include "Arduino_CatM1ConnectionHandler.h" /****************************************************************************** CTOR/DTOR @@ -96,7 +97,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnected() } else { - return NetworkConnectionState::CLOSED; + return NetworkConnectionState::CLOSED; } } diff --git a/src/Arduino_CatM1ConnectionHandler.h b/src/Arduino_CatM1ConnectionHandler.h index de5fd01f..ec6b2633 100644 --- a/src/Arduino_CatM1ConnectionHandler.h +++ b/src/Arduino_CatM1ConnectionHandler.h @@ -22,10 +22,11 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" +#include "Arduino_ConnectionHandlerInterface.h" - -#ifdef BOARD_HAS_CATM1_NBIOT /* Only compile if the board has CatM1 BN-IoT */ +#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_EDGE_CONTROL) + #include +#endif /****************************************************************************** CLASS DECLARATION @@ -66,6 +67,4 @@ class CatM1ConnectionHandler : public ConnectionHandler GSMClient _gsm_client; }; -#endif /* #ifdef BOARD_HAS_CATM1_NBIOT */ - #endif /* #ifndef ARDUINO_CATM1_CONNECTION_HANDLER_H_ */ diff --git a/src/Arduino_CellularConnectionHandler.cpp b/src/Arduino_CellularConnectionHandler.cpp index 7e543b0e..ff7111c7 100644 --- a/src/Arduino_CellularConnectionHandler.cpp +++ b/src/Arduino_CellularConnectionHandler.cpp @@ -13,9 +13,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_CellularConnectionHandler.h" +#include "Arduino_ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_CELLULAR /* Only compile if the board has Cellular */ +#include "Arduino_CellularConnectionHandler.h" /****************************************************************************** CTOR/DTOR diff --git a/src/Arduino_CellularConnectionHandler.h b/src/Arduino_CellularConnectionHandler.h index 0c4d5f89..8515fa99 100644 --- a/src/Arduino_CellularConnectionHandler.h +++ b/src/Arduino_CellularConnectionHandler.h @@ -18,12 +18,15 @@ #include "Arduino_ConnectionHandler.h" -#ifdef BOARD_HAS_CELLULAR /* Only compile if the board has Cellular */ /****************************************************************************** CLASS DECLARATION ******************************************************************************/ +#if defined(ARDUINO_PORTENTA_C33) || defined(ARDUINO_PORTENTA_H7_M7) +#include +#endif + class CellularConnectionHandler : public ConnectionHandler { public: @@ -56,6 +59,4 @@ class CellularConnectionHandler : public ConnectionHandler TinyGsmClient _gsm_client = _cellular.getNetworkClient(); }; -#endif /* #ifdef BOARD_HAS_CELLULAR */ - #endif /* #ifndef ARDUINO_CELLULAR_CONNECTION_HANDLER_H_ */ diff --git a/src/Arduino_ConnectionHandlerDefinitions.h b/src/Arduino_ConnectionHandlerDefinitions.h index 74212d3e..3fdde169 100644 --- a/src/Arduino_ConnectionHandlerDefinitions.h +++ b/src/Arduino_ConnectionHandlerDefinitions.h @@ -162,7 +162,8 @@ enum class NetworkAdapter { NB, GSM, LORA, - CATM1 + CATM1, + CELL }; /****************************************************************************** diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp index 0fa2e254..52254501 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -16,9 +16,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_EthernetConnectionHandler.h" +#include "Arduino_ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_ETHERNET /* Only compile if the board has ethernet */ +#include "Arduino_EthernetConnectionHandler.h" /****************************************************************************** CTOR/DTOR diff --git a/src/Arduino_EthernetConnectionHandler.h b/src/Arduino_EthernetConnectionHandler.h index cc22bfee..29dde2fa 100644 --- a/src/Arduino_EthernetConnectionHandler.h +++ b/src/Arduino_EthernetConnectionHandler.h @@ -19,9 +19,18 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" - -#ifdef BOARD_HAS_ETHERNET /* Only compile if the board has ethernet */ +#include "Arduino_ConnectionHandlerInterface.h" + +#if defined(ARDUINO_PORTENTA_H7_M7) + #include + #include +#elif defined(ARDUINO_PORTENTA_C33) + #include + #include +#elif defined(ARDUINO_OPTA) + #include + #include +#endif /****************************************************************************** CLASS DECLARATION @@ -64,6 +73,4 @@ class EthernetConnectionHandler : public ConnectionHandler }; -#endif /* #ifdef BOARD_HAS_ETHERNET */ - #endif /* ARDUINO_ETHERNET_CONNECTION_HANDLER_H_ */ diff --git a/src/Arduino_GSMConnectionHandler.cpp b/src/Arduino_GSMConnectionHandler.cpp index e57a7201..684abdee 100644 --- a/src/Arduino_GSMConnectionHandler.cpp +++ b/src/Arduino_GSMConnectionHandler.cpp @@ -19,9 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_GSMConnectionHandler.h" +#include "Arduino_ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_GSM /* Only compile if this is a board with GSM */ +#include "Arduino_GSMConnectionHandler.h" /****************************************************************************** CONSTANTS diff --git a/src/Arduino_GSMConnectionHandler.h b/src/Arduino_GSMConnectionHandler.h index 714ed8c5..c2d2b053 100644 --- a/src/Arduino_GSMConnectionHandler.h +++ b/src/Arduino_GSMConnectionHandler.h @@ -22,10 +22,11 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" +#include "Arduino_ConnectionHandlerInterface.h" - -#ifdef BOARD_HAS_GSM /* Only compile if this is a board with GSM */ +#if defined(ARDUINO_SAMD_MKRGSM1400) + #include +#endif /****************************************************************************** CLASS DECLARATION @@ -65,6 +66,4 @@ class GSMConnectionHandler : public ConnectionHandler GSMClient _gsm_client; }; -#endif /* #ifdef BOARD_HAS_GSM */ - #endif /* #ifndef GSM_CONNECTION_MANAGER_H_ */ diff --git a/src/Arduino_LoRaConnectionHandler.cpp b/src/Arduino_LoRaConnectionHandler.cpp index cf1deaf0..2f94910b 100644 --- a/src/Arduino_LoRaConnectionHandler.cpp +++ b/src/Arduino_LoRaConnectionHandler.cpp @@ -19,9 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_LoRaConnectionHandler.h" +#include "Arduino_ConnectionHandlerDefinitions.h" #if defined(BOARD_HAS_LORA) /* Only compile if the board has LoRa */ +#include "Arduino_LoRaConnectionHandler.h" /****************************************************************************** TYPEDEF diff --git a/src/Arduino_LoRaConnectionHandler.h b/src/Arduino_LoRaConnectionHandler.h index aa769ab5..fb0f560b 100644 --- a/src/Arduino_LoRaConnectionHandler.h +++ b/src/Arduino_LoRaConnectionHandler.h @@ -22,7 +22,11 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" +#include "Arduino_ConnectionHandlerInterface.h" + +#if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) + #include +#endif #ifdef BOARD_HAS_LORA /* Only compile if the board has LoRa */ diff --git a/src/Arduino_NBConnectionHandler.cpp b/src/Arduino_NBConnectionHandler.cpp index 344e104f..a06fb797 100644 --- a/src/Arduino_NBConnectionHandler.cpp +++ b/src/Arduino_NBConnectionHandler.cpp @@ -19,9 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_NBConnectionHandler.h" +#include "Arduino_ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_NB /* Only compile if this is a board with NB */ +#include "Arduino_NBConnectionHandler.h" /****************************************************************************** CONSTANTS diff --git a/src/Arduino_NBConnectionHandler.h b/src/Arduino_NBConnectionHandler.h index 53d2174e..0a7ec8ad 100644 --- a/src/Arduino_NBConnectionHandler.h +++ b/src/Arduino_NBConnectionHandler.h @@ -22,9 +22,11 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" +#include "Arduino_ConnectionHandlerInterface.h" -#ifdef BOARD_HAS_NB /* Only compile if this is a board with NB */ +#ifdef ARDUINO_SAMD_MKRNB1500 + #include +#endif /****************************************************************************** CLASS DECLARATION @@ -68,6 +70,4 @@ class NBConnectionHandler : public ConnectionHandler NBClient _nb_client; }; -#endif /* #ifdef BOARD_HAS_NB */ - #endif /* #ifndef NB_CONNECTION_MANAGER_H_ */ diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/Arduino_WiFiConnectionHandler.cpp index 902b53f0..34ed664d 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/Arduino_WiFiConnectionHandler.cpp @@ -19,9 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_WiFiConnectionHandler.h" +#include "Arduino_ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_WIFI /* Only compile if the board has WiFi */ +#include "Arduino_WiFiConnectionHandler.h" /****************************************************************************** CONSTANTS @@ -143,7 +144,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnected() Debug.print(DBG_INFO, F("Attempting reconnection")); #endif } - + return NetworkConnectionState::DISCONNECTED; } return NetworkConnectionState::CONNECTED; diff --git a/src/Arduino_WiFiConnectionHandler.h b/src/Arduino_WiFiConnectionHandler.h index bf16fa06..e7621e57 100644 --- a/src/Arduino_WiFiConnectionHandler.h +++ b/src/Arduino_WiFiConnectionHandler.h @@ -22,9 +22,31 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" - -#ifdef BOARD_HAS_WIFI /* Only compile if the board has WiFi */ +#include "Arduino_ConnectionHandlerInterface.h" + +#ifdef ARDUINO_SAMD_MKR1000 + #include + #include +#elif defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \ + defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined (ARDUINO_NANO_RP2040_CONNECT) + #include + #include +#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M7) || \ + defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_OPTA) || defined(ARDUINO_GIGA) + #include + #include +#elif defined(ARDUINO_PORTENTA_C33) + #include + #include +#elif defined(ARDUINO_ARCH_ESP8266) + #include + #include +#elif defined(ARDUINO_ARCH_ESP32) + #include + #include +#elif defined(ARDUINO_UNOR4_WIFI) + #include +#endif /****************************************************************************** CLASS DECLARATION @@ -59,6 +81,4 @@ class WiFiConnectionHandler : public ConnectionHandler WiFiClient _wifi_client; }; -#endif /* #ifdef BOARD_HAS_WIFI */ - #endif /* ARDUINO_WIFI_CONNECTION_HANDLER_H_ */ From 62ad2b83f77b0922e8d76ae9712f7eeb75b9a8ad Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Tue, 20 Aug 2024 11:57:43 +0200 Subject: [PATCH 150/203] renaming connection handler implmentation files --- src/Arduino_ConnectionHandler.h | 16 ++++++++-------- ...ionHandler.cpp => CatM1ConnectionHandler.cpp} | 4 ++-- ...nectionHandler.h => CatM1ConnectionHandler.h} | 2 +- ...Handler.cpp => CellularConnectionHandler.cpp} | 4 ++-- ...tionHandler.h => CellularConnectionHandler.h} | 0 ...initions.h => ConnectionHandlerDefinitions.h} | 0 ...erface.cpp => ConnectionHandlerInterface.cpp} | 2 +- ...rInterface.h => ConnectionHandlerInterface.h} | 2 +- ...Handler.cpp => EthernetConnectionHandler.cpp} | 4 ++-- ...tionHandler.h => EthernetConnectionHandler.h} | 2 +- ...ctionHandler.cpp => GSMConnectionHandler.cpp} | 4 ++-- ...onnectionHandler.h => GSMConnectionHandler.h} | 2 +- ...tionHandler.cpp => LoRaConnectionHandler.cpp} | 4 ++-- ...nnectionHandler.h => LoRaConnectionHandler.h} | 2 +- ...ectionHandler.cpp => NBConnectionHandler.cpp} | 4 ++-- ...ConnectionHandler.h => NBConnectionHandler.h} | 2 +- ...tionHandler.cpp => WiFiConnectionHandler.cpp} | 4 ++-- ...nnectionHandler.h => WiFiConnectionHandler.h} | 2 +- 18 files changed, 30 insertions(+), 30 deletions(-) rename src/{Arduino_CatM1ConnectionHandler.cpp => CatM1ConnectionHandler.cpp} (97%) rename src/{Arduino_CatM1ConnectionHandler.h => CatM1ConnectionHandler.h} (98%) rename src/{Arduino_CellularConnectionHandler.cpp => CellularConnectionHandler.cpp} (96%) rename src/{Arduino_CellularConnectionHandler.h => CellularConnectionHandler.h} (100%) rename src/{Arduino_ConnectionHandlerDefinitions.h => ConnectionHandlerDefinitions.h} (100%) rename src/{Arduino_ConnectionHandlerInterface.cpp => ConnectionHandlerInterface.cpp} (99%) rename src/{Arduino_ConnectionHandlerInterface.h => ConnectionHandlerInterface.h} (98%) rename src/{Arduino_EthernetConnectionHandler.cpp => EthernetConnectionHandler.cpp} (97%) rename src/{Arduino_EthernetConnectionHandler.h => EthernetConnectionHandler.h} (98%) rename src/{Arduino_GSMConnectionHandler.cpp => GSMConnectionHandler.cpp} (98%) rename src/{Arduino_GSMConnectionHandler.h => GSMConnectionHandler.h} (97%) rename src/{Arduino_LoRaConnectionHandler.cpp => LoRaConnectionHandler.cpp} (98%) rename src/{Arduino_LoRaConnectionHandler.h => LoRaConnectionHandler.h} (98%) rename src/{Arduino_NBConnectionHandler.cpp => NBConnectionHandler.cpp} (98%) rename src/{Arduino_NBConnectionHandler.h => NBConnectionHandler.h} (98%) rename src/{Arduino_WiFiConnectionHandler.cpp => WiFiConnectionHandler.cpp} (98%) rename src/{Arduino_WiFiConnectionHandler.h => WiFiConnectionHandler.h} (98%) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index ee79dc3a..bb4c0e64 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -27,34 +27,34 @@ #endif #include -#include "Arduino_ConnectionHandlerDefinitions.h" +#include "ConnectionHandlerDefinitions.h" #if defined(BOARD_HAS_WIFI) - #include "Arduino_WiFiConnectionHandler.h" + #include "WiFiConnectionHandler.h" #endif #if defined(BOARD_HAS_GSM) - #include "Arduino_GSMConnectionHandler.h" + #include "GSMConnectionHandler.h" #endif #if defined(BOARD_HAS_NB) - #include "Arduino_NBConnectionHandler.h" + #include "NBConnectionHandler.h" #endif #if defined(BOARD_HAS_LORA) - #include "Arduino_LoRaConnectionHandler.h" + #include "LoRaConnectionHandler.h" #endif #if defined(BOARD_HAS_ETHERNET) - #include "Arduino_EthernetConnectionHandler.h" + #include "EthernetConnectionHandler.h" #endif #if defined(BOARD_HAS_CATM1_NBIOT) - #include "Arduino_CatM1ConnectionHandler.h" + #include "CatM1ConnectionHandler.h" #endif #if defined(BOARD_HAS_CELLULAR) - #include "Arduino_CellularConnectionHandler.h" + #include "CellularConnectionHandler.h" #endif #endif /* CONNECTION_HANDLER_H_ */ diff --git a/src/Arduino_CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp similarity index 97% rename from src/Arduino_CatM1ConnectionHandler.cpp rename to src/CatM1ConnectionHandler.cpp index 46553730..0263a397 100644 --- a/src/Arduino_CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -19,10 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerDefinitions.h" +#include "ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_CATM1_NBIOT /* Only compile if the board has CatM1 BN-IoT */ -#include "Arduino_CatM1ConnectionHandler.h" +#include "CatM1ConnectionHandler.h" /****************************************************************************** CTOR/DTOR diff --git a/src/Arduino_CatM1ConnectionHandler.h b/src/CatM1ConnectionHandler.h similarity index 98% rename from src/Arduino_CatM1ConnectionHandler.h rename to src/CatM1ConnectionHandler.h index ec6b2633..987230f8 100644 --- a/src/Arduino_CatM1ConnectionHandler.h +++ b/src/CatM1ConnectionHandler.h @@ -22,7 +22,7 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerInterface.h" +#include "ConnectionHandlerInterface.h" #if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_EDGE_CONTROL) #include diff --git a/src/Arduino_CellularConnectionHandler.cpp b/src/CellularConnectionHandler.cpp similarity index 96% rename from src/Arduino_CellularConnectionHandler.cpp rename to src/CellularConnectionHandler.cpp index ff7111c7..2e4499a0 100644 --- a/src/Arduino_CellularConnectionHandler.cpp +++ b/src/CellularConnectionHandler.cpp @@ -13,10 +13,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerDefinitions.h" +#include "ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_CELLULAR /* Only compile if the board has Cellular */ -#include "Arduino_CellularConnectionHandler.h" +#include "CellularConnectionHandler.h" /****************************************************************************** CTOR/DTOR diff --git a/src/Arduino_CellularConnectionHandler.h b/src/CellularConnectionHandler.h similarity index 100% rename from src/Arduino_CellularConnectionHandler.h rename to src/CellularConnectionHandler.h diff --git a/src/Arduino_ConnectionHandlerDefinitions.h b/src/ConnectionHandlerDefinitions.h similarity index 100% rename from src/Arduino_ConnectionHandlerDefinitions.h rename to src/ConnectionHandlerDefinitions.h diff --git a/src/Arduino_ConnectionHandlerInterface.cpp b/src/ConnectionHandlerInterface.cpp similarity index 99% rename from src/Arduino_ConnectionHandlerInterface.cpp rename to src/ConnectionHandlerInterface.cpp index ccfc4df9..2fdc10e1 100644 --- a/src/Arduino_ConnectionHandlerInterface.cpp +++ b/src/ConnectionHandlerInterface.cpp @@ -19,7 +19,7 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerInterface.h" +#include "ConnectionHandlerInterface.h" /****************************************************************************** CONSTRUCTOR/DESTRUCTOR diff --git a/src/Arduino_ConnectionHandlerInterface.h b/src/ConnectionHandlerInterface.h similarity index 98% rename from src/Arduino_ConnectionHandlerInterface.h rename to src/ConnectionHandlerInterface.h index 52a09bd5..94768ea8 100644 --- a/src/Arduino_ConnectionHandlerInterface.h +++ b/src/ConnectionHandlerInterface.h @@ -28,7 +28,7 @@ #include #include #include -#include "Arduino_ConnectionHandlerDefinitions.h" +#include "ConnectionHandlerDefinitions.h" /****************************************************************************** TYPEDEFS diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/EthernetConnectionHandler.cpp similarity index 97% rename from src/Arduino_EthernetConnectionHandler.cpp rename to src/EthernetConnectionHandler.cpp index 52254501..14f7aee4 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/EthernetConnectionHandler.cpp @@ -16,10 +16,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerDefinitions.h" +#include "ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_ETHERNET /* Only compile if the board has ethernet */ -#include "Arduino_EthernetConnectionHandler.h" +#include "EthernetConnectionHandler.h" /****************************************************************************** CTOR/DTOR diff --git a/src/Arduino_EthernetConnectionHandler.h b/src/EthernetConnectionHandler.h similarity index 98% rename from src/Arduino_EthernetConnectionHandler.h rename to src/EthernetConnectionHandler.h index 29dde2fa..e6f08dd9 100644 --- a/src/Arduino_EthernetConnectionHandler.h +++ b/src/EthernetConnectionHandler.h @@ -19,7 +19,7 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerInterface.h" +#include "ConnectionHandlerInterface.h" #if defined(ARDUINO_PORTENTA_H7_M7) #include diff --git a/src/Arduino_GSMConnectionHandler.cpp b/src/GSMConnectionHandler.cpp similarity index 98% rename from src/Arduino_GSMConnectionHandler.cpp rename to src/GSMConnectionHandler.cpp index 684abdee..34bf1792 100644 --- a/src/Arduino_GSMConnectionHandler.cpp +++ b/src/GSMConnectionHandler.cpp @@ -19,10 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerDefinitions.h" +#include "ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_GSM /* Only compile if this is a board with GSM */ -#include "Arduino_GSMConnectionHandler.h" +#include "GSMConnectionHandler.h" /****************************************************************************** CONSTANTS diff --git a/src/Arduino_GSMConnectionHandler.h b/src/GSMConnectionHandler.h similarity index 97% rename from src/Arduino_GSMConnectionHandler.h rename to src/GSMConnectionHandler.h index c2d2b053..e524cda5 100644 --- a/src/Arduino_GSMConnectionHandler.h +++ b/src/GSMConnectionHandler.h @@ -22,7 +22,7 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerInterface.h" +#include "ConnectionHandlerInterface.h" #if defined(ARDUINO_SAMD_MKRGSM1400) #include diff --git a/src/Arduino_LoRaConnectionHandler.cpp b/src/LoRaConnectionHandler.cpp similarity index 98% rename from src/Arduino_LoRaConnectionHandler.cpp rename to src/LoRaConnectionHandler.cpp index 2f94910b..1f454a51 100644 --- a/src/Arduino_LoRaConnectionHandler.cpp +++ b/src/LoRaConnectionHandler.cpp @@ -19,10 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerDefinitions.h" +#include "ConnectionHandlerDefinitions.h" #if defined(BOARD_HAS_LORA) /* Only compile if the board has LoRa */ -#include "Arduino_LoRaConnectionHandler.h" +#include "LoRaConnectionHandler.h" /****************************************************************************** TYPEDEF diff --git a/src/Arduino_LoRaConnectionHandler.h b/src/LoRaConnectionHandler.h similarity index 98% rename from src/Arduino_LoRaConnectionHandler.h rename to src/LoRaConnectionHandler.h index fb0f560b..828fec2c 100644 --- a/src/Arduino_LoRaConnectionHandler.h +++ b/src/LoRaConnectionHandler.h @@ -22,7 +22,7 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerInterface.h" +#include "ConnectionHandlerInterface.h" #if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) #include diff --git a/src/Arduino_NBConnectionHandler.cpp b/src/NBConnectionHandler.cpp similarity index 98% rename from src/Arduino_NBConnectionHandler.cpp rename to src/NBConnectionHandler.cpp index a06fb797..eb72f3e7 100644 --- a/src/Arduino_NBConnectionHandler.cpp +++ b/src/NBConnectionHandler.cpp @@ -19,10 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerDefinitions.h" +#include "ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_NB /* Only compile if this is a board with NB */ -#include "Arduino_NBConnectionHandler.h" +#include "NBConnectionHandler.h" /****************************************************************************** CONSTANTS diff --git a/src/Arduino_NBConnectionHandler.h b/src/NBConnectionHandler.h similarity index 98% rename from src/Arduino_NBConnectionHandler.h rename to src/NBConnectionHandler.h index 0a7ec8ad..ddda333b 100644 --- a/src/Arduino_NBConnectionHandler.h +++ b/src/NBConnectionHandler.h @@ -22,7 +22,7 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerInterface.h" +#include "ConnectionHandlerInterface.h" #ifdef ARDUINO_SAMD_MKRNB1500 #include diff --git a/src/Arduino_WiFiConnectionHandler.cpp b/src/WiFiConnectionHandler.cpp similarity index 98% rename from src/Arduino_WiFiConnectionHandler.cpp rename to src/WiFiConnectionHandler.cpp index 34ed664d..0cd2e126 100644 --- a/src/Arduino_WiFiConnectionHandler.cpp +++ b/src/WiFiConnectionHandler.cpp @@ -19,10 +19,10 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerDefinitions.h" +#include "ConnectionHandlerDefinitions.h" #ifdef BOARD_HAS_WIFI /* Only compile if the board has WiFi */ -#include "Arduino_WiFiConnectionHandler.h" +#include "WiFiConnectionHandler.h" /****************************************************************************** CONSTANTS diff --git a/src/Arduino_WiFiConnectionHandler.h b/src/WiFiConnectionHandler.h similarity index 98% rename from src/Arduino_WiFiConnectionHandler.h rename to src/WiFiConnectionHandler.h index e7621e57..88a1e460 100644 --- a/src/Arduino_WiFiConnectionHandler.h +++ b/src/WiFiConnectionHandler.h @@ -22,7 +22,7 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandlerInterface.h" +#include "ConnectionHandlerInterface.h" #ifdef ARDUINO_SAMD_MKR1000 #include From bc9691b38519ec1031109958442944d773e3cd04 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Tue, 20 Aug 2024 14:32:38 +0200 Subject: [PATCH 151/203] added error when compiling unsupported connection handler --- src/CatM1ConnectionHandler.h | 4 ++++ src/CellularConnectionHandler.h | 4 ++++ src/EthernetConnectionHandler.h | 4 ++++ src/GSMConnectionHandler.h | 4 ++++ src/LoRaConnectionHandler.h | 7 ++++--- src/NBConnectionHandler.h | 4 ++++ src/WiFiConnectionHandler.h | 4 ++++ 7 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/CatM1ConnectionHandler.h b/src/CatM1ConnectionHandler.h index 987230f8..33ac9fea 100644 --- a/src/CatM1ConnectionHandler.h +++ b/src/CatM1ConnectionHandler.h @@ -28,6 +28,10 @@ #include #endif +#ifndef BOARD_HAS_CATM1_NBIOT + #error "Board doesn't support CATM1_NBIOT" +#endif + /****************************************************************************** CLASS DECLARATION ******************************************************************************/ diff --git a/src/CellularConnectionHandler.h b/src/CellularConnectionHandler.h index 8515fa99..048c9f74 100644 --- a/src/CellularConnectionHandler.h +++ b/src/CellularConnectionHandler.h @@ -27,6 +27,10 @@ #include #endif +#ifndef BOARD_HAS_CELLULAR + #error "Board doesn't support CELLULAR" +#endif + class CellularConnectionHandler : public ConnectionHandler { public: diff --git a/src/EthernetConnectionHandler.h b/src/EthernetConnectionHandler.h index e6f08dd9..35a02cd9 100644 --- a/src/EthernetConnectionHandler.h +++ b/src/EthernetConnectionHandler.h @@ -32,6 +32,10 @@ #include #endif +#ifndef BOARD_HAS_ETHERNET + #error "Board doesn't support ETHERNET" +#endif + /****************************************************************************** CLASS DECLARATION ******************************************************************************/ diff --git a/src/GSMConnectionHandler.h b/src/GSMConnectionHandler.h index e524cda5..1f3db49a 100644 --- a/src/GSMConnectionHandler.h +++ b/src/GSMConnectionHandler.h @@ -28,6 +28,10 @@ #include #endif +#ifndef BOARD_HAS_GSM + #error "Board doesn't support GSM" +#endif + /****************************************************************************** CLASS DECLARATION ******************************************************************************/ diff --git a/src/LoRaConnectionHandler.h b/src/LoRaConnectionHandler.h index 828fec2c..3ddcca24 100644 --- a/src/LoRaConnectionHandler.h +++ b/src/LoRaConnectionHandler.h @@ -28,7 +28,10 @@ #include #endif -#ifdef BOARD_HAS_LORA /* Only compile if the board has LoRa */ +#ifndef BOARD_HAS_LORA + #error "Board doesn't support LORA" +#endif + /****************************************************************************** CLASS DECLARATION @@ -78,6 +81,4 @@ class LoRaConnectionHandler : public ConnectionHandler LoRaModem _modem; }; -#endif /* #ifdef BOARD_HAS_LORA */ - #endif /* ARDUINO_LORA_CONNECTION_HANDLER_H_ */ diff --git a/src/NBConnectionHandler.h b/src/NBConnectionHandler.h index ddda333b..fd2afb6c 100644 --- a/src/NBConnectionHandler.h +++ b/src/NBConnectionHandler.h @@ -28,6 +28,10 @@ #include #endif +#ifndef BOARD_HAS_NB + #error "Board doesn't support NB" +#endif + /****************************************************************************** CLASS DECLARATION ******************************************************************************/ diff --git a/src/WiFiConnectionHandler.h b/src/WiFiConnectionHandler.h index 88a1e460..e5e2e25d 100644 --- a/src/WiFiConnectionHandler.h +++ b/src/WiFiConnectionHandler.h @@ -48,6 +48,10 @@ #include #endif +#ifndef BOARD_HAS_WIFI + #error "Board doesn't support WIFI" +#endif + /****************************************************************************** CLASS DECLARATION ******************************************************************************/ From bf6b62e76010c69f892100c94abd33b80c2e828e Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 20 Aug 2024 17:43:36 +0200 Subject: [PATCH 152/203] CellularConnectionHandler: align includes --- src/CellularConnectionHandler.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/CellularConnectionHandler.h b/src/CellularConnectionHandler.h index 048c9f74..2addd29b 100644 --- a/src/CellularConnectionHandler.h +++ b/src/CellularConnectionHandler.h @@ -16,12 +16,7 @@ INCLUDE ******************************************************************************/ -#include "Arduino_ConnectionHandler.h" - - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ +#include "ConnectionHandlerInterface.h" #if defined(ARDUINO_PORTENTA_C33) || defined(ARDUINO_PORTENTA_H7_M7) #include @@ -31,6 +26,10 @@ #error "Board doesn't support CELLULAR" #endif +/****************************************************************************** + CLASS DECLARATION + ******************************************************************************/ + class CellularConnectionHandler : public ConnectionHandler { public: From 4f50b120d6f8454c01e9b9f5127a69ed4b80d991 Mon Sep 17 00:00:00 2001 From: "Zachary J. Fields" Date: Thu, 22 Aug 2024 20:40:33 -0500 Subject: [PATCH 153/203] chore: Broaden API usage in example sketch --- .../ConnectionHandlerDemo.ino | 81 ++++++++++++++++--- .../ConnectionHandlerDemo/arduino_secrets.h | 12 +-- 2 files changed, 77 insertions(+), 16 deletions(-) diff --git a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino index 13ad117c..46a0c9d4 100644 --- a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino +++ b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino @@ -1,10 +1,11 @@ -/* SECRET_ fields are in arduino_secrets.h included above - * if using a WiFi board (Arduino MKR1000, MKR WiFi 1010, Nano 33 IoT, UNO +/* SECRET_ fields are in `arduino_secrets.h` (included below) + * + * If using a WiFi board (Arduino MKR1000, MKR WiFi 1010, Nano 33 IoT, UNO * WiFi Rev 2 or ESP8266/32), create a WiFiConnectionHandler object by adding - * Network Name (SECRET_SSID) and password (SECRET_PASS) in the arduino_secrets.h - * file (or Secrets tab in Create Web Editor). + * Network Name (SECRET_WIFI_SSID) and password (SECRET_WIFI_PASS) in the + * arduino_secrets.h file (or Secrets tab in Create Web Editor). * - * WiFiConnectionHandler conMan(SECRET_SSID, SECRET_PASS); + * WiFiConnectionHandler conMan(SECRET_WIFI_SSID, SECRET_WIFI_PASS); * * If using a MKR GSM 1400 or other GSM boards supporting the same API you'll * need a GSMConnectionHandler object as follows @@ -27,14 +28,21 @@ * */ +#include + #include "arduino_secrets.h" -#include +#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)) + #error "Please check Arduino Connection Handler supported boards list: https://github.com/arduino-libraries/Arduino_ConnectionHandler/blob/master/README.md" +#endif #if defined(BOARD_HAS_ETHERNET) EthernetConnectionHandler conMan(SECRET_IP, SECRET_DNS, SECRET_GATEWAY, SECRET_NETMASK); #elif defined(BOARD_HAS_WIFI) -WiFiConnectionHandler conMan(SECRET_SSID, SECRET_PASS); +WiFiConnectionHandler conMan(SECRET_WIFI_SSID, SECRET_WIFI_PASS); #elif defined(BOARD_HAS_GSM) GSMConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); #elif defined(BOARD_HAS_NB) @@ -47,19 +55,73 @@ CatM1ConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GS CellularConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); #endif +bool attemptConnect = false; +uint32_t lastConnToggleMs = 0; + void setup() { + /* Initialize serial debug port and wait up to 5 seconds for port to open */ Serial.begin(9600); - /* Give a few seconds for the Serial connection to be available */ - delay(4000); + for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { } + #ifndef __AVR__ + /* Set the debug message level: + * - DBG_ERROR: Only show error messages + * - DBG_WARNING: Show warning and error messages + * - DBG_INFO: Show info, warning, and error messages + * - DBG_DEBUG: Show debug, info, warning, and error messages + * - DBG_VERBOSE: Show all messages + */ setDebugMessageLevel(DBG_INFO); #endif + + /* Add callbacks to the ConnectionHandler object to get notified of network + * connection events. */ conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect); conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect); conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError); + + Serial.print("Network Adapter Interface: "); + switch (conMan.getInterface()) { + case NetworkAdapter::WIFI: + Serial.println("Wi-Fi"); + break; + case NetworkAdapter::ETHERNET: + Serial.println("Ethernet"); + break; + case NetworkAdapter::NB: + Serial.println("Narrowband"); + break; + case NetworkAdapter::GSM: + Serial.println("GSM"); + break; + case NetworkAdapter::LORA: + Serial.println("LoRa"); + break; + case NetworkAdapter::CATM1: + Serial.println("Category M1"); + break; + case NetworkAdapter::CELL: + Serial.println("Cellular"); + break; + default: + Serial.println("Unknown"); + break; + } } void loop() { + /* Toggle the connection every `CONN_TOGGLE_MS` milliseconds */ + if ((millis() - lastConnToggleMs) > CONN_TOGGLE_MS) { + Serial.println("Toggling connection..."); + if (attemptConnect) { + conMan.connect(); + } else { + conMan.disconnect(); + } + attemptConnect = !attemptConnect; + lastConnToggleMs = millis(); + } + /* The following code keeps on running connection workflows on our * ConnectionHandler object, hence allowing reconnection in case of failure * and notification of connect/disconnect event if enabled (see @@ -68,7 +130,6 @@ void loop() { * which might not guarantee the correct functioning of the ConnectionHandler * object. */ - conMan.check(); } diff --git a/examples/ConnectionHandlerDemo/arduino_secrets.h b/examples/ConnectionHandlerDemo/arduino_secrets.h index 4d9fb7c8..f9906f69 100644 --- a/examples/ConnectionHandlerDemo/arduino_secrets.h +++ b/examples/ConnectionHandlerDemo/arduino_secrets.h @@ -1,12 +1,12 @@ // Required for WiFiConnectionHandler -const char SECRET_SSID[] = "NETWORK NAME"; -const char SECRET_PASS[] = "NETWORK PASSWORD"; +const char SECRET_WIFI_SSID[] = "NETWORK NAME"; +const char SECRET_WIFI_PASS[] = "NETWORK PASSWORD"; // Required for GSMConnectionHandler -const char SECRET_APN[] = "MOBILE PROVIDER APN ADDRESS"; -const char SECRET_PIN[] = "0000"; // Required for NBConnectionHandler -const char SECRET_GSM_USER[] = "GSM USERNAME"; -const char SECRET_GSM_PASS[] = "GSM PASSWORD"; +const char SECRET_APN[] = "MOBILE PROVIDER APN ADDRESS"; +const char SECRET_PIN[] = "0000"; // Required for NBConnectionHandler +const char SECRET_GSM_USER[] = "GSM USERNAME"; +const char SECRET_GSM_PASS[] = "GSM PASSWORD"; // Required for LoRaConnectionHandler const char SECRET_APP_EUI[] = "APP_EUI"; From df5c8271b34cd0ab22f6c457c5fc3bcad4ba85ce Mon Sep 17 00:00:00 2001 From: "Zachary J. Fields" Date: Thu, 22 Aug 2024 20:44:43 -0500 Subject: [PATCH 154/203] feat: NotecardConnectionHandler --- .github/workflows/compile-examples.yml | 42 + README.md | 8 +- .../ConnectionHandlerDemo-Notecard.ino | 144 +++ .../ConnectionHandlerDemo-Notecard/README.md | 71 ++ .../arduino_secrets.h | 5 + keywords.txt | 10 +- library.properties | 6 +- src/Arduino_ConnectionHandler.h | 6 + src/ConnectionHandlerDefinitions.h | 15 +- src/ConnectionHandlerInterface.h | 14 +- src/NotecardConnectionHandler.cpp | 828 ++++++++++++++++++ src/NotecardConnectionHandler.h | 341 ++++++++ 12 files changed, 1475 insertions(+), 15 deletions(-) create mode 100644 examples/ConnectionHandlerDemo-Notecard/ConnectionHandlerDemo-Notecard.ino create mode 100644 examples/ConnectionHandlerDemo-Notecard/README.md create mode 100644 examples/ConnectionHandlerDemo-Notecard/arduino_secrets.h create mode 100644 src/NotecardConnectionHandler.cpp create mode 100644 src/NotecardConnectionHandler.h diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 878d5669..c0c5b9a9 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -35,6 +35,9 @@ jobs: - name: MKRNB - name: MKRWAN - name: Arduino_Cellular + - name: Blues Wireless Notecard + SKETCH_PATHS: | + - examples/ConnectionHandlerDemo ARDUINOCORE_MBED_STAGING_PATH: extras/ArduinoCore-mbed ARDUINOCORE_API_STAGING_PATH: extras/ArduinoCore-API SKETCHES_REPORTS_PATH: sketches-reports @@ -106,6 +109,8 @@ jobs: platforms: | # Install Arduino SAMD Boards via Boards Manager - name: arduino:samd + sketch-paths: | + - examples/ConnectionHandlerDemo-Notecard - board: platform-name: arduino:mbed platforms: | @@ -114,21 +119,53 @@ jobs: # Overwrite the Arduino mbed-Enabled Boards release version with version from the tip of the default branch (located in local path because of the need to first install ArduinoCore-API) - source-path: extras/ArduinoCore-mbed name: arduino:mbed + sketch-paths: | + - examples/ConnectionHandlerDemo-Notecard + - board: + platform-name: arduino:mbed_portenta + sketch-paths: | + - examples/ConnectionHandlerDemo-Notecard + - board: + platform-name: arduino:mbed_nano + sketch-paths: | + - examples/ConnectionHandlerDemo-Notecard + - board: + platform-name: arduino:mbed_nicla + sketch-paths: | + - examples/ConnectionHandlerDemo-Notecard + - board: + platform-name: arduino:mbed_opta + sketch-paths: | + - examples/ConnectionHandlerDemo-Notecard + - board: + platform-name: arduino:mbed_giga + sketch-paths: | + - examples/ConnectionHandlerDemo-Notecard + - board: + platform-name: arduino:mbed_edge + sketch-paths: | + - examples/ConnectionHandlerDemo-Notecard - board: platform-name: arduino:renesas_portenta platforms: | # Install Arduino Renesas portenta Boards via Boards Manager - name: arduino:renesas_portenta + sketch-paths: | + - examples/ConnectionHandlerDemo-Notecard - board: platform-name: arduino:renesas_uno platforms: | # Install Arduino Renesas uno Boards via Boards Manager - name: arduino:renesas_uno + sketch-paths: | + - examples/ConnectionHandlerDemo-Notecard - board: platform-name: arduino:esp32 platforms: | # Install Arduino ESP32 Boards via Boards Manager - name: arduino:esp32 + sketch-paths: | + - examples/ConnectionHandlerDemo-Notecard - board: platform-name: esp8266:esp8266 platforms: | @@ -142,6 +179,8 @@ jobs: # Install ESP32 platform via Boards Manager - name: esp32:esp32 source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json + sketch-paths: | + - examples/ConnectionHandlerDemo-Notecard steps: - uses: actions/checkout@v4 @@ -180,6 +219,9 @@ jobs: platforms: ${{ matrix.platforms }} fqbn: ${{ matrix.board.fqbn }} libraries: ${{ env.LIBRARIES }} + sketch-paths: | + ${{ env.SKETCH_PATHS }} + ${{ matrix.sketch-paths }} enable-deltas-report: 'true' sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/README.md b/README.md index c2759ac3..139db7f9 100644 --- a/README.md +++ b/README.md @@ -6,21 +6,25 @@ Arduino Library for network connections management [![Spell Check status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml) Library for handling and managing network connections by providing keep-alive functionality and automatic reconnection in case of connection-loss. It supports the following boards: + * **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/products/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`GIGA R1 WiFi`](https://store.arduino.cc/products/giga-r1-wifi), [`Portenta C33`](https://store.arduino.cc/products/portenta-c33), [`UNO R4 WiFi`](https://store.arduino.cc/products/uno-r4-wifi), [`Nano ESP32`](https://store.arduino.cc/products/nano-esp32), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32) * **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415) * **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413) * **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) * **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Breakout`](https://store.arduino.cc/products/arduino-portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/products/arduino-portenta-machine-control), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`OPTA RS485`](https://store.arduino.cc/products/opta-rs485), [`OPTA Lite`](https://store.arduino.cc/products/opta-lite), [`Portenta C33`](https://store.arduino.cc/products/portenta-c33) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet) +* **Notecard**: [Provides Cellular/LoRa/Satellite/Wi-Fi to any modern board/architecture](examples/ConnectionHandlerDemo-Notecard/README.md) ### How-to-use ```C++ #include /* ... */ -#if defined(BOARD_HAS_ETHERNET) +#if defined(BOARD_HAS_NOTECARD) +NotecardConnectionHandler conMan("com.domain.you:product"); +#elif defined(BOARD_HAS_ETHERNET) EthernetConnectionHandler conMan; #elif defined(BOARD_HAS_WIFI) -WiFiConnectionHandler conMan("SECRET_SSID", "SECRET_PASS"); +WiFiConnectionHandler conMan("SECRET_WIFI_SSID", "SECRET_WIFI_PASS"); #elif defined(BOARD_HAS_GSM) GSMConnectionHandler conMan("SECRET_PIN", "SECRET_APN", "SECRET_GSM_LOGIN", "SECRET_GSM_PASS"); #elif defined(BOARD_HAS_NB) diff --git a/examples/ConnectionHandlerDemo-Notecard/ConnectionHandlerDemo-Notecard.ino b/examples/ConnectionHandlerDemo-Notecard/ConnectionHandlerDemo-Notecard.ino new file mode 100644 index 00000000..e4183618 --- /dev/null +++ b/examples/ConnectionHandlerDemo-Notecard/ConnectionHandlerDemo-Notecard.ino @@ -0,0 +1,144 @@ +/* SECRET_ fields are in `arduino_secrets.h` (included below) + * + * If using a Host + Notecard connected over I2C you'll need a + * NotecardConnectionHandler object as follows: + * + * NotecardConnectionHandler conMan(NOTECARD_PRODUCT_UID); + * + * If using a Host + Notecard connected over Serial you'll need a + * NotecardConnectionHandler object as follows: + * + * NotecardConnectionHandler conMan(NOTECARD_PRODUCT_UID, UART_INTERFACE); + */ + +#include // MUST include this first to enable Notecard support +#include + +#include "arduino_secrets.h" + +/* Uncomment the following line to use this example in a manner that is more + * compatible with LoRa. + */ +// #define USE_NOTE_LORA + +#ifndef USE_NOTE_LORA +#define CONN_TOGGLE_MS 60000 +#else +#define CONN_TOGGLE_MS 300000 +#endif + +/* The Notecard can provide connectivity to almost any board via ESLOV (I2C) + * or UART. An empty string (or the default value provided below) will not + * override the Notecard's existing configuration. + * Learn more at: https://dev.blues.io */ +#define NOTECARD_PRODUCT_UID "com.domain.you:product" + +/* Uncomment the following line to use the Notecard over UART */ +// #define UART_INTERFACE Serial1 + +#ifndef UART_INTERFACE +NotecardConnectionHandler conMan(NOTECARD_PRODUCT_UID); +#else +NotecardConnectionHandler conMan(NOTECARD_PRODUCT_UID, UART_INTERFACE); +#endif + +bool attemptConnect = false; +uint32_t lastConnToggleMs = 0; + +void setup() { + /* Initialize serial debug port and wait up to 5 seconds for port to open */ + Serial.begin(9600); + for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { } + + /* Set the debug message level: + * - DBG_ERROR: Only show error messages + * - DBG_WARNING: Show warning and error messages + * - DBG_INFO: Show info, warning, and error messages + * - DBG_DEBUG: Show debug, info, warning, and error messages + * - DBG_VERBOSE: Show all messages + */ + setDebugMessageLevel(DBG_INFO); + + /* Add callbacks to the ConnectionHandler object to get notified of network + * connection events. */ + conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect); + conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect); + conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError); + + /* First call to `check()` initializes the connection to the Notecard. While + * not strictly necessary, it cleans up the logging from this application. + */ + conMan.check(); + +#ifndef USE_NOTE_LORA + /* Set the Wi-Fi credentials for the Notecard */ + String ssid = SECRET_WIFI_SSID; + if (ssid.length() > 0 && ssid != "NETWORK NAME") { + conMan.setWiFiCredentials(SECRET_WIFI_SSID, SECRET_WIFI_PASS); + } +#else + conMan.setNotehubPollingInterval(720); // poll twice per day +#endif + + /* Confirm Interface */ + Serial.print("Network Adapter Interface: "); + if (NetworkAdapter::NOTECARD == conMan.getInterface()) { + Serial.print("Notecard "); + Serial.print(conMan.getNotecardUid()); +#ifndef UART_INTERFACE + Serial.println(" (via I2C)"); +#else + Serial.println(" (via UART)"); +#endif + } else { + Serial.println("ERROR: Unexpected Interface"); + while(1); + } + + /* Display the Arduino IoT Cloud Device ID */ + displayCachedDeviceId(); +} + +void loop() { + /* Toggle the connection every `CONN_TOGGLE_MS` milliseconds */ + if ((millis() - lastConnToggleMs) > CONN_TOGGLE_MS) { + Serial.println("Toggling connection..."); + if (attemptConnect) { + displayCachedDeviceId(); + conMan.connect(); + } else { + // Flush any queued Notecard requests before disconnecting + conMan.initiateNotehubSync(NotecardConnectionHandler::SyncType::Outbound); + conMan.disconnect(); + } + attemptConnect = !attemptConnect; + lastConnToggleMs = millis(); + } + + /* The following code keeps on running connection workflows on our + * ConnectionHandler object, hence allowing reconnection in case of failure + * and notification of connect/disconnect event if enabled (see + * addConnectCallback/addDisconnectCallback) NOTE: any use of delay() within + * the loop or methods called from it will delay the execution of .update(), + * which might not guarantee the correct functioning of the ConnectionHandler + * object. + */ + conMan.check(); +} + +void displayCachedDeviceId() { + Serial.print("Cached Arduino IoT Cloud Device ID: "); + Serial.println(conMan.getDeviceId()); +} + +void onNetworkConnect() { + Serial.println(">>>> CONNECTED to network"); +} + +void onNetworkDisconnect() { + Serial.println(">>>> DISCONNECTED from network"); +} + +void onNetworkError() { + Serial.println(">>>> ERROR"); +} diff --git a/examples/ConnectionHandlerDemo-Notecard/README.md b/examples/ConnectionHandlerDemo-Notecard/README.md new file mode 100644 index 00000000..7f90a7cf --- /dev/null +++ b/examples/ConnectionHandlerDemo-Notecard/README.md @@ -0,0 +1,71 @@ +Notecard Connectivity +===================== + +The Notecard is a wireless, secure abstraction for device connectivity, that can +be used to enable _ANY*_ device with I2C, or UART, to connect to the Arduino IoT +Cloud via cellular, LoRa, satellite or Wi-Fi! + +As a result, your existing device architecture can now have first class support +in the Arduino IoT Cloud, by using a Notecard as a secure communication channel. + +> \*_While any device with I2C/UART may use the Notecard, the Arduino IoT Cloud +> library is not supported by the AVR toolchain. Therefore, devices based on the +> AVR architecture cannot access the Arduino IoT Cloud via the Notecard._ +> +> _However, any device (including AVR), may use the Notecard library to send data +> to Notehub, then that data may be routed to any endpoint of your choosing. See the +> [Notecard Routing Guide](https://dev.blues.io/guides-and-tutorials/routing-data-to-cloud) +> for more information..._ + +Wireless Connectivity Options +----------------------------- + +- [Cellular](https://shop.blues.com/collections/notecard/products/notecard-cellular) +- [Cellular + Wi-Fi](https://shop.blues.com/collections/notecard/products/notecard-cell-wifi) +- [Wi-Fi](https://shop.blues.com/collections/notecard/products/wifi-notecard) +- [LoRa](https://shop.blues.com/collections/notecard/products/notecard-lora) +- [Satellite](https://shop.blues.com/products/starnote) + +How it Works +------------ + +**Architecture Diagram:** + +``` +-------- ------------ ----------- ----------- +| | | | | | | | +| Host | | | Secure | | | Arduino | +| MCU |------| Notecard | ( ( Wireless ) ) | Notehub |------| IoT | +| | | | Protocol | | | Cloud | +|______| |__________| |_________| |_________| +``` + +Getting Started +--------------- + +### Setup a Notehub Account + +Using the Notecard only requires a couple of easy steps: + +1. [Purchase a Notecard](https://shop.blues.com/collections/notecard) (and +[Notecarrier](https://shop.blues.com/collections/notecarrier)) that fits the +needs of your device. + > _**NOTE:** We recommend starting with our [Dev Kit](https://shop.blues.com/products/blues-global-starter-kit) + > if you are unsure._ +1. [Setup a Notehub account](https://dev.blues.io/quickstart/notecard-quickstart/notecard-and-notecarrier-f/#set-up-notehub). + > _**NOTE:** Notehub accounts are free (no credit card required)._ +1. [Create a project on your Notehub account](https://dev.blues.io/quickstart/notecard-quickstart/notecard-and-notecarrier-f/#create-a-notehub-project). +1. In `ConnectionHandlerDemo-Notecard`, replace "com.domain.you:product" (from +`NOTECARD_PRODUCT_UID`) with the ProductUID of your new Notehub project. + +### Power-up the Device + +1. [Connect the Notecard to your Host MCU](https://dev.blues.io/quickstart/notecard-quickstart/notecard-and-notecarrier-f/#connect-your-notecard-and-notecarrier) +1. Flash the `ConnectionHanderDemo-Notecard` example sketch to your device. You +should see the device reporting itself as online in your [Notehub Project](https://notehub.io). + +### More Information + +For more information about the Notecard and Notehub in general, please see our +[Quickstart Guide](https://dev.blues.io/quickstart/) for a general overview of +how the Notecard and Notehub are designed to work. diff --git a/examples/ConnectionHandlerDemo-Notecard/arduino_secrets.h b/examples/ConnectionHandlerDemo-Notecard/arduino_secrets.h new file mode 100644 index 00000000..bd2a9d58 --- /dev/null +++ b/examples/ConnectionHandlerDemo-Notecard/arduino_secrets.h @@ -0,0 +1,5 @@ +/* If provided, the Wi-Fi Credentials will be passed along to the Notecard. If + * the Notecard supports Wi-Fi, it will attempt to connect to the network using + * these credentials, if not, the Notecard will safely ignore these values. */ +const char SECRET_WIFI_SSID[] = "NETWORK NAME"; +const char SECRET_WIFI_PASS[] = "NETWORK PASSWORD"; diff --git a/keywords.txt b/keywords.txt index ef5227f0..68e2be2d 100644 --- a/keywords.txt +++ b/keywords.txt @@ -11,13 +11,17 @@ GSMConnectionHandler KEYWORD1 NBConnectionHandler KEYWORD1 LoRaConnectionHandler KEYWORD1 EthernetConnectionHandler KEYWORD1 -CatM1ConnectionHandler KEYWORD1 +CatM1ConnectionHandler KEYWORD1 +NotecardConnectionHandler KEYWORD1 #################################################### # Methods and Functions (KEYWORD2) #################################################### ConnectionHandler KEYWORD2 +available KEYWORD2 +read KEYWORD2 +write KEYWORD2 check KEYWORD2 connect KEYWORD2 disconnect KEYWORD2 @@ -26,6 +30,10 @@ getTime KEYWORD2 getClient KEYWORD2 getUDP KEYWORD2 +# NotecardConnectionHandler.h +initiateNotehubSync KEYWORD2 +setWiFiCredentials KEYWORD2 + #################################################### # Constants (LITERAL1) #################################################### diff --git a/library.properties b/library.properties index 16239e46..c2ebe2a0 100644 --- a/library.properties +++ b/library.properties @@ -2,9 +2,9 @@ name=Arduino_ConnectionHandler version=0.9.0 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino -sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) +sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet], Notecard) 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 -depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN +architectures=samd,esp32,esp8266,mbed,megaavr,mbed_nano,mbed_portenta,mbed_nicla,mbed_opta,mbed_giga,renesas_portenta,renesas_uno,mbed_edge,stm32 +depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN, Blues Wireless Notecard (>=1.6.3) diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index bb4c0e64..48327268 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -29,6 +29,10 @@ #include #include "ConnectionHandlerDefinitions.h" +#if defined(BOARD_HAS_NOTECARD) + #include "NotecardConnectionHandler.h" +#else + #if defined(BOARD_HAS_WIFI) #include "WiFiConnectionHandler.h" #endif @@ -57,4 +61,6 @@ #include "CellularConnectionHandler.h" #endif +#endif // BOARD_HAS_NOTECARD + #endif /* CONNECTION_HANDLER_H_ */ diff --git a/src/ConnectionHandlerDefinitions.h b/src/ConnectionHandlerDefinitions.h index 3fdde169..96bcd654 100644 --- a/src/ConnectionHandlerDefinitions.h +++ b/src/ConnectionHandlerDefinitions.h @@ -21,8 +21,16 @@ INCLUDES ******************************************************************************/ +#if defined __has_include + #if __has_include () + #define BOARD_HAS_NOTECARD + #endif +#endif + #include +#ifndef BOARD_HAS_NOTECARD + #ifdef ARDUINO_SAMD_MKR1000 #define BOARD_HAS_WIFI #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD @@ -136,6 +144,8 @@ #define NETWORK_HARDWARE_ERROR #endif +#endif // BOARD_HAS_NOTECARD + /****************************************************************************** TYPEDEFS ******************************************************************************/ @@ -163,7 +173,8 @@ enum class NetworkAdapter { GSM, LORA, CATM1, - CELL + CELL, + NOTECARD }; /****************************************************************************** @@ -173,7 +184,7 @@ enum class NetworkAdapter { static unsigned int const CHECK_INTERVAL_TABLE[] = { /* INIT */ 100, -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) +#if defined(BOARD_HAS_NOTECARD) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) /* CONNECTING */ 4000, #else /* CONNECTING */ 500, diff --git a/src/ConnectionHandlerInterface.h b/src/ConnectionHandlerInterface.h index 94768ea8..228827e7 100644 --- a/src/ConnectionHandlerInterface.h +++ b/src/ConnectionHandlerInterface.h @@ -48,16 +48,17 @@ class ConnectionHandler { NetworkConnectionState check(); - #if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT) + #if not defined(BOARD_HAS_LORA) virtual unsigned long getTime() = 0; - virtual Client &getClient() = 0; - virtual UDP &getUDP() = 0; #endif - #if defined(BOARD_HAS_LORA) - virtual int write(const uint8_t *buf, size_t size) = 0; - virtual int read() = 0; + #if defined(BOARD_HAS_NOTECARD) || defined(BOARD_HAS_LORA) virtual bool available() = 0; + virtual int read() = 0; + virtual int write(const uint8_t *buf, size_t size) = 0; + #else + virtual Client &getClient() = 0; + virtual UDP &getUDP() = 0; #endif NetworkConnectionState getStatus() __attribute__((deprecated)) { @@ -87,7 +88,6 @@ class ConnectionHandler { virtual NetworkConnectionState update_handleDisconnecting() = 0; virtual NetworkConnectionState update_handleDisconnected () = 0; - private: unsigned long _lastConnectionTickTime; diff --git a/src/NotecardConnectionHandler.cpp b/src/NotecardConnectionHandler.cpp new file mode 100644 index 00000000..5205c4a8 --- /dev/null +++ b/src/NotecardConnectionHandler.cpp @@ -0,0 +1,828 @@ +/* + This file is part of the ArduinoIoTCloud library. + + Copyright 2024 Blues (http://www.blues.com/) + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +/****************************************************************************** + INCLUDE + ******************************************************************************/ + +#include "ConnectionHandlerDefinitions.h" + +#if defined(BOARD_HAS_NOTECARD) // Only compile if the Notecard is present + +#include "NotecardConnectionHandler.h" + +#include +#include +#include + +/****************************************************************************** + DEFINES + ******************************************************************************/ + +#define NO_INBOUND_POLLING -1 + +#define NOTEFILE_BASE_NAME "arduino_iot_cloud" + +// Notecard LoRa requires us to choose an arbitrary port between 1-99 +#define NOTEFILE_DATABASE_LORA_PORT 1 +#define NOTEFILE_INBOUND_LORA_PORT 2 +#define NOTEFILE_OUTBOUND_LORA_PORT 3 + +// Note that we use "s" versions of the Notefile extensions to ensure that +// traffic always happens on a secure transport +#define NOTEFILE_SECURE_DATABASE NOTEFILE_BASE_NAME ".dbs" +#define NOTEFILE_SECURE_INBOUND NOTEFILE_BASE_NAME ".qis" +#define NOTEFILE_SECURE_OUTBOUND NOTEFILE_BASE_NAME ".qos" + +/****************************************************************************** + STLINK DEBUG OUTPUT + ******************************************************************************/ + +// Provide Notehub debug output via STLINK serial port when available +#if defined(ARDUINO_SWAN_R5) || defined(ARDUINO_CYGNET) + #define STLINK_DEBUG + HardwareSerial stlinkSerial(PIN_VCP_RX, PIN_VCP_TX); +#endif + +/****************************************************************************** + TYPEDEF + ******************************************************************************/ + +struct NotecardConnectionStatus +{ + NotecardConnectionStatus(void) : transport_connected(0), connected_to_notehub(0), notecard_error(0), host_error(0), reserved(0) { } + NotecardConnectionStatus(uint_fast8_t x) : transport_connected(x & 0x01), connected_to_notehub(x & 0x02), notecard_error(x & 0x04), host_error(x & 0x08), reserved(x & 0xF0) { } + NotecardConnectionStatus & operator=(uint_fast8_t x) { + transport_connected = (x & 0x01); + connected_to_notehub = (x & 0x02); + notecard_error = (x & 0x04); + host_error = (x & 0x08); + reserved = (x & 0xF0); + return *this; + } + operator uint_fast8_t () const { + return ((reserved << 4) | (host_error << 3) | (notecard_error << 2) | (connected_to_notehub << 1) | (transport_connected)); + } + + bool transport_connected : 1; + bool connected_to_notehub : 1; + bool notecard_error : 1; + bool host_error : 1; + uint_fast8_t reserved : 4; +}; +static_assert(sizeof(NotecardConnectionStatus) == sizeof(uint_fast8_t)); + +/****************************************************************************** + CTOR/DTOR + ******************************************************************************/ + +NotecardConnectionHandler::NotecardConnectionHandler( + const String & project_uid_, + uint32_t i2c_address_, + uint32_t i2c_max_, + TwoWire & wire_, + bool keep_alive_ +) : + ConnectionHandler{keep_alive_, NetworkAdapter::NOTECARD}, + _notecard{}, + _device_id{}, + _notecard_uid{}, + _project_uid(project_uid_), + _serial(nullptr), + _wire(&wire_), + _inbound_buffer(nullptr), + _conn_start_ms(0), + _i2c_address(i2c_address_), + _i2c_max(i2c_max_), + _inbound_buffer_index(0), + _inbound_buffer_size(0), + _inbound_polling_interval_min(NO_INBOUND_POLLING), + _uart_baud(0), + _en_hw_int(false), + _topic_type{TopicType::Invalid} +{ } + +NotecardConnectionHandler::NotecardConnectionHandler( + const String & project_uid_, + HardwareSerial & serial_, + uint32_t baud_, + bool keep_alive_ +) : + ConnectionHandler{keep_alive_, NetworkAdapter::NOTECARD}, + _notecard{}, + _device_id{}, + _notecard_uid{}, + _project_uid(project_uid_), + _serial(&serial_), + _wire(nullptr), + _inbound_buffer(nullptr), + _conn_start_ms(0), + _i2c_address(0), + _i2c_max(0), + _inbound_buffer_index(0), + _inbound_buffer_size(0), + _inbound_polling_interval_min(NO_INBOUND_POLLING), + _uart_baud(baud_), + _en_hw_int(false), + _topic_type{TopicType::Invalid} +{ } + +/****************************************************************************** + PUBLIC MEMBER FUNCTIONS + ******************************************************************************/ + +int NotecardConnectionHandler::initiateNotehubSync (SyncType type_) const +{ + int result; + + Debug.print(DBG_DEBUG, F("NotecardConnectionHandler::%s initiating Notehub sync..."), __FUNCTION__); + if (J *req = _notecard.newRequest("hub.sync")) { + if (type_ == SyncType::Inbound) { + JAddBoolToObject(req, "in", true); + } else if (type_ == SyncType::Outbound) { + JAddBoolToObject(req, "out", true); + } + if (J *rsp = _notecard.requestAndResponse(req)) { + // Check the response for errors + if (NoteResponseError(rsp)) { + const char *err = JGetString(rsp, "err"); + Debug.print(DBG_ERROR, F("%s"), err); + result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; + } else { + Debug.print(DBG_DEBUG, F("NotecardConnectionHandler::%s successfully initiated Notehub sync."), __FUNCTION__); + result = NotecardCommunicationError::NOTECARD_ERROR_NONE; + } + JDelete(rsp); + } else { + Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; + } + } else { + Debug.print(DBG_ERROR, "Failed to allocate request: hub.sync"); + result = NotecardCommunicationError::HOST_ERROR_OUT_OF_MEMORY; + } + + return result; +} + +int NotecardConnectionHandler::setWiFiCredentials (const String & ssid_, const String & password_) +{ + int result; + + // Validate the connection state is not in an initialization state + const NetworkConnectionState current_net_connection_state = check(); + if (NetworkConnectionState::INIT == current_net_connection_state) + { + Debug.print(DBG_ERROR, F("Unable to set Wi-Fi credentials. Connection to Notecard uninitialized.")); + result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; + } else if (J *req = _notecard.newRequest("card.wifi")) { + JAddStringToObject(req, "ssid", ssid_.c_str()); + JAddStringToObject(req, "password", password_.c_str()); + if (J *rsp = _notecard.requestAndResponse(req)) { + // Check the response for errors + if (NoteResponseError(rsp)) { + const char *err = JGetString(rsp, "err"); + Debug.print(DBG_ERROR, F("%s"), err); + Debug.print(DBG_ERROR, F("Failed to set Wi-Fi credentials.")); + result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; + } else { + Debug.print(DBG_INFO, F("Wi-Fi credentials updated. ssid: \"%s\" password: \"%s\"."), ssid_.c_str(), password_.length() ? "**********" : ""); + result = NotecardCommunicationError::NOTECARD_ERROR_NONE; + } + JDelete(rsp); + } else { + Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; + } + } else { + Debug.print(DBG_ERROR, F("Failed to allocate request: wifi.set")); + result = NotecardCommunicationError::HOST_ERROR_OUT_OF_MEMORY; + } + + return result; +} + +/****************************************************************************** + PUBLIC INTERFACE MEMBER FUNCTIONS + ******************************************************************************/ + +bool NotecardConnectionHandler::available() +{ + bool buffered_data = (_inbound_buffer_index < _inbound_buffer_size); + bool flush_required = !buffered_data && _inbound_buffer_size; + + // When the buffer is empty, look for a Note in the + // NOTEFILE_SECURE_INBOUND file to reload the buffer. + if (!buffered_data) { + // Reset the buffer + free(_inbound_buffer); + _inbound_buffer = nullptr; + _inbound_buffer_index = 0; + _inbound_buffer_size = 0; + + // Do NOT attempt to buffer the next Note immediately after buffer + // exhaustion (a.k.a. flush required). Returning `false` between Notes, + // will break the read loop, force the CBOR buffer to be parsed, and the + // property containers to be updated. + if (!flush_required) { + // Reload the buffer + J *note = getNote(true); + if (note) { + if (J *body = JGetObject(note, "body")) { + _topic_type = static_cast(JGetInt(body, "topic")); + if (_topic_type == TopicType::Invalid) { + Debug.print(DBG_WARNING, F("Note does not contain a topic")); + } else { + buffered_data = JGetBinaryFromObject(note, "payload", &_inbound_buffer, &_inbound_buffer_size); + if (!buffered_data) { + Debug.print(DBG_WARNING, F("Note does not contain payload data")); + } else { + Debug.print(DBG_DEBUG, F("NotecardConnectionHandler::%s buffered payload with size: %d"), __FUNCTION__, _inbound_buffer_size); + } + } + } else { + _topic_type = TopicType::Invalid; + } + JDelete(note); + } + } + } + + return buffered_data; +} + +unsigned long NotecardConnectionHandler::getTime() +{ + unsigned long result; + + if (J *rsp = _notecard.requestAndResponse(_notecard.newRequest("card.time"))) { + if (NoteResponseError(rsp)) { + const char *err = JGetString(rsp, "err"); + Debug.print(DBG_ERROR, F("%s\n"), err); + result = 0; + } else { + result = JGetInt(rsp, "time"); + } + JDelete(rsp); + } else { + result = 0; + } + + return result; +} + +int NotecardConnectionHandler::read() +{ + int result; + + if (_inbound_buffer_index < _inbound_buffer_size) { + result = _inbound_buffer[_inbound_buffer_index++]; + } else { + result = NotecardCommunicationError::NOTECARD_ERROR_NO_DATA_AVAILABLE; + } + + return result; +} + +int NotecardConnectionHandler::write(const uint8_t * buf_, size_t size_) +{ + int result; + + // Validate the connection state is not uninitialized or in error state + const NetworkConnectionState current_net_connection_state = check(); + if ((NetworkConnectionState::INIT == current_net_connection_state) + || (NetworkConnectionState::ERROR == current_net_connection_state)) + { + Debug.print(DBG_ERROR, F("Unable to write message. Connection to Notecard uninitialized or in error state.")); + result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; + } else if (J * req = _notecard.newRequest("note.add")) { + JAddStringToObject(req, "file", NOTEFILE_SECURE_OUTBOUND); + if (buf_) { + JAddBinaryToObject(req, "payload", buf_, size_); + } + // Queue the Note when `_keep_alive` is disabled or not connected to Notehub + if (_keep_alive && (NetworkConnectionState::CONNECTED == current_net_connection_state)) { + JAddBoolToObject(req, "live", true); + JAddBoolToObject(req, "sync", true); + } + if (J *body = JAddObjectToObject(req, "body")) { + JAddIntToObject(body, "topic", static_cast(_topic_type)); + J * rsp = _notecard.requestAndResponse(req); + if (NoteResponseError(rsp)) { + const char *err = JGetString(rsp, "err"); + if (NoteErrorContains(err, "{hub-not-connected}")) { + // _current_net_connection_state = NetworkConnectionState::DISCONNECTED; + } + Debug.print(DBG_ERROR, F("%s\n"), err); + result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; + } else { + result = NotecardCommunicationError::NOTECARD_ERROR_NONE; + Debug.print(DBG_INFO, F("Message sent correctly!")); + } + JDelete(rsp); + } else { + JFree(req); + result = NotecardCommunicationError::HOST_ERROR_OUT_OF_MEMORY; + } + } else { + result = NotecardCommunicationError::HOST_ERROR_OUT_OF_MEMORY; + } + + return result; +} + +/****************************************************************************** + PROTECTED STATE MACHINE FUNCTIONS + ******************************************************************************/ + +NetworkConnectionState NotecardConnectionHandler::update_handleInit() +{ + NetworkConnectionState result = NetworkConnectionState::INIT; + + // Configure Hardware +/////////////////////// + +#if defined(STLINK_DEBUG) + // Output Notecard logs to the STLINK serial port + stlinkSerial.end(); // necessary to handle multiple initializations (e.g. reconnections) + stlinkSerial.begin(115200); + const size_t usb_timeout_ms = 3000; + for (const size_t start_ms = millis(); !stlinkSerial && (millis() - start_ms) < usb_timeout_ms;); + _notecard.setDebugOutputStream(stlinkSerial); +#endif + + // Initialize the Notecard based on the configuration + if (_serial) { + _notecard.begin(*_serial, _uart_baud); + } else { + _notecard.begin(_i2c_address, _i2c_max, *_wire); + } + + // Configure `note-c` + /////////////////////// + + // Set the user agent + NoteSetUserAgent((char *) ("arduino-iot-cloud " NOTECARD_CONNECTION_HANDLER_VERSION)); + + // Configure the ATTN pin to be used as an interrupt to indicate when a Note + // is available to read. `getNote()` will only arm the interrupt if no old + // Notes are available. If `ATTN` remains unarmed, it signals the user + // application that outstanding Notes are queued and need to be processed. + if (J *note = getNote(false)) { + JDelete(note); + } + + // Configure the Notecard + /////////////////////////// + + // Set the project UID + if (NetworkConnectionState::INIT == result) { + if (configureConnection(true)) { + result = NetworkConnectionState::INIT; + } else { + result = NetworkConnectionState::ERROR; + } + } + +#if defined(ARDUINO_OPTA) + // The Opta Extension has an onboard Li-Ion capacitor, that can be utilized + // to monitor the power state of the device and automatically report loss of + // power to Notehub. The following command enables that detection by default + // for the Opta Wirelss Extension. + if (NetworkConnectionState::INIT == result) { + if (J *req = _notecard.newRequest("card.voltage")) { + JAddStringToObject(req, "mode", "lipo"); + JAddBoolToObject(req, "alert", true); + JAddBoolToObject(req, "sync", true); + JAddBoolToObject(req, "usb", true); + if (J *rsp = _notecard.requestAndResponse(req)) { + // Check the response for errors + if (NoteResponseError(rsp)) { + const char *err = JGetString(rsp, "err"); + Debug.print(DBG_ERROR, F("%s"), err); + result = NetworkConnectionState::ERROR; + } else { + result = NetworkConnectionState::INIT; + } + JDelete(rsp); + } else { + Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + result = NetworkConnectionState::ERROR; // Assume the worst + } + } else { + Debug.print(DBG_ERROR, "Failed to allocate request: card.voltage"); + result = NetworkConnectionState::ERROR; // Assume the worst + } + } +#endif + + // Set database template to support LoRa/Satellite Notecard + if (NetworkConnectionState::INIT == result) { + if (J *req = _notecard.newRequest("note.template")) { + JAddStringToObject(req, "file", NOTEFILE_SECURE_DATABASE); + JAddStringToObject(req, "format", "compact"); // Support LoRa/Satellite Notecards + JAddIntToObject(req, "port", NOTEFILE_DATABASE_LORA_PORT); // Support LoRa/Satellite Notecards + if (J *body = JAddObjectToObject(req, "body")) { + JAddStringToObject(body, "text", TSTRINGV); + JAddNumberToObject(body, "value", TFLOAT64); + JAddBoolToObject(body, "flag", TBOOL); + if (J *rsp = _notecard.requestAndResponse(req)) { + // Check the response for errors + if (NoteResponseError(rsp)) { + const char *err = JGetString(rsp, "err"); + Debug.print(DBG_ERROR, F("%s"), err); + result = NetworkConnectionState::ERROR; + } else { + result = NetworkConnectionState::INIT; + } + JDelete(rsp); + } else { + Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + result = NetworkConnectionState::ERROR; // Assume the worst + } + } else { + Debug.print(DBG_ERROR, "Failed to allocate request: note.template:body"); + JFree(req); + result = NetworkConnectionState::ERROR; // Assume the worst + } + } else { + Debug.print(DBG_ERROR, "Failed to allocate request: note.template"); + result = NetworkConnectionState::ERROR; // Assume the worst + } + } + + // Set inbound template to support LoRa/Satellite Notecard + if (NetworkConnectionState::INIT == result) { + if (J *req = _notecard.newRequest("note.template")) { + JAddStringToObject(req, "file", NOTEFILE_SECURE_INBOUND); + JAddStringToObject(req, "format", "compact"); // Support LoRa/Satellite Notecards + JAddIntToObject(req, "port", NOTEFILE_INBOUND_LORA_PORT); // Support LoRa/Satellite Notecards + if (J *body = JAddObjectToObject(req, "body")) { + JAddIntToObject(body, "topic", TUINT8); + if (J *rsp = _notecard.requestAndResponse(req)) { + // Check the response for errors + if (NoteResponseError(rsp)) { + const char *err = JGetString(rsp, "err"); + Debug.print(DBG_ERROR, F("%s"), err); + result = NetworkConnectionState::ERROR; + } else { + result = NetworkConnectionState::INIT; + } + JDelete(rsp); + } else { + Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + result = NetworkConnectionState::ERROR; // Assume the worst + } + } else { + Debug.print(DBG_ERROR, "Failed to allocate request: note.template:body"); + JFree(req); + result = NetworkConnectionState::ERROR; // Assume the worst + } + } else { + Debug.print(DBG_ERROR, "Failed to allocate request: note.template"); + result = NetworkConnectionState::ERROR; // Assume the worst + } + } + + // Set outbound template to remove payload size restrictions + if (NetworkConnectionState::INIT == result) { + if (J *req = _notecard.newRequest("note.template")) { + JAddStringToObject(req, "file", NOTEFILE_SECURE_OUTBOUND); + JAddStringToObject(req, "format", "compact"); // Support LoRa/Satellite Notecards + JAddIntToObject(req, "port", NOTEFILE_OUTBOUND_LORA_PORT); // Support LoRa/Satellite Notecards + if (J *body = JAddObjectToObject(req, "body")) { + JAddIntToObject(body, "topic", TUINT8); + if (J *rsp = _notecard.requestAndResponse(req)) { + // Check the response for errors + if (NoteResponseError(rsp)) { + const char *err = JGetString(rsp, "err"); + Debug.print(DBG_ERROR, F("%s"), err); + result = NetworkConnectionState::ERROR; + } else { + result = NetworkConnectionState::INIT; + } + JDelete(rsp); + } else { + Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + result = NetworkConnectionState::ERROR; // Assume the worst + } + } else { + Debug.print(DBG_ERROR, "Failed to allocate request: note.template:body"); + JFree(req); + result = NetworkConnectionState::ERROR; // Assume the worst + } + } else { + Debug.print(DBG_ERROR, "Failed to allocate request: note.template"); + result = NetworkConnectionState::ERROR; // Assume the worst + } + } + + // Get the device UID + if (NetworkConnectionState::INIT == result) { + if (!updateUidCache()) { + result = NetworkConnectionState::ERROR; + } else { + Debug.print(DBG_INFO, F("Notecard has been initialized.")); + if (_keep_alive) { + _conn_start_ms = ::millis(); + Debug.print(DBG_INFO, F("Starting network connection...")); + result = NetworkConnectionState::CONNECTING; + } else { + Debug.print(DBG_INFO, F("Network is disconnected.")); + result = NetworkConnectionState::DISCONNECTED; + } + } + } + + return result; +} + +NetworkConnectionState NotecardConnectionHandler::update_handleConnecting() +{ + NetworkConnectionState result; + + // Check the connection status + const NotecardConnectionStatus conn_status = connected(); + + // Update the connection state + if (!conn_status.connected_to_notehub) { + if ((::millis() - _conn_start_ms) > NOTEHUB_CONN_TIMEOUT_MS) { + Debug.print(DBG_ERROR, F("Timeout exceeded, connection to the network failed.")); + Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); + result = NetworkConnectionState::INIT; + } else { + // Continue awaiting the connection to Notehub + if (conn_status.transport_connected) { + Debug.print(DBG_INFO, F("Establishing connection to Notehub...")); + } else { + Debug.print(DBG_INFO, F("Connecting to the network...")); + } + result = NetworkConnectionState::CONNECTING; + } + } else { + Debug.print(DBG_INFO, F("Connected to Notehub!")); + result = NetworkConnectionState::CONNECTED; + if (initiateNotehubSync()) { + Debug.print(DBG_ERROR, F("Failed to initiate Notehub sync.")); + } + } + + return result; +} + +NetworkConnectionState NotecardConnectionHandler::update_handleConnected() +{ + NetworkConnectionState result; + + const NotecardConnectionStatus conn_status = connected(); + if (!conn_status.connected_to_notehub) { + if (!conn_status.transport_connected) { + Debug.print(DBG_ERROR, F("Connection to the network lost.")); + } else { + Debug.print(DBG_ERROR, F("Connection to Notehub lost.")); + } + result = NetworkConnectionState::DISCONNECTED; + } else { + result = NetworkConnectionState::CONNECTED; + } + + return result; +} + +NetworkConnectionState NotecardConnectionHandler::update_handleDisconnecting() +{ + NetworkConnectionState result; + + Debug.print(DBG_ERROR, F("Connection to the network lost.")); + result = NetworkConnectionState::DISCONNECTED; + + return result; +} + +NetworkConnectionState NotecardConnectionHandler::update_handleDisconnected() +{ + NetworkConnectionState result; + + if (_keep_alive) + { + Debug.print(DBG_ERROR, F("Attempting reconnection...")); + result = NetworkConnectionState::INIT; + } + else + { + if (configureConnection(false)) { + result = NetworkConnectionState::CLOSED; + Debug.print(DBG_INFO, F("Closing connection...")); + } else { + result = NetworkConnectionState::ERROR; + Debug.print(DBG_INFO, F("Error closing connection...")); + } + } + + return result; +} + +/****************************************************************************** + PRIVATE MEMBER FUNCTIONS + ******************************************************************************/ + +bool NotecardConnectionHandler::armInterrupt (void) const +{ + bool result; + + if (J *req = _notecard.newRequest("card.attn")) { + JAddStringToObject(req, "mode","rearm,files"); + if (J *files = JAddArrayToObject(req, "files")) { + JAddItemToArray(files, JCreateString(NOTEFILE_SECURE_INBOUND)); + if (J *rsp = _notecard.requestAndResponse(req)) { + // Check the response for errors + if (NoteResponseError(rsp)) { + const char *err = JGetString(rsp, "err"); + Debug.print(DBG_ERROR, F("%s\n"), err); + result = false; + } else { + result = true; + } + JDelete(rsp); + } else { + Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + result = false; + } + } else { + Debug.print(DBG_ERROR, "Failed to allocate request: card.attn:files"); + JFree(req); + result = false; + } + } else { + Debug.print(DBG_ERROR, "Failed to allocate request: card.attn"); + result = false; + } + + return result; +} + +bool NotecardConnectionHandler::configureConnection (bool connect_) const +{ + bool result; + + if (J *req = _notecard.newRequest("hub.set")) { + // Only update the product if it is not empty or the default value + if (_project_uid.length() > 0 && _project_uid != "com.domain.you:product") { + JAddStringToObject(req, "product", _project_uid.c_str()); + } + + // Configure the connection mode based on the `connect_` parameter + if (connect_) { + JAddStringToObject(req, "mode", "continuous"); + JAddIntToObject(req, "inbound", _inbound_polling_interval_min); + JAddBoolToObject(req, "sync", true); + } else { + JAddStringToObject(req, "mode", "periodic"); + JAddIntToObject(req, "inbound", NO_INBOUND_POLLING); + JAddIntToObject(req, "outbound", -1); + JAddStringToObject(req, "vinbound", "-"); + JAddStringToObject(req, "voutbound", "-"); + } + + // Send the request to the Notecard + if (J *rsp = _notecard.requestAndResponseWithRetry(req, 30)) { + // Check the response for errors + if (NoteResponseError(rsp)) { + const char *err = JGetString(rsp, "err"); + Debug.print(DBG_ERROR, F("%s"), err); + result = false; + } else { + result = true; + } + JDelete(rsp); + } else { + Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + result = false; // Assume the worst + } + } else { + Debug.print(DBG_ERROR, "Failed to allocate request: hub.set"); + result = false; // Assume the worst + } + + return result; +} + +uint_fast8_t NotecardConnectionHandler::connected (void) const +{ + NotecardConnectionStatus result; + + // Query the connection status from the Notecard + if (J *rsp = _notecard.requestAndResponse(_notecard.newRequest("hub.status"))) { + // Ensure the transaction doesn't return an error + if (NoteResponseError(rsp)) { + const char *err = JGetString(rsp, "err"); + Debug.print(DBG_ERROR, F("%s"),err); + result.notecard_error = true; + } else { + // Parse the transport connection status + result.transport_connected = (strstr(JGetString(rsp,"status"),"{connected}") != nullptr); + + // Parse the status of the connection to Notehub + result.connected_to_notehub = JGetBool(rsp,"connected"); + + // Set the Notecard error status + result.notecard_error = false; + result.host_error = false; + } + + // Free the response + JDelete(rsp); + } else { + Debug.print(DBG_ERROR, F("Failed to acquire Notecard connection status.")); + result.transport_connected = false; + result.connected_to_notehub = false; + result.notecard_error = false; + result.host_error = true; + } + + return result; +} + +J * NotecardConnectionHandler::getNote (bool pop_) const +{ + J * result; + + // Look for a Note in the NOTEFILE_SECURE_INBOUND file + if (J *req = _notecard.newRequest("note.get")) { + JAddStringToObject(req, "file", NOTEFILE_SECURE_INBOUND); + if (pop_) { + JAddBoolToObject(req, "delete", true); + } + if (J *note = _notecard.requestAndResponse(req)) { + // Ensure the transaction doesn't return an error + if (NoteResponseError(note)) { + const char *jErr = JGetString(note, "err"); + if (NoteErrorContains(jErr, "{note-noexist}")) { + // The Notefile is empty, thus no Note is available. + if (_en_hw_int) { + armInterrupt(); + } + } else { + // Any other error indicates that we were unable to + // retrieve a Note, therefore no Note is available. + } + result = nullptr; + JDelete(note); + } else { + // The Note was successfully retrieved, and it now + // becomes the callers responsibility to free it. + result = note; + } + } else { + Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + result = nullptr; + } + } else { + Debug.print(DBG_ERROR, "Failed to allocate request: note.get"); + // Failed to retrieve a Note, therefore no Note is available. + result = nullptr; + } + + return result; +} + +bool NotecardConnectionHandler::updateUidCache (void) +{ + bool result; + + // This operation is safe to perform before a sync has occurred, because the + // Notecard UID is static and the cloud value of Serial Number is strictly + // informational with regard to the host firmware operations. + + // Read the Notecard UID from the Notehub configuration + if (J *rsp = _notecard.requestAndResponse(_notecard.newRequest("hub.get"))) { + // Check the response for errors + if (NoteResponseError(rsp)) { + const char *err = JGetString(rsp, "err"); + Debug.print(DBG_ERROR, F("Failed to read Notecard UID")); + Debug.print(DBG_ERROR, F("Error: %s"), err); + result = false; + } else { + _notecard_uid = JGetString(rsp, "device"); + _device_id = JGetString(rsp, "sn"); + _device_id = (_device_id.length() ? _device_id : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); + Debug.print(DBG_DEBUG, F("NotecardConnectionHandler::%s updated cache with Notecard UID: <%s> and Arduino Device ID: <%s>"), __FUNCTION__, _notecard_uid.c_str(), _device_id.c_str()); + result = true; + } + JDelete(rsp); + } else { + Debug.print(DBG_ERROR, F("Failed to read Notecard UID")); + result = false; + } + + return result; +} + +#endif /* BOARD_HAS_NOTECARD */ diff --git a/src/NotecardConnectionHandler.h b/src/NotecardConnectionHandler.h new file mode 100644 index 00000000..c758030f --- /dev/null +++ b/src/NotecardConnectionHandler.h @@ -0,0 +1,341 @@ +/* + This file is part of the ArduinoIoTCloud library. + + Copyright 2024 Blues (http://www.blues.com/) + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#ifndef ARDUINO_NOTECARD_CONNECTION_HANDLER_H_ +#define ARDUINO_NOTECARD_CONNECTION_HANDLER_H_ + +/****************************************************************************** + INCLUDE + ******************************************************************************/ + +#include + +#include +#include +#include + +#include "ConnectionHandlerInterface.h" + +/****************************************************************************** + DEFINES + ******************************************************************************/ + +#define NOTECARD_CONNECTION_HANDLER_VERSION_MAJOR 1 +#define NOTECARD_CONNECTION_HANDLER_VERSION_MINOR 0 +#define NOTECARD_CONNECTION_HANDLER_VERSION_PATCH 0 + +#define NOTECARD_CONNECTION_HANDLER_VERSION NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_MAJOR) "." NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_MINOR) "." NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_PATCH) + +/****************************************************************************** + CLASS DECLARATION + ******************************************************************************/ + +/** + * @brief The NotecardConnectionHandler class + * + * The NotecardConnectionHandler class is a concrete implementation of the + * ConnectionHandler interface that provides connectivity to the Arduino IoT + * Cloud using a Notecard. + */ +class NotecardConnectionHandler final : public ConnectionHandler +{ + public: + /** + * @brief The manner in which the Notecard is synchronized with Notehub + * + * The SyncType enum defines the valid types of synchronization operations + * that can be performed by the NotecardConnectionHandler class. + * + * @par + * - Full - synchronize both the inbound and outbound queues. + * - Inbound - synchronize only the inbound queues. + * - Outbound - synchronize only the outbound queues. + */ + enum class SyncType : uint8_t { + Full, + Inbound, + Outbound, + }; + + /** + * @brief The type of topic to be used for R/W operations + * + * The Notecard uses topics to identify the target of a read or write + * operation. The TopicType enum defines the valid types of topics. + * + * @par + * - Command - used to interact with the Arduino IoT Cloud. + * - Thing - used to send application data to the Arduino IoT Cloud. + */ + enum class TopicType : uint8_t { + Invalid = 0, + Command, + Thing, + }; + + /** + * @brief The error codes for communicating with the Notecard + * + * The NotecardCommunicationError enum defines the error codes that can be + * returned by the NotecardConnectionHandler class. + * + * @par + * - NOTECARD_ERROR_NONE - No error occurred. + * - NOTECARD_ERROR_NO_DATA_AVAILABLE - No data is available. + * - NOTECARD_ERROR_GENERIC - A generic error occurred. + * - HOST_ERROR_OUT_OF_MEMORY - The host is out of memory. + */ + typedef enum { + NOTECARD_ERROR_NONE = 0, + NOTECARD_ERROR_NO_DATA_AVAILABLE = -1, + NOTECARD_ERROR_GENERIC = -2, + HOST_ERROR_OUT_OF_MEMORY = -3, + } NotecardCommunicationError; + + /** + * @brief The default timeout for the Notecard to connect to Notehub + */ + static const uint32_t NOTEHUB_CONN_TIMEOUT_MS = 185000; + + /** + * @brief The I2C constructor for the Notecard + * + * @param project_uid[in] The project UID of the related Notehub account + * @param i2c_address[in] The I2C address of the Notecard + * @param i2c_max[in] The maximum I2C transaction size (MTU) + * @param wire[in] The I2C bus to use + * @param keep_alive[in] Keep the connection alive if connection to Notehub drops + */ + NotecardConnectionHandler( + const String & project_uid, + uint32_t i2c_address = NOTE_I2C_ADDR_DEFAULT, + uint32_t i2c_max = NOTE_I2C_MAX_DEFAULT, + TwoWire & wire = Wire, + bool keep_alive = true + ); + + /** + * @brief The UART constructor for the Notecard + * + * @param project_uid[in] The project UID of the related Notehub account + * @param serial[in] The serial port to use + * @param baud[in] The baud rate of the serial port + * @param keep_alive[in] Keep the connection alive if connection to Notehub drops + */ + NotecardConnectionHandler( + const String & project_uid, + HardwareSerial & serial, + uint32_t baud = 9600, + bool keep_alive = true + ); + + /** + * @brief Disable hardware interrupts + * + * When hardware interrupts are disabled, the `NotecardConnectionHandler` + * must be polled for incoming data. This is necessary when the host + * microcontroller is unable to use the ATTN pin of the Notecard. + */ + inline void disableHardwareInterrupts (void) { + _en_hw_int = false; + } + + /** + * @brief Enable hardware interrupts + * + * Hardware interrupts allow the `NotecardConnectionHandler` to leverage the + * ATTN pin of the Notecard. This improves the responsiveness of the + * `NotecardConnectionHandler` by eliminating the need for the host + * microcontroller to poll the Notecard for incoming data. + */ + inline void enableHardwareInterrupts (void) { + _en_hw_int = true; + } + + /** + * @brief Get the Arduino IoT Cloud Device ID + * + * The Arduino IoT Cloud Device ID is set as the serial number of the + * Notecard when the device is provisioned in Notehub. The serial number is + * updated on each sync between the Notecard and Notehub and cached by the + * Notecard. As a result, this value can lag behind the actual value of the + * Arduino IoT Cloud Device ID used by the Notehub. However, this value is + * typically unchanged during the life of the Notecard, so this is rarely, + * if ever, an issue. + * + * @return The Arduino IoT Cloud Device ID + */ + inline const String & getDeviceId (void) { + check(); // Ensure the connection to the Notecard is initialized + return _device_id; + } + + /** + * @brief Get the Notecard object + * + * The Notecard object is used to interact with the Notecard. This object + * provides methods to read and write data to the Notecard, as well as + * methods to configure the Notecard. + * + * @return The Notecard object + */ + inline const Notecard & getNotecard (void) { + return _notecard; + } + + /** + * @brief Get the Notecard Device ID + * + * The Notecard Device ID is the unique identifier of the Notecard. This + * value is set at time of manufacture, and is used to identify the Notecard + * in Notehub. + * + * @return The Notecard Device ID + */ + inline const String & getNotecardUid (void) { + check(); // Ensure the connection to the Notecard is initialized + return _notecard_uid; + } + + /** + * @brief Get the topic type of the most recent R/W operations + * + * @return The current topic type + * + * @see TopicType + */ + TopicType getTopicType (void) const { + return _topic_type; + } + + /** + * @brief Initiate a synchronization operation with Notehub + * + * The Notecard maintains two queues: an inbound queue and an outbound + * queue. The inbound queue is used to receive data from Notehub, while the + * outbound queue is used to send data to Notehub. This method initiates a + * synchronization operation between the Notecard and Notehub. + * + * As the name implies, this method is asynchronous and will only initiate + * the synchronization operation. The actual synchronization operation will + * be performed by the Notecard in the background. + * + * @param type[in] The type of synchronization operation to perform + * @par + * - SyncType::Full - synchronize both the inbound and outbound queues (default) + * - SyncType::Inbound - synchronize only the inbound queues. + * - SyncType::Outbound - synchronize only the outbound queues. + * + * @return 0 if successful, otherwise an error code + * + * @see SyncType + * @see NotecardCommunicationError + */ + int initiateNotehubSync (SyncType type = SyncType::Full) const; + + /** + * @brief Set the inbound polling interval (in minutes) + * + * A cellular Notecard will receive inbound traffic from the Arduino IoT + * Cloud in real-time. As such, the polling interval is used as a fail-safe + * to ensure the Notecard is guaranteed to receive inbound traffic at the + * interval specified by this method. + * + * Alternatively, a LoRa (or Satellite) Notecard does not maintain a + * continuous connection, and therefore must rely on the polling interval to + * establish the maximum acceptable delay before receiving any unsolicited, + * inbound traffic from the Arduino IoT Cloud. The polling interval must + * balance the needs of the application against the regulatory limitations + * of LoRa (or bandwidth limitations and cost of Satellite). + * + * LoRaWAN Fair Use Policy: + * https://www.thethingsnetwork.org/forum/t/fair-use-policy-explained/1300 + * + * @param interval_min[in] The inbound polling interval (in minutes) + * + * @note Set the interval to 0 to disable inbound polling. + */ + inline void setNotehubPollingInterval (int32_t interval_min) { + _inbound_polling_interval_min = (interval_min ? interval_min : -1); + } + + /** + * @brief Set the topic type for R/W operations + * + * @param topic[in] The topic type + * @par + * - TopicType::Command - used to interact with the Arduino IoT Cloud. + * - TopicType::Thing - used to send application data to the Arduino IoT Cloud. + * + * @see TopicType + */ + void setTopicType (TopicType topic) { + _topic_type = topic; + } + + /** + * @brief Set the WiFi credentials to be used by the Notecard + * + * @param ssid[in] The SSID of the WiFi network + * @param pass[in] The password of the WiFi network + * + * @return 0 if successful, otherwise an error code + * + * @note This method is only applicable when using a Wi-Fi capable Notecard, + * and is unnecessary when using a Notecard with cellular connectivity. + * If the Notecard is not Wi-Fi capable, this method will be a no-op. + * + * @see NotecardCommunicationError + */ + int setWiFiCredentials (const String & ssid, const String & pass); + + // ConnectionHandler interface + virtual bool available() override; + virtual unsigned long getTime() override; + virtual int read() override; + virtual int write(const uint8_t *buf, size_t size) override; + + protected: + + virtual NetworkConnectionState update_handleInit () override; + virtual NetworkConnectionState update_handleConnecting () override; + virtual NetworkConnectionState update_handleConnected () override; + virtual NetworkConnectionState update_handleDisconnecting() override; + virtual NetworkConnectionState update_handleDisconnected () override; + + private: + + // Private members + Notecard _notecard; + String _device_id; + String _notecard_uid; + String _project_uid; + HardwareSerial * _serial; + TwoWire * _wire; + uint8_t * _inbound_buffer; + uint32_t _conn_start_ms; + uint32_t _i2c_address; + uint32_t _i2c_max; + uint32_t _inbound_buffer_index; + uint32_t _inbound_buffer_size; + int32_t _inbound_polling_interval_min; + uint32_t _uart_baud; + bool _en_hw_int; + TopicType _topic_type; + + // Private methods + bool armInterrupt (void) const; + bool configureConnection (bool connect) const; + uint_fast8_t connected (void) const; + J * getNote (bool pop = false) const; + bool updateUidCache (void); +}; + +#endif /* ARDUINO_NOTECARD_CONNECTION_HANDLER_H_ */ From 8e11455c32f2afb8b7398020ca6acb27cf5a66ed Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 20 Aug 2024 18:09:48 +0200 Subject: [PATCH 155/203] Add support to Raspberry Pi Pico W --- .github/workflows/compile-examples.yml | 11 +++++++++++ src/ConnectionHandlerDefinitions.h | 7 +++++++ src/WiFiConnectionHandler.h | 3 +++ 3 files changed, 21 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index c0c5b9a9..808258ed 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -101,6 +101,9 @@ jobs: - fqbn: arduino:mbed_edge:edge_control platform-name: arduino:mbed_edge artifact-name-suffix: arduino-mbed_edge-edge_control + - fqbn: "rp2040:rp2040:rpipicow" + platform-name: rp2040:rp2040 + artifact-name-suffix: rp2040-rp2040-rpipicow # Make board type-specific customizations to the matrix jobs include: @@ -181,6 +184,14 @@ jobs: source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json sketch-paths: | - examples/ConnectionHandlerDemo-Notecard + - board: + platform-name: rp2040:rp2040 + platforms: | + # Install rp2040 platform via Boards Manager + - name: rp2040:rp2040 + source-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json + sketch-paths: | + - examples/ConnectionHandlerDemo-Notecard steps: - uses: actions/checkout@v4 diff --git a/src/ConnectionHandlerDefinitions.h b/src/ConnectionHandlerDefinitions.h index 96bcd654..4f295592 100644 --- a/src/ConnectionHandlerDefinitions.h +++ b/src/ConnectionHandlerDefinitions.h @@ -144,6 +144,13 @@ #define NETWORK_HARDWARE_ERROR #endif +#if defined(ARDUINO_RASPBERRY_PI_PICO_W) + #define BOARD_HAS_WIFI + #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD + #define NETWORK_IDLE_STATUS WL_IDLE_STATUS + #define NETWORK_CONNECTED WL_CONNECTED +#endif + #endif // BOARD_HAS_NOTECARD /****************************************************************************** diff --git a/src/WiFiConnectionHandler.h b/src/WiFiConnectionHandler.h index e5e2e25d..2ee674a5 100644 --- a/src/WiFiConnectionHandler.h +++ b/src/WiFiConnectionHandler.h @@ -46,6 +46,9 @@ #include #elif defined(ARDUINO_UNOR4_WIFI) #include +#elif defined(ARDUINO_RASPBERRY_PI_PICO_W) + #include + #include #endif #ifndef BOARD_HAS_WIFI From bbaabd29c8a7eb489fc7baaa70e5e05fd865906d Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Mon, 9 Sep 2024 12:17:55 +0200 Subject: [PATCH 156/203] Release 1.0.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index c2ebe2a0..c202d604 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=0.9.0 +version=1.0.0 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet], Notecard) From a0a58b85dfb1086571119bd941ece8375fdc57f2 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 12 Sep 2024 09:55:05 +0200 Subject: [PATCH 157/203] Add missing rp2040 architecture to library.properties --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index c202d604..a40fac0e 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethe 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 +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) From 924f18efea7d08388f784b31a83165cdf3c290fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 13:05:06 +0000 Subject: [PATCH 158/203] Bump arduino/arduino-lint-action from 1 to 2 Bumps [arduino/arduino-lint-action](https://github.com/arduino/arduino-lint-action) from 1 to 2. - [Release notes](https://github.com/arduino/arduino-lint-action/releases) - [Commits](https://github.com/arduino/arduino-lint-action/compare/v1...v2) --- updated-dependencies: - dependency-name: arduino/arduino-lint-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/check-arduino.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index adb330f8..e8186852 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -19,7 +19,7 @@ jobs: uses: actions/checkout@v4 - name: Arduino Lint - uses: arduino/arduino-lint-action@v1 + uses: arduino/arduino-lint-action@v2 with: compliance: specification library-manager: update From d6a727a8d13764f72a88dbd9340d87e49086fc62 Mon Sep 17 00:00:00 2001 From: "Zachary J. Fields" Date: Mon, 7 Oct 2024 11:54:30 -0500 Subject: [PATCH 159/203] chore: Remove vestigial database template from NCH --- src/NotecardConnectionHandler.cpp | 37 ------------------------------- src/NotecardConnectionHandler.h | 3 ++- 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/src/NotecardConnectionHandler.cpp b/src/NotecardConnectionHandler.cpp index 5205c4a8..b254c79a 100644 --- a/src/NotecardConnectionHandler.cpp +++ b/src/NotecardConnectionHandler.cpp @@ -31,13 +31,11 @@ #define NOTEFILE_BASE_NAME "arduino_iot_cloud" // Notecard LoRa requires us to choose an arbitrary port between 1-99 -#define NOTEFILE_DATABASE_LORA_PORT 1 #define NOTEFILE_INBOUND_LORA_PORT 2 #define NOTEFILE_OUTBOUND_LORA_PORT 3 // Note that we use "s" versions of the Notefile extensions to ensure that // traffic always happens on a secure transport -#define NOTEFILE_SECURE_DATABASE NOTEFILE_BASE_NAME ".dbs" #define NOTEFILE_SECURE_INBOUND NOTEFILE_BASE_NAME ".qis" #define NOTEFILE_SECURE_OUTBOUND NOTEFILE_BASE_NAME ".qos" @@ -423,41 +421,6 @@ NetworkConnectionState NotecardConnectionHandler::update_handleInit() } #endif - // Set database template to support LoRa/Satellite Notecard - if (NetworkConnectionState::INIT == result) { - if (J *req = _notecard.newRequest("note.template")) { - JAddStringToObject(req, "file", NOTEFILE_SECURE_DATABASE); - JAddStringToObject(req, "format", "compact"); // Support LoRa/Satellite Notecards - JAddIntToObject(req, "port", NOTEFILE_DATABASE_LORA_PORT); // Support LoRa/Satellite Notecards - if (J *body = JAddObjectToObject(req, "body")) { - JAddStringToObject(body, "text", TSTRINGV); - JAddNumberToObject(body, "value", TFLOAT64); - JAddBoolToObject(body, "flag", TBOOL); - if (J *rsp = _notecard.requestAndResponse(req)) { - // Check the response for errors - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - Debug.print(DBG_ERROR, F("%s"), err); - result = NetworkConnectionState::ERROR; - } else { - result = NetworkConnectionState::INIT; - } - JDelete(rsp); - } else { - Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); - result = NetworkConnectionState::ERROR; // Assume the worst - } - } else { - Debug.print(DBG_ERROR, "Failed to allocate request: note.template:body"); - JFree(req); - result = NetworkConnectionState::ERROR; // Assume the worst - } - } else { - Debug.print(DBG_ERROR, "Failed to allocate request: note.template"); - result = NetworkConnectionState::ERROR; // Assume the worst - } - } - // Set inbound template to support LoRa/Satellite Notecard if (NetworkConnectionState::INIT == result) { if (J *req = _notecard.newRequest("note.template")) { diff --git a/src/NotecardConnectionHandler.h b/src/NotecardConnectionHandler.h index c758030f..2b3a8734 100644 --- a/src/NotecardConnectionHandler.h +++ b/src/NotecardConnectionHandler.h @@ -29,7 +29,7 @@ #define NOTECARD_CONNECTION_HANDLER_VERSION_MAJOR 1 #define NOTECARD_CONNECTION_HANDLER_VERSION_MINOR 0 -#define NOTECARD_CONNECTION_HANDLER_VERSION_PATCH 0 +#define NOTECARD_CONNECTION_HANDLER_VERSION_PATCH 1 #define NOTECARD_CONNECTION_HANDLER_VERSION NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_MAJOR) "." NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_MINOR) "." NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_PATCH) @@ -261,6 +261,7 @@ class NotecardConnectionHandler final : public ConnectionHandler * @param interval_min[in] The inbound polling interval (in minutes) * * @note Set the interval to 0 to disable inbound polling. + * @note Must be set prior to initializing the connection to the Notecard. */ inline void setNotehubPollingInterval (int32_t interval_min) { _inbound_polling_interval_min = (interval_min ? interval_min : -1); From cb2dc7aa9b08f1da8f915b88afb22ddc449a77a9 Mon Sep 17 00:00:00 2001 From: "Zachary J. Fields" Date: Fri, 28 Feb 2025 15:16:42 -0600 Subject: [PATCH 160/203] chore: refactor device id handling - Migrate from `sn` to `_arduino_device_id` --- src/NotecardConnectionHandler.cpp | 10 +++++++--- src/NotecardConnectionHandler.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/NotecardConnectionHandler.cpp b/src/NotecardConnectionHandler.cpp index b254c79a..9917fcef 100644 --- a/src/NotecardConnectionHandler.cpp +++ b/src/NotecardConnectionHandler.cpp @@ -774,9 +774,13 @@ bool NotecardConnectionHandler::updateUidCache (void) result = false; } else { _notecard_uid = JGetString(rsp, "device"); - _device_id = JGetString(rsp, "sn"); - _device_id = (_device_id.length() ? _device_id : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); - Debug.print(DBG_DEBUG, F("NotecardConnectionHandler::%s updated cache with Notecard UID: <%s> and Arduino Device ID: <%s>"), __FUNCTION__, _notecard_uid.c_str(), _device_id.c_str()); + char device_id[] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; + if (NoteGetEnv("_arduino_device_id", device_id, device_id, sizeof(device_id))) { + _device_id = device_id; + } else { + Debug.print(DBG_DEBUG, F("NotecardConnectionHandler::%s Arduino Device ID not cached on Notecard, using default value: <%s>"), __FUNCTION__, _device_id.c_str()); + } + Debug.print(DBG_DEBUG, F("NotecardConnectionHandler::%s updated local cache with Notecard UID: <%s> and Arduino Device ID: <%s>"), __FUNCTION__, _notecard_uid.c_str(), _device_id.c_str()); result = true; } JDelete(rsp); diff --git a/src/NotecardConnectionHandler.h b/src/NotecardConnectionHandler.h index 2b3a8734..4278c144 100644 --- a/src/NotecardConnectionHandler.h +++ b/src/NotecardConnectionHandler.h @@ -28,7 +28,7 @@ ******************************************************************************/ #define NOTECARD_CONNECTION_HANDLER_VERSION_MAJOR 1 -#define NOTECARD_CONNECTION_HANDLER_VERSION_MINOR 0 +#define NOTECARD_CONNECTION_HANDLER_VERSION_MINOR 1 #define NOTECARD_CONNECTION_HANDLER_VERSION_PATCH 1 #define NOTECARD_CONNECTION_HANDLER_VERSION NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_MAJOR) "." NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_MINOR) "." NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_PATCH) From 8014ed99588906e6d047a0b97f4006c6e535cf9c Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Mon, 10 Mar 2025 12:20:09 +0100 Subject: [PATCH 161/203] Release 1.0.1 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index a40fac0e..f3c10c58 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=1.0.0 +version=1.0.1 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet], Notecard) From 84da5681702b974b7c2650b0d93c9d0997b490a0 Mon Sep 17 00:00:00 2001 From: "Zachary J. Fields" Date: Thu, 17 Apr 2025 10:18:47 -0500 Subject: [PATCH 162/203] fix: Notecard_ConnectionHandler Power Profile There is a bug in code that specifically targets the Wireless for Arduino Opta expansion. The battery backup on the device is a Lithium Ion Capacitor (LIC), but the Lithium Polymer (LiPo) profile was provided. The Notecard will work correctly in this state, but it the LIC is designed to support lower voltages than a LiPo. The improvement provided here will allow the Notecard to remain powered for a longer duration. --- src/NotecardConnectionHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NotecardConnectionHandler.cpp b/src/NotecardConnectionHandler.cpp index 9917fcef..466c74df 100644 --- a/src/NotecardConnectionHandler.cpp +++ b/src/NotecardConnectionHandler.cpp @@ -396,7 +396,7 @@ NetworkConnectionState NotecardConnectionHandler::update_handleInit() // for the Opta Wirelss Extension. if (NetworkConnectionState::INIT == result) { if (J *req = _notecard.newRequest("card.voltage")) { - JAddStringToObject(req, "mode", "lipo"); + JAddStringToObject(req, "mode", "lic"); JAddBoolToObject(req, "alert", true); JAddBoolToObject(req, "sync", true); JAddBoolToObject(req, "usb", true); From 432961add867901df6dcc909b5d57fe747aaeb22 Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Mon, 28 Apr 2025 12:01:37 +0200 Subject: [PATCH 163/203] Release 1.0.2 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index f3c10c58..4539afee 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=1.0.1 +version=1.0.2 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet], Notecard) From d4778bcb0bcb25f336bcddc99b99bfc718b705a1 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Tue, 4 Jun 2024 16:01:19 +0200 Subject: [PATCH 164/203] defining interface settings in a struct --- src/connectionHandlerModels/settings.h | 128 +++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 src/connectionHandlerModels/settings.h diff --git a/src/connectionHandlerModels/settings.h b/src/connectionHandlerModels/settings.h new file mode 100644 index 00000000..b47960c4 --- /dev/null +++ b/src/connectionHandlerModels/settings.h @@ -0,0 +1,128 @@ +/* + This file is part of the Arduino_ConnectionHandler library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#pragma once + +#include "ConnectionHandlerDefinitions.h" +#include +#include + +namespace models { + constexpr size_t WifiSsidLength = 33; // Max length of wifi ssid is 32 + \0 + constexpr size_t WifiPwdLength = 64; // Max length of wifi password is 63 + \0 + + constexpr size_t CellularPinLength = 9; + constexpr size_t CellularApnLength = 101; // Max length of apn is 100 + \0 + constexpr size_t CellularLoginLength = 65; + constexpr size_t CellularPassLength = 65; + + constexpr size_t LoraAppeuiLength = 17; // appeui is 8 octets * 2 (hex format) + \0 + constexpr size_t LoraAppkeyLength = 33; // appeui is 16 octets * 2 (hex format) + \0 + constexpr size_t LoraChannelMaskLength = 13; + + #if defined(BOARD_HAS_WIFI) + struct WiFiSetting { + char ssid[WifiSsidLength]; + char pwd[WifiPwdLength]; + }; + #endif //defined(BOARD_HAS_WIFI) + + #if defined(BOARD_HAS_ETHERNET) + // this struct represents an ip address in its simplest form. + // FIXME this should be available from ArduinoCore-api IPAddress + struct ip_addr { + IPType type; + union { + uint8_t bytes[16]; + uint32_t dword[4]; + }; + }; + + struct EthernetSetting { + ip_addr ip; + ip_addr dns; + ip_addr gateway; + ip_addr netmask; + unsigned long timeout; + unsigned long response_timeout; + }; + #endif // BOARD_HAS_ETHERNET + + #if defined(BOARD_HAS_NB) || defined(BOARD_HAS_GSM) ||defined(BOARD_HAS_CELLULAR) + struct CellularSetting { + char pin[CellularPinLength]; + char apn[CellularApnLength]; + char login[CellularLoginLength]; + char pass[CellularPassLength]; + }; + #endif // defined(BOARD_HAS_NB) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR) + + #if defined(BOARD_HAS_GSM) + typedef CellularSetting GSMSetting; + #endif //defined(BOARD_HAS_GSM) + + #if defined(BOARD_HAS_NB) + typedef CellularSetting NBSetting; + #endif //defined(BOARD_HAS_NB) + + #if defined(BOARD_HAS_CATM1_NBIOT) + struct CATM1Setting { + char pin[CellularPinLength]; + char apn[CellularApnLength]; + char login[CellularLoginLength]; + char pass[CellularPassLength]; + uint32_t band; + uint8_t rat; + }; + #endif //defined(BOARD_HAS_CATM1_NBIOT) + +#if defined(BOARD_HAS_LORA) + struct LoraSetting { + char appeui[LoraAppeuiLength]; + char appkey[LoraAppkeyLength]; + uint8_t band; + char channelMask[LoraChannelMaskLength]; + uint8_t deviceClass; + }; +#endif + + struct NetworkSetting { + NetworkAdapter type; + union { + #if defined(BOARD_HAS_WIFI) + WiFiSetting wifi; + #endif + + #if defined(BOARD_HAS_ETHERNET) + EthernetSetting eth; + #endif + + #if defined(BOARD_HAS_NB) + NBSetting nb; + #endif + + #if defined(BOARD_HAS_GSM) + GSMSetting gsm; + #endif + + #if defined(BOARD_HAS_CATM1_NBIOT) + CATM1Setting catm1; + #endif + + #if defined(BOARD_HAS_CELLULAR) + CellularSetting cell; + #endif + + #if defined(BOARD_HAS_LORA) + LoraSetting lora; + #endif + }; + }; +} From 10195f57d394baab08b823b49af4cf38ca05434d Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 5 Jun 2024 14:34:40 +0200 Subject: [PATCH 165/203] readapting ConnectionHandlerInterface to use setting struct --- src/ConnectionHandlerInterface.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/ConnectionHandlerInterface.h b/src/ConnectionHandlerInterface.h index 228827e7..eecf7108 100644 --- a/src/ConnectionHandlerInterface.h +++ b/src/ConnectionHandlerInterface.h @@ -29,6 +29,7 @@ #include #include #include "ConnectionHandlerDefinitions.h" +#include "connectionHandlerModels/settings.h" /****************************************************************************** TYPEDEFS @@ -40,10 +41,13 @@ typedef void (*OnNetworkEventCallback)(); CLASS DECLARATION ******************************************************************************/ +// forward declaration FIXME +class GenericConnectionHandler; + class ConnectionHandler { public: - ConnectionHandler(bool const keep_alive, NetworkAdapter interface); + ConnectionHandler(bool const keep_alive=true, NetworkAdapter interface=NetworkAdapter::NONE); NetworkConnectionState check(); @@ -77,6 +81,22 @@ class ConnectionHandler { void addDisconnectCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); void addErrorCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); + /** + * Update the interface settings. This can be performed only when the interface is + * in INIT state. otherwise nothing is performed. The type of the interface should match + * the type of the settings provided + * + * @return true if the update is successful, false otherwise + */ + virtual bool updateSetting(const models::NetworkSetting& s) { + if(_current_net_connection_state == NetworkConnectionState::INIT && s.type == _interface) { + memcpy(&_settings, &s, sizeof(s)); + return true; + } + + return false; + } + protected: bool _keep_alive; @@ -88,6 +108,8 @@ class ConnectionHandler { virtual NetworkConnectionState update_handleDisconnecting() = 0; virtual NetworkConnectionState update_handleDisconnected () = 0; + models::NetworkSetting _settings; + private: unsigned long _lastConnectionTickTime; @@ -95,5 +117,7 @@ class ConnectionHandler { OnNetworkEventCallback _on_connect_event_callback = NULL, _on_disconnect_event_callback = NULL, _on_error_event_callback = NULL; + + friend GenericConnectionHandler; }; From c066a8c7abc0705011712e7e33f602a702fb17e5 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Thu, 5 Dec 2024 15:15:24 +0100 Subject: [PATCH 166/203] Virtual methods and destructors for ConnectionHnadler interface --- src/ConnectionHandlerInterface.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ConnectionHandlerInterface.h b/src/ConnectionHandlerInterface.h index eecf7108..cde533af 100644 --- a/src/ConnectionHandlerInterface.h +++ b/src/ConnectionHandlerInterface.h @@ -49,6 +49,7 @@ class ConnectionHandler { ConnectionHandler(bool const keep_alive=true, NetworkAdapter interface=NetworkAdapter::NONE); + virtual ~ConnectionHandler() {} NetworkConnectionState check(); @@ -73,10 +74,10 @@ class ConnectionHandler { return _interface; } - void connect(); - void disconnect(); + virtual void connect(); + virtual void disconnect(); - void addCallback(NetworkConnectionEvent const event, OnNetworkEventCallback callback); + virtual void addCallback(NetworkConnectionEvent const event, OnNetworkEventCallback callback); void addConnectCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); void addDisconnectCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); void addErrorCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); @@ -97,6 +98,8 @@ class ConnectionHandler { return false; } + virtual void setKeepAlive(bool keep_alive=true) { this->_keep_alive = keep_alive; } + protected: bool _keep_alive; From 3d7564d2f34c1abd346cc90082ae7689e3e7eec4 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Thu, 3 Apr 2025 17:07:04 +0200 Subject: [PATCH 167/203] splitting check() method into updateConnectionState() and updateCallback() --- src/ConnectionHandlerInterface.cpp | 82 +++++++++++++++++++----------- src/ConnectionHandlerInterface.h | 3 ++ 2 files changed, 54 insertions(+), 31 deletions(-) diff --git a/src/ConnectionHandlerInterface.cpp b/src/ConnectionHandlerInterface.cpp index 2fdc10e1..1f62bde2 100644 --- a/src/ConnectionHandlerInterface.cpp +++ b/src/ConnectionHandlerInterface.cpp @@ -46,42 +46,22 @@ NetworkConnectionState ConnectionHandler::check() if((now - _lastConnectionTickTime) > connectionTickTimeInterval) { _lastConnectionTickTime = now; - NetworkConnectionState next_net_connection_state = _current_net_connection_state; - /* While the state machine is implemented here, the concrete implementation of the - * states is done in the derived connection handlers. - */ - switch (_current_net_connection_state) - { - case NetworkConnectionState::INIT: next_net_connection_state = update_handleInit (); break; - case NetworkConnectionState::CONNECTING: next_net_connection_state = update_handleConnecting (); break; - case NetworkConnectionState::CONNECTED: next_net_connection_state = update_handleConnected (); break; - case NetworkConnectionState::DISCONNECTING: next_net_connection_state = update_handleDisconnecting(); break; - case NetworkConnectionState::DISCONNECTED: next_net_connection_state = update_handleDisconnected (); break; - case NetworkConnectionState::ERROR: break; - case NetworkConnectionState::CLOSED: break; - } + NetworkConnectionState old_net_connection_state = _current_net_connection_state; + NetworkConnectionState next_net_connection_state = updateConnectionState(); /* Here we are determining whether a state transition from one state to the next has * occurred - and if it has, we call eventually registered callbacks. */ - if(next_net_connection_state != _current_net_connection_state) - { - /* Check the next state to determine the kind of state conversion which has occurred (and call the appropriate callback) */ - if(next_net_connection_state == NetworkConnectionState::CONNECTED) - { - if(_on_connect_event_callback) _on_connect_event_callback(); - } - if(next_net_connection_state == NetworkConnectionState::DISCONNECTED) - { - if(_on_disconnect_event_callback) _on_disconnect_event_callback(); - } - if(next_net_connection_state == NetworkConnectionState::ERROR) - { - if(_on_error_event_callback) _on_error_event_callback(); - } - - /* Assign new state to the member variable holding the state */ + + if(old_net_connection_state != next_net_connection_state) { + updateCallback(next_net_connection_state); + + /* It may happen that the local _current_net_connection_state + * is not updated by the updateConnectionState() call. This is the case for GenericConnection handler + * where the call of updateConnectionState() is replaced by the inner ConnectionHandler call + * that updates its state, but not the outer one. For this reason it is required to perform this call twice + */ _current_net_connection_state = next_net_connection_state; } } @@ -89,6 +69,46 @@ NetworkConnectionState ConnectionHandler::check() return _current_net_connection_state; } +NetworkConnectionState ConnectionHandler::updateConnectionState() { + NetworkConnectionState next_net_connection_state = _current_net_connection_state; + + /* While the state machine is implemented here, the concrete implementation of the + * states is done in the derived connection handlers. + */ + switch (_current_net_connection_state) + { + case NetworkConnectionState::INIT: next_net_connection_state = update_handleInit (); break; + case NetworkConnectionState::CONNECTING: next_net_connection_state = update_handleConnecting (); break; + case NetworkConnectionState::CONNECTED: next_net_connection_state = update_handleConnected (); break; + case NetworkConnectionState::DISCONNECTING: next_net_connection_state = update_handleDisconnecting(); break; + case NetworkConnectionState::DISCONNECTED: next_net_connection_state = update_handleDisconnected (); break; + case NetworkConnectionState::ERROR: break; + case NetworkConnectionState::CLOSED: break; + } + + /* Assign new state to the member variable holding the state */ + _current_net_connection_state = next_net_connection_state; + + return next_net_connection_state; +} + +void ConnectionHandler::updateCallback(NetworkConnectionState next_net_connection_state) { + + /* Check the next state to determine the kind of state conversion which has occurred (and call the appropriate callback) */ + if(next_net_connection_state == NetworkConnectionState::CONNECTED) + { + if(_on_connect_event_callback) _on_connect_event_callback(); + } + if(next_net_connection_state == NetworkConnectionState::DISCONNECTED) + { + if(_on_disconnect_event_callback) _on_disconnect_event_callback(); + } + if(next_net_connection_state == NetworkConnectionState::ERROR) + { + if(_on_error_event_callback) _on_error_event_callback(); + } +} + void ConnectionHandler::connect() { if (_current_net_connection_state != NetworkConnectionState::INIT && _current_net_connection_state != NetworkConnectionState::CONNECTING) diff --git a/src/ConnectionHandlerInterface.h b/src/ConnectionHandlerInterface.h index cde533af..a60da81f 100644 --- a/src/ConnectionHandlerInterface.h +++ b/src/ConnectionHandlerInterface.h @@ -102,6 +102,9 @@ class ConnectionHandler { protected: + virtual NetworkConnectionState updateConnectionState(); + virtual void updateCallback(NetworkConnectionState next_net_connection_state); + bool _keep_alive; NetworkAdapter _interface; From 0c341ad7c8a8066fb1664d4dccb9996b5b6c02e9 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Thu, 5 Dec 2024 10:44:46 +0100 Subject: [PATCH 168/203] readapting ConnectionHandler implementation to use setting struct --- src/CatM1ConnectionHandler.cpp | 29 +++++++---- src/CatM1ConnectionHandler.h | 9 +--- src/CellularConnectionHandler.cpp | 15 +++--- src/CellularConnectionHandler.h | 7 +-- src/EthernetConnectionHandler.cpp | 87 ++++++++++++++++--------------- src/EthernetConnectionHandler.h | 8 --- src/GSMConnectionHandler.cpp | 17 +++--- src/GSMConnectionHandler.h | 7 +-- src/LoRaConnectionHandler.cpp | 22 ++++---- src/LoRaConnectionHandler.h | 5 -- src/NBConnectionHandler.cpp | 19 ++++--- src/NBConnectionHandler.h | 7 +-- src/WiFiConnectionHandler.cpp | 18 ++++--- src/WiFiConnectionHandler.h | 6 +-- 14 files changed, 124 insertions(+), 132 deletions(-) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index 0263a397..b739bea3 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -28,16 +28,21 @@ CTOR/DTOR ******************************************************************************/ -CatM1ConnectionHandler::CatM1ConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, RadioAccessTechnologyType rat, uint32_t band, bool const keep_alive) +CatM1ConnectionHandler::CatM1ConnectionHandler() +: ConnectionHandler(true, NetworkAdapter::CATM1) { } + +CatM1ConnectionHandler::CatM1ConnectionHandler( + const char * pin, const char * apn, const char * login, const char * pass, + RadioAccessTechnologyType rat, uint32_t band, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::CATM1} -, _pin(pin) -, _apn(apn) -, _login(login) -, _pass(pass) -, _rat(rat) -, _band(band) { - + _settings.type = NetworkAdapter::CATM1; + 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); + strncpy(_settings.catm1.pass, pass, sizeof(_settings.catm1.pass)-1); + _settings.catm1.rat = static_cast(rat); + _settings.catm1.band = band; } /****************************************************************************** @@ -64,7 +69,13 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleInit() NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting() { - if(!GSM.begin(_pin, _apn, _login, _pass, _rat, _band)) + if(!GSM.begin( + _settings.catm1.pin, + _settings.catm1.apn, + _settings.catm1.login, + _settings.catm1.pass, + static_cast(_settings.catm1.rat) , + _settings.catm1.band)) { Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); return NetworkConnectionState::ERROR; diff --git a/src/CatM1ConnectionHandler.h b/src/CatM1ConnectionHandler.h index 33ac9fea..67f317b7 100644 --- a/src/CatM1ConnectionHandler.h +++ b/src/CatM1ConnectionHandler.h @@ -40,6 +40,7 @@ class CatM1ConnectionHandler : public ConnectionHandler { public: + CatM1ConnectionHandler(); CatM1ConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, RadioAccessTechnologyType rat = CATM1, uint32_t band = BAND_3 | BAND_20 | BAND_19, bool const keep_alive = true); @@ -59,14 +60,6 @@ class CatM1ConnectionHandler : public ConnectionHandler private: - const char * _pin; - const char * _apn; - const char * _login; - const char * _pass; - - RadioAccessTechnologyType _rat; - uint32_t _band; - GSMUDP _gsm_udp; GSMClient _gsm_client; }; diff --git a/src/CellularConnectionHandler.cpp b/src/CellularConnectionHandler.cpp index 2e4499a0..d0877d3e 100644 --- a/src/CellularConnectionHandler.cpp +++ b/src/CellularConnectionHandler.cpp @@ -21,14 +21,17 @@ /****************************************************************************** CTOR/DTOR ******************************************************************************/ +CellularConnectionHandler::CellularConnectionHandler() +: ConnectionHandler(true, NetworkAdapter::CELL) {} CellularConnectionHandler::CellularConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::CELL} -, _pin(pin) -, _apn(apn) -, _login(login) -, _pass(pass) { + _settings.type = NetworkAdapter::CELL; + strncpy(_settings.cell.pin, pin, sizeof(_settings.cell.pin)-1); + strncpy(_settings.cell.apn, apn, sizeof(_settings.cell.apn)-1); + strncpy(_settings.cell.login, login, sizeof(_settings.cell.login)-1); + strncpy(_settings.cell.pass, pass, sizeof(_settings.cell.pass)-1); } @@ -55,7 +58,7 @@ NetworkConnectionState CellularConnectionHandler::update_handleInit() { _cellular.begin(); _cellular.setDebugStream(Serial); - if (String(_pin).length() > 0 && !_cellular.unlockSIM(_pin)) { + if (strlen(_settings.cell.pin) > 0 && !_cellular.unlockSIM(_settings.cell.pin)) { Debug.print(DBG_ERROR, F("SIM not present or wrong PIN")); return NetworkConnectionState::ERROR; } @@ -64,7 +67,7 @@ NetworkConnectionState CellularConnectionHandler::update_handleInit() NetworkConnectionState CellularConnectionHandler::update_handleConnecting() { - if (!_cellular.connect(_apn, _login, _pass)) { + if (!_cellular.connect(String(_settings.cell.apn), String(_settings.cell.login), String(_settings.cell.pass))) { Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); return NetworkConnectionState::ERROR; } diff --git a/src/CellularConnectionHandler.h b/src/CellularConnectionHandler.h index 2addd29b..fcc02c66 100644 --- a/src/CellularConnectionHandler.h +++ b/src/CellularConnectionHandler.h @@ -33,7 +33,7 @@ class CellularConnectionHandler : public ConnectionHandler { public: - + CellularConnectionHandler(); CellularConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, bool const keep_alive = true); @@ -53,11 +53,6 @@ class CellularConnectionHandler : public ConnectionHandler private: - const char * _pin; - const char * _apn; - const char * _login; - const char * _pass; - ArduinoCellular _cellular; TinyGsmClient _gsm_client = _cellular.getNetworkClient(); }; diff --git a/src/EthernetConnectionHandler.cpp b/src/EthernetConnectionHandler.cpp index 14f7aee4..af5b118e 100644 --- a/src/EthernetConnectionHandler.cpp +++ b/src/EthernetConnectionHandler.cpp @@ -25,51 +25,41 @@ CTOR/DTOR ******************************************************************************/ -EthernetConnectionHandler::EthernetConnectionHandler(unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive) -: ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} -,_ip{INADDR_NONE} -,_dns{INADDR_NONE} -,_gateway{INADDR_NONE} -,_netmask{INADDR_NONE} -,_timeout{timeout} -,_response_timeout{responseTimeout} -{ - +static inline void fromIPAddress(const IPAddress src, models::ip_addr& dst) { + if(src.type() == IPv4) { + dst.dword[IPADDRESS_V4_DWORD_INDEX] = (uint32_t)src; + } else if(src.type() == IPv6) { + for(uint8_t i=0; i static ip configuration + if (ip != INADDR_NONE) { + if (Ethernet.begin(nullptr, ip, + IPAddress(_settings.eth.dns.type, _settings.eth.dns.bytes), + IPAddress(_settings.eth.gateway.type, _settings.eth.gateway.bytes), + IPAddress(_settings.eth.netmask.type, _settings.eth.netmask.bytes), + _settings.eth.timeout, + _settings.eth.response_timeout) == 0) { + Debug.print(DBG_ERROR, F("Failed to configure Ethernet, check cable connection")); - Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", _timeout, _response_timeout); + Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", + _settings.eth.timeout, _settings.eth.response_timeout); return NetworkConnectionState::CONNECTING; } + // An ip address is not provided -> dhcp configuration } else { - if (Ethernet.begin(nullptr, _timeout, _response_timeout) == 0) { + if (Ethernet.begin(nullptr, _settings.eth.timeout, _settings.eth.response_timeout) == 0) { Debug.print(DBG_ERROR, F("Waiting Ethernet configuration from DHCP server, check cable connection")); - Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", _timeout, _response_timeout); + Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", + _settings.eth.timeout, _settings.eth.response_timeout); + return NetworkConnectionState::CONNECTING; } } diff --git a/src/EthernetConnectionHandler.h b/src/EthernetConnectionHandler.h index 35a02cd9..8ddbbe42 100644 --- a/src/EthernetConnectionHandler.h +++ b/src/EthernetConnectionHandler.h @@ -64,14 +64,6 @@ class EthernetConnectionHandler : public ConnectionHandler private: - IPAddress _ip; - IPAddress _dns; - IPAddress _gateway; - IPAddress _netmask; - - unsigned long _timeout; - unsigned long _response_timeout; - EthernetUDP _eth_udp; EthernetClient _eth_client; diff --git a/src/GSMConnectionHandler.cpp b/src/GSMConnectionHandler.cpp index 34bf1792..75f9e536 100644 --- a/src/GSMConnectionHandler.cpp +++ b/src/GSMConnectionHandler.cpp @@ -46,15 +46,17 @@ __attribute__((weak)) void mkr_gsm_feed_watchdog() /****************************************************************************** CTOR/DTOR ******************************************************************************/ +GSMConnectionHandler::GSMConnectionHandler() +: ConnectionHandler(true, NetworkAdapter::GSM) {} GSMConnectionHandler::GSMConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::GSM} -, _pin(pin) -, _apn(apn) -, _login(login) -, _pass(pass) { - + _settings.type = NetworkAdapter::GSM; + strncpy(_settings.gsm.pin, pin, sizeof(_settings.gsm.pin)-1); + strncpy(_settings.gsm.apn, apn, sizeof(_settings.gsm.apn)-1); + strncpy(_settings.gsm.login, login, sizeof(_settings.gsm.login)-1); + strncpy(_settings.gsm.pass, pass, sizeof(_settings.gsm.pass)-1); } /****************************************************************************** @@ -74,7 +76,7 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit() { mkr_gsm_feed_watchdog(); - if (_gsm.begin(_pin) != GSM_READY) + if (_gsm.begin(_settings.gsm.pin) != GSM_READY) { Debug.print(DBG_ERROR, F("SIM not present or wrong PIN")); return NetworkConnectionState::ERROR; @@ -88,7 +90,8 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit() mkr_gsm_feed_watchdog(); - GSM3_NetworkStatus_t const network_status = _gprs.attachGPRS(_apn, _login, _pass, true); + GSM3_NetworkStatus_t const network_status = _gprs.attachGPRS( + _settings.gsm.apn, _settings.gsm.login, _settings.gsm.pass, true); Debug.print(DBG_DEBUG, F("GPRS.attachGPRS(): %d"), network_status); if (network_status == GSM3_NetworkStatus_t::ERROR) { diff --git a/src/GSMConnectionHandler.h b/src/GSMConnectionHandler.h index 1f3db49a..891fb989 100644 --- a/src/GSMConnectionHandler.h +++ b/src/GSMConnectionHandler.h @@ -39,7 +39,7 @@ class GSMConnectionHandler : public ConnectionHandler { public: - + GSMConnectionHandler(); GSMConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, bool const keep_alive = true); @@ -59,11 +59,6 @@ class GSMConnectionHandler : public ConnectionHandler private: - const char * _pin; - const char * _apn; - const char * _login; - const char * _pass; - GSM _gsm; GPRS _gprs; GSMUDP _gsm_udp; diff --git a/src/LoRaConnectionHandler.cpp b/src/LoRaConnectionHandler.cpp index 1f454a51..bc753fd2 100644 --- a/src/LoRaConnectionHandler.cpp +++ b/src/LoRaConnectionHandler.cpp @@ -46,13 +46,13 @@ typedef enum ******************************************************************************/ LoRaConnectionHandler::LoRaConnectionHandler(char const * appeui, char const * appkey, _lora_band const band, char const * channelMask, _lora_class const device_class) : ConnectionHandler{false, NetworkAdapter::LORA} -, _appeui(appeui) -, _appkey(appkey) -, _band(band) -, _channelMask(channelMask) -, _device_class(device_class) { - + _settings.type = NetworkAdapter::LORA; + strncpy(_settings.lora.appeui, appeui, sizeof(_settings.lora.appeui)-1); + strncpy(_settings.lora.appkey, appkey, sizeof(_settings.lora.appkey)-1); + _settings.lora.band = band; + strncpy(_settings.lora.channelMask, channelMask, sizeof(_settings.lora.channelMask)-1); + _settings.lora.deviceClass = device_class; } /****************************************************************************** @@ -103,18 +103,18 @@ bool LoRaConnectionHandler::available() NetworkConnectionState LoRaConnectionHandler::update_handleInit() { - if (!_modem.begin(_band)) + if (!_modem.begin((_lora_band)_settings.lora.band)) { Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry.")); return NetworkConnectionState::ERROR; } // Set channelmask based on configuration - if (_channelMask) { - _modem.sendMask(_channelMask); + if (_settings.lora.channelMask) { + _modem.sendMask(_settings.lora.channelMask); } //A delay is required between _modem.begin(band) and _modem.joinOTAA(appeui, appkey) in order to let the chip to be correctly initialized before the connection attempt delay(100); - _modem.configureClass(_device_class); + _modem.configureClass((_lora_class)_settings.lora.deviceClass); delay(100); Debug.print(DBG_INFO, F("Connecting to the network")); return NetworkConnectionState::CONNECTING; @@ -122,7 +122,7 @@ NetworkConnectionState LoRaConnectionHandler::update_handleInit() NetworkConnectionState LoRaConnectionHandler::update_handleConnecting() { - bool const network_status = _modem.joinOTAA(_appeui, _appkey); + bool const network_status = _modem.joinOTAA(_settings.lora.appeui, _settings.lora.appkey); if (network_status != true) { Debug.print(DBG_ERROR, F("Connection to the network failed")); diff --git a/src/LoRaConnectionHandler.h b/src/LoRaConnectionHandler.h index 3ddcca24..cecf8302 100644 --- a/src/LoRaConnectionHandler.h +++ b/src/LoRaConnectionHandler.h @@ -73,11 +73,6 @@ class LoRaConnectionHandler : public ConnectionHandler private: - char const * _appeui; - char const * _appkey; - _lora_band _band; - char const * _channelMask; - _lora_class _device_class; LoRaModem _modem; }; diff --git a/src/NBConnectionHandler.cpp b/src/NBConnectionHandler.cpp index eb72f3e7..02d62ba2 100644 --- a/src/NBConnectionHandler.cpp +++ b/src/NBConnectionHandler.cpp @@ -45,6 +45,10 @@ __attribute__((weak)) void mkr_nb_feed_watchdog() /****************************************************************************** CTOR/DTOR ******************************************************************************/ + +NBConnectionHandler::NBConnectionHandler() +: ConnectionHandler(true, NetworkAdapter::NB) {} + NBConnectionHandler::NBConnectionHandler(char const * pin, bool const keep_alive) : NBConnectionHandler(pin, "", keep_alive) { @@ -59,12 +63,12 @@ NBConnectionHandler::NBConnectionHandler(char const * pin, char const * apn, boo NBConnectionHandler::NBConnectionHandler(char const * pin, char const * apn, char const * login, char const * pass, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::NB} -, _pin(pin) -, _apn(apn) -, _login(login) -, _pass(pass) { - + _settings.type = NetworkAdapter::NB; + strncpy(_settings.nb.pin, pin, sizeof(_settings.nb.pin)-1); + strncpy(_settings.nb.apn, apn, sizeof(_settings.nb.apn)-1); + strncpy(_settings.nb.login, login, sizeof(_settings.nb.login)-1); + strncpy(_settings.nb.pass, pass, sizeof(_settings.nb.pass)-1); } /****************************************************************************** @@ -84,7 +88,10 @@ NetworkConnectionState NBConnectionHandler::update_handleInit() { mkr_nb_feed_watchdog(); - if (_nb.begin(_pin, _apn, _login, _pass) == NB_READY) + if (_nb.begin(_settings.nb.pin, + _settings.nb.apn, + _settings.nb.login, + _settings.nb.pass) == NB_READY) { Debug.print(DBG_INFO, F("SIM card ok")); _nb.setTimeout(NB_TIMEOUT); diff --git a/src/NBConnectionHandler.h b/src/NBConnectionHandler.h index fd2afb6c..6641bb69 100644 --- a/src/NBConnectionHandler.h +++ b/src/NBConnectionHandler.h @@ -39,7 +39,7 @@ class NBConnectionHandler : public ConnectionHandler { public: - + NBConnectionHandler(); NBConnectionHandler(char const * pin, bool const keep_alive = true); NBConnectionHandler(char const * pin, char const * apn, bool const keep_alive = true); NBConnectionHandler(char const * pin, char const * apn, char const * login, char const * pass, bool const keep_alive = true); @@ -63,11 +63,6 @@ class NBConnectionHandler : public ConnectionHandler void changeConnectionState(NetworkConnectionState _newState); - char const * _pin; - char const * _apn; - char const * _login; - char const * _pass; - NB _nb; GPRS _nb_gprs; NBUDP _nb_udp; diff --git a/src/WiFiConnectionHandler.cpp b/src/WiFiConnectionHandler.cpp index 0cd2e126..efc30fa9 100644 --- a/src/WiFiConnectionHandler.cpp +++ b/src/WiFiConnectionHandler.cpp @@ -35,12 +35,16 @@ static int const ESP_WIFI_CONNECTION_TIMEOUT = 3000; CTOR/DTOR ******************************************************************************/ +WiFiConnectionHandler::WiFiConnectionHandler() +: ConnectionHandler(true, NetworkAdapter::WIFI) { +} + WiFiConnectionHandler::WiFiConnectionHandler(char const * ssid, char const * pass, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::WIFI} -, _ssid{ssid} -, _pass{pass} { - + _settings.type = NetworkAdapter::WIFI; + strncpy(_settings.wifi.ssid, ssid, sizeof(_settings.wifi.ssid)-1); + strncpy(_settings.wifi.pwd, pass, sizeof(_settings.wifi.pwd)-1); } /****************************************************************************** @@ -99,7 +103,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() { if (WiFi.status() != WL_CONNECTED) { - WiFi.begin(_ssid, _pass); + WiFi.begin(_settings.wifi.ssid, _settings.wifi.pwd); #if defined(ARDUINO_ARCH_ESP8266) /* Wait connection otherwise board won't connect */ unsigned long start = millis(); @@ -113,7 +117,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() if (WiFi.status() != NETWORK_CONNECTED) { #if !defined(__AVR__) - Debug.print(DBG_ERROR, F("Connection to \"%s\" failed"), _ssid); + Debug.print(DBG_ERROR, F("Connection to \"%s\" failed"), _settings.wifi.ssid); Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); #endif return NetworkConnectionState::CONNECTING; @@ -121,7 +125,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() else { #if !defined(__AVR__) - Debug.print(DBG_INFO, F("Connected to \"%s\""), _ssid); + Debug.print(DBG_INFO, F("Connected to \"%s\""), _settings.wifi.ssid); #endif #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) configTime(0, 0, "time.arduino.cc", "pool.ntp.org", "time.nist.gov"); @@ -136,7 +140,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnected() { #if !defined(__AVR__) Debug.print(DBG_VERBOSE, F("WiFi.status(): %d"), WiFi.status()); - Debug.print(DBG_ERROR, F("Connection to \"%s\" lost."), _ssid); + Debug.print(DBG_ERROR, F("Connection to \"%s\" lost."), _settings.wifi.ssid); #endif if (_keep_alive) { diff --git a/src/WiFiConnectionHandler.h b/src/WiFiConnectionHandler.h index 2ee674a5..1d360b70 100644 --- a/src/WiFiConnectionHandler.h +++ b/src/WiFiConnectionHandler.h @@ -62,7 +62,7 @@ class WiFiConnectionHandler : public ConnectionHandler { public: - + WiFiConnectionHandler(); WiFiConnectionHandler(char const * ssid, char const * pass, bool const keep_alive = true); @@ -80,10 +80,6 @@ class WiFiConnectionHandler : public ConnectionHandler virtual NetworkConnectionState update_handleDisconnected () override; private: - - char const * _ssid; - char const * _pass; - WiFiUDP _wifi_udp; WiFiClient _wifi_client; }; From 4abd7a230edc22c59476fba88c6c9726d212da18 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Thu, 5 Dec 2024 10:33:51 +0100 Subject: [PATCH 169/203] defining a wrapper connection handler with the objective of being generic --- src/ConnectionHandlerInterface.h | 2 +- src/GenericConnectionHandler.cpp | 151 +++++++++++++++++++++++++++++++ src/GenericConnectionHandler.h | 73 +++++++++++++++ 3 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 src/GenericConnectionHandler.cpp create mode 100644 src/GenericConnectionHandler.h diff --git a/src/ConnectionHandlerInterface.h b/src/ConnectionHandlerInterface.h index a60da81f..80819605 100644 --- a/src/ConnectionHandlerInterface.h +++ b/src/ConnectionHandlerInterface.h @@ -51,7 +51,7 @@ class ConnectionHandler { virtual ~ConnectionHandler() {} - NetworkConnectionState check(); + virtual NetworkConnectionState check(); #if not defined(BOARD_HAS_LORA) virtual unsigned long getTime() = 0; diff --git a/src/GenericConnectionHandler.cpp b/src/GenericConnectionHandler.cpp new file mode 100644 index 00000000..f1f9eb6b --- /dev/null +++ b/src/GenericConnectionHandler.cpp @@ -0,0 +1,151 @@ +/* + This file is part of the Arduino_ConnectionHandler library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +/****************************************************************************** + INCLUDE + ******************************************************************************/ + +#include "GenericConnectionHandler.h" +#include "Arduino_ConnectionHandler.h" + +static inline ConnectionHandler* instantiate_handler(NetworkAdapter adapter); + +bool GenericConnectionHandler::updateSetting(const models::NetworkSetting& s) { + if(_ch != nullptr && _ch->_current_net_connection_state != NetworkConnectionState::INIT) { + // If the internal connection handler is already being used and not in INIT phase we cannot update the settings + return false; + } else if(_ch != nullptr && _ch->_current_net_connection_state == NetworkConnectionState::INIT && _interface != s.type) { + // If the internal connection handler is already being used and in INIT phase and the interface type is being changed + // -> we need to deallocate the previously allocated handler + + // if interface type is not being changed -> we just need to call updateSettings + delete _ch; + _ch = nullptr; + } + + if(_ch == nullptr) { + _ch = instantiate_handler(s.type); + } + + if(_ch != nullptr) { + _interface = s.type; + _ch->setKeepAlive(_keep_alive); + return _ch->updateSetting(s); + } else { + _interface = NetworkAdapter::NONE; + + return false; + } +} + +NetworkConnectionState GenericConnectionHandler::updateConnectionState() { + return _ch != nullptr ? _ch->updateConnectionState() : NetworkConnectionState::INIT; +} + +NetworkConnectionState GenericConnectionHandler::update_handleInit() { + return _ch != nullptr ? _ch->update_handleInit() : NetworkConnectionState::INIT; +} + +NetworkConnectionState GenericConnectionHandler::update_handleConnecting() { + return _ch != nullptr ? _ch->update_handleConnecting() : NetworkConnectionState::INIT; +} + +NetworkConnectionState GenericConnectionHandler::update_handleConnected() { + return _ch != nullptr ? _ch->update_handleConnected() : NetworkConnectionState::INIT; +} + +NetworkConnectionState GenericConnectionHandler::update_handleDisconnecting() { + return _ch != nullptr ? _ch->update_handleDisconnecting() : NetworkConnectionState::INIT; +} + +NetworkConnectionState GenericConnectionHandler::update_handleDisconnected() { + return _ch != nullptr ? _ch->update_handleDisconnected() : NetworkConnectionState::INIT; +} + +#if not (defined(BOARD_HAS_LORA) or defined(BOARD_HAS_NOTECARD)) +unsigned long GenericConnectionHandler::getTime() { + return _ch != nullptr ? _ch->getTime() : 0; +} + +Client & GenericConnectionHandler::getClient() { + return _ch->getClient(); // NOTE _ch may be nullptr +} + +UDP & GenericConnectionHandler::getUDP() { + return _ch->getUDP(); // NOTE _ch may be nullptr +} + +#endif // not (defined(BOARD_HAS_LORA) or defined(BOARD_HAS_NOTECARD)) + +void GenericConnectionHandler::connect() { + if(_ch!=nullptr) { + _ch->connect(); + } + ConnectionHandler::connect(); +} + +void GenericConnectionHandler::disconnect() { + if(_ch!=nullptr) { + _ch->disconnect(); + } + ConnectionHandler::disconnect(); +} + +void GenericConnectionHandler::setKeepAlive(bool keep_alive) { + _keep_alive = keep_alive; + + if(_ch!=nullptr) { + _ch->setKeepAlive(keep_alive); + } +} + +static inline ConnectionHandler* instantiate_handler(NetworkAdapter adapter) { + switch(adapter) { + #if defined(BOARD_HAS_WIFI) + case NetworkAdapter::WIFI: + return new WiFiConnectionHandler(); + break; + #endif + + #if defined(BOARD_HAS_ETHERNET) + case NetworkAdapter::ETHERNET: + return new EthernetConnectionHandler(); + break; + #endif + + #if defined(BOARD_HAS_NB) + case NetworkAdapter::NB: + return new NBConnectionHandler(); + break; + #endif + + #if defined(BOARD_HAS_GSM) + case NetworkAdapter::GSM: + return new GSMConnectionHandler(); + break; + #endif + + #if defined(BOARD_HAS_CATM1_NBIOT) + case NetworkAdapter::CATM1: + return new CatM1ConnectionHandler(); + break; + #endif + + #if defined(BOARD_HAS_CELLULAR) + case NetworkAdapter::CELL: + return new CellularConnectionHandler(); + break; + #endif + + default: + Debug.print(DBG_ERROR, "Network adapter not supported by this platform: %d", adapter); + return nullptr; + } +} diff --git a/src/GenericConnectionHandler.h b/src/GenericConnectionHandler.h new file mode 100644 index 00000000..e1b315e4 --- /dev/null +++ b/src/GenericConnectionHandler.h @@ -0,0 +1,73 @@ +/* + This file is part of the Arduino_ConnectionHandler library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#ifndef ARDUINO_GENERIC_CONNECTION_HANDLER_H_ +#define ARDUINO_GENERIC_CONNECTION_HANDLER_H_ + +/****************************************************************************** + INCLUDE + ******************************************************************************/ + +#include "ConnectionHandlerInterface.h" + +/****************************************************************************** + CLASS DECLARATION + ******************************************************************************/ + +/** GenericConnectionHandler class + * This class aims to wrap a connectionHandler and provide a generic way to + * instantiate a specific connectionHandler type + */ +class GenericConnectionHandler : public ConnectionHandler +{ + public: + + GenericConnectionHandler(bool const keep_alive=true): ConnectionHandler(keep_alive), _ch(nullptr) {} + + #if defined(BOARD_HAS_NOTECARD) || defined(BOARD_HAS_LORA) + virtual bool available() = 0; + virtual int read() = 0; + virtual int write(const uint8_t *buf, size_t size) = 0; + #else + unsigned long getTime() override; + + /* + * NOTE: The following functions have a huge risk of returning a reference to a non existing memory location + * It is important to make sure that the internal connection handler is already allocated before calling them + * When updateSettings is called and the internal connectionHandler is reallocated the references to TCP and UDP + * handles should be deleted. + */ + Client & getClient() override; + UDP & getUDP() override; + #endif + + bool updateSetting(const models::NetworkSetting& s) override; + + void connect() override; + void disconnect() override; + + void setKeepAlive(bool keep_alive=true) override; + + protected: + + NetworkConnectionState updateConnectionState() override; + + NetworkConnectionState update_handleInit () override; + NetworkConnectionState update_handleConnecting () override; + NetworkConnectionState update_handleConnected () override; + NetworkConnectionState update_handleDisconnecting() override; + NetworkConnectionState update_handleDisconnected () override; + + private: + + ConnectionHandler* _ch; +}; + +#endif /* ARDUINO_GENERIC_CONNECTION_HANDLER_H_ */ From 773544342772a56076c4c3c22ee89be25ffb86c9 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Tue, 24 Sep 2024 12:33:13 +0200 Subject: [PATCH 170/203] adding NONE as interface in order to make sense of GenericConnectionHandler --- src/ConnectionHandlerDefinitions.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ConnectionHandlerDefinitions.h b/src/ConnectionHandlerDefinitions.h index 4f295592..9297dc0c 100644 --- a/src/ConnectionHandlerDefinitions.h +++ b/src/ConnectionHandlerDefinitions.h @@ -174,6 +174,7 @@ enum class NetworkConnectionEvent { }; enum class NetworkAdapter { + NONE, WIFI, ETHERNET, NB, From 2084b1697d05c1d5beed96a4b770cfa89f002e08 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Thu, 26 Sep 2024 11:27:36 +0200 Subject: [PATCH 171/203] EthernetConnectionHandler improving formatting for constructors and removing redundant constructor with strings --- src/EthernetConnectionHandler.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/EthernetConnectionHandler.h b/src/EthernetConnectionHandler.h index 8ddbbe42..738b6a8c 100644 --- a/src/EthernetConnectionHandler.h +++ b/src/EthernetConnectionHandler.h @@ -44,16 +44,24 @@ class EthernetConnectionHandler : public ConnectionHandler { public: - EthernetConnectionHandler(unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true); - EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true); - EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true); - + EthernetConnectionHandler( + unsigned long const timeout = 15000, + unsigned long const responseTimeout = 4000, + bool const keep_alive = true); + + EthernetConnectionHandler( + const IPAddress ip, + const IPAddress dns, + const IPAddress gateway, + const IPAddress netmask, + unsigned long const timeout = 15000, + unsigned long const responseTimeout = 4000, + bool const keep_alive = true); virtual unsigned long getTime() override { return 0; } virtual Client & getClient() override{ return _eth_client; } virtual UDP & getUDP() override { return _eth_udp; } - protected: virtual NetworkConnectionState update_handleInit () override; From 9a641912d9dd2bfdfd24a88c4576d3dfcd950a02 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 25 Sep 2024 12:22:28 +0200 Subject: [PATCH 172/203] adding an example for GenericConnectionHandler --- .../GenericConnectionHandlerDemo.ino | 139 ++++++++++++++++++ .../arduino_secrets.h | 19 +++ 2 files changed, 158 insertions(+) create mode 100644 examples/GenericConnectionHandlerDemo/GenericConnectionHandlerDemo.ino create mode 100644 examples/GenericConnectionHandlerDemo/arduino_secrets.h diff --git a/examples/GenericConnectionHandlerDemo/GenericConnectionHandlerDemo.ino b/examples/GenericConnectionHandlerDemo/GenericConnectionHandlerDemo.ino new file mode 100644 index 00000000..2ce18f7e --- /dev/null +++ b/examples/GenericConnectionHandlerDemo/GenericConnectionHandlerDemo.ino @@ -0,0 +1,139 @@ +/* SECRET_ fields are in `arduino_secrets.h` (included below) + * + * If using a WiFi board (Arduino MKR1000, MKR WiFi 1010, Nano 33 IoT, UNO + * WiFi Rev 2 or ESP8266/32), create a WiFiConnectionHandler object by adding + * Network Name (SECRET_WIFI_SSID) and password (SECRET_WIFI_PASS) in the + * arduino_secrets.h file (or Secrets tab in Create Web Editor). + * + * WiFiConnectionHandler conMan(SECRET_WIFI_SSID, SECRET_WIFI_PASS); + * + * If using a MKR GSM 1400 or other GSM boards supporting the same API you'll + * need a GSMConnectionHandler object as follows + * + * GSMConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); + * + * If using a MKR NB1500 you'll need a NBConnectionHandler object as follows + * + * NBConnectionHandler conMan(SECRET_PIN); + * + * If using a Portenta + Ethernet shield you'll need a EthernetConnectionHandler object as follows: + * + * DHCP mode + * EthernetConnectionHandler conMan; + * + * Manual configuration + * EthernetConnectionHandler conMan(SECRET_IP, SECRET_DNS, SECRET_GATEWAY, SECRET_NETMASK); + * + * Manual configuration will fallback on DHCP mode if SECRET_IP is invalid or equal to INADDR_NONE. + * + */ + +#include + +#include "arduino_secrets.h" + +#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)) + #error "Please check Arduino Connection Handler supported boards list: https://github.com/arduino-libraries/Arduino_ConnectionHandler/blob/master/README.md" +#endif + +GenericConnectionHandler conMan; + + +bool attemptConnect = false; +uint32_t lastConnToggleMs = 0; + +void setup() { + /* Initialize serial debug port and wait up to 5 seconds for port to open */ + Serial.begin(9600); + for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { } + +#ifndef __AVR__ + /* Set the debug message level: + * - DBG_ERROR: Only show error messages + * - DBG_WARNING: Show warning and error messages + * - DBG_INFO: Show info, warning, and error messages + * - DBG_DEBUG: Show debug, info, warning, and error messages + * - DBG_VERBOSE: Show all messages + */ + setDebugMessageLevel(DBG_INFO); +#endif + + models::NetworkSetting setting = models::settingsDefault(NetworkAdapter::WIFI); + + strcpy(setting.wifi.ssid, SECRET_WIFI_SSID); + strcpy(setting.wifi.pwd, SECRET_WIFI_PASS); + + /* Add callbacks to the ConnectionHandler object to get notified of network + * connection events. */ + conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect); + conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect); + conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError); + + conMan.updateSetting(setting); + Serial.print("Network Adapter Interface: "); + switch (conMan.getInterface()) { + case NetworkAdapter::WIFI: + Serial.println("Wi-Fi"); + break; + case NetworkAdapter::ETHERNET: + Serial.println("Ethernet"); + break; + case NetworkAdapter::NB: + Serial.println("Narrowband"); + break; + case NetworkAdapter::GSM: + Serial.println("GSM"); + break; + case NetworkAdapter::LORA: + Serial.println("LoRa"); + break; + case NetworkAdapter::CATM1: + Serial.println("Category M1"); + break; + case NetworkAdapter::CELL: + Serial.println("Cellular"); + break; + default: + Serial.println("Unknown"); + break; + } +} + +void loop() { + /* Toggle the connection every `CONN_TOGGLE_MS` milliseconds */ + if ((millis() - lastConnToggleMs) > CONN_TOGGLE_MS) { + Serial.println("Toggling connection..."); + if (attemptConnect) { + conMan.connect(); + } else { + conMan.disconnect(); + } + attemptConnect = !attemptConnect; + lastConnToggleMs = millis(); + } + + /* The following code keeps on running connection workflows on our + * ConnectionHandler object, hence allowing reconnection in case of failure + * and notification of connect/disconnect event if enabled (see + * addConnectCallback/addDisconnectCallback) NOTE: any use of delay() within + * the loop or methods called from it will delay the execution of .update(), + * which might not guarantee the correct functioning of the ConnectionHandler + * object. + */ + conMan.check(); +} + +void onNetworkConnect() { + Serial.println(">>>> CONNECTED to network"); +} + +void onNetworkDisconnect() { + Serial.println(">>>> DISCONNECTED from network"); +} + +void onNetworkError() { + Serial.println(">>>> ERROR"); +} diff --git a/examples/GenericConnectionHandlerDemo/arduino_secrets.h b/examples/GenericConnectionHandlerDemo/arduino_secrets.h new file mode 100644 index 00000000..cecefa42 --- /dev/null +++ b/examples/GenericConnectionHandlerDemo/arduino_secrets.h @@ -0,0 +1,19 @@ +// Required for WiFiConnectionHandler +const char SECRET_WIFI_SSID[] = "SSID"; +const char SECRET_WIFI_PASS[] = "PASSWORD"; + +// Required for GSMConnectionHandler +const char SECRET_APN[] = "MOBILE PROVIDER APN ADDRESS"; +const char SECRET_PIN[] = "0000"; // Required for NBConnectionHandler +const char SECRET_GSM_USER[] = "GSM USERNAME"; +const char SECRET_GSM_PASS[] = "GSM PASSWORD"; + +// Required for LoRaConnectionHandler +const char SECRET_APP_EUI[] = "APP_EUI"; +const char SECRET_APP_KEY[] = "APP_KEY"; + +// Required for EthernetConnectionHandler (without DHCP mode) +const char SECRET_IP[] = "IP ADDRESS"; +const char SECRET_DNS[] = "DNS ADDRESS"; +const char SECRET_GATEWAY[] = "GATEWAY ADDRESS"; +const char SECRET_NETMASK[] = "NETWORK MASK"; From 2760757e0a050a9278a048f7c6ac97d1bff06caa Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 22 Jan 2025 13:22:57 +0100 Subject: [PATCH 173/203] adding a function to get the dafault initialization values for NetworkSetting --- src/connectionHandlerModels/settings.h | 2 + .../settings_default.h | 72 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/connectionHandlerModels/settings_default.h diff --git a/src/connectionHandlerModels/settings.h b/src/connectionHandlerModels/settings.h index b47960c4..40319d66 100644 --- a/src/connectionHandlerModels/settings.h +++ b/src/connectionHandlerModels/settings.h @@ -126,3 +126,5 @@ namespace models { }; }; } + +#include "settings_default.h" diff --git a/src/connectionHandlerModels/settings_default.h b/src/connectionHandlerModels/settings_default.h new file mode 100644 index 00000000..dc9a4efd --- /dev/null +++ b/src/connectionHandlerModels/settings_default.h @@ -0,0 +1,72 @@ +/* + This file is part of the Arduino_ConnectionHandler library. + + Copyright (c) 2024 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#pragma once +#include "settings.h" + +namespace models { + + /* + * if the cpp version is older than cpp14 then a constexpr function cannot include + * other than a simple return statement, thsu we can define it only as inline + */ + #if __cplusplus > 201103L + constexpr NetworkSetting settingsDefault(NetworkAdapter type) { + #else + inline NetworkSetting settingsDefault(NetworkAdapter type) { + #endif + + NetworkSetting res = {type}; + + switch(type) { + #if defined(BOARD_HAS_ETHERNET) + case NetworkAdapter::ETHERNET: + res.eth.timeout = 15000; + res.eth.response_timeout = 4000; + break; + #endif //defined(BOARD_HAS_ETHERNET) + + #if defined(BOARD_HAS_CATM1_NBIOT) + case NetworkAdapter::CATM1: + res.catm1.rat = 7; // CATM1 + res.catm1.band = 0x04 | 0x80000 | 0x40000; // BAND_3 | BAND_20 | BAND_19 + break; + #endif //defined(BOARD_HAS_CATM1_NBIOT) + + #if defined(BOARD_HAS_LORA) + case NetworkAdapter::LORA: + res.lora.band = 5; // _lora_band::EU868 + res.lora.channelMask[0] = '\0'; + res.lora.deviceClass = 'A'; // _lora_class::CLASS_A + break; + #endif //defined(BOARD_HAS_LORA) + + #if defined(BOARD_HAS_WIFI) + case NetworkAdapter::WIFI: // nothing todo, default optional values are fine with 0 + #endif //defined(BOARD_HAS_WIFI) + + #if defined(BOARD_HAS_NB) + case NetworkAdapter::NB: // nothing todo, default optional values are fine with 0 + #endif //defined(BOARD_HAS_NB) + + #if defined(BOARD_HAS_GSM) + case NetworkAdapter::GSM: // nothing todo, default optional values are fine with 0 + #endif //defined(BOARD_HAS_GSM) + + #if defined(BOARD_HAS_CELLULAR) + case NetworkAdapter::CELL: // nothing todo, default optional values are fine with 0 + #endif //defined(BOARD_HAS_CELLULAR) + default: + (void) 0; + } + + return res; + } +} From 12a4c635de5a74ddc2a073882c2d93affcc3b091 Mon Sep 17 00:00:00 2001 From: fabik111 Date: Mon, 23 Dec 2024 20:38:58 +0100 Subject: [PATCH 174/203] set connected state after checking internet availability use ping for all connectivity compile fix for esp8266 and esp32 remove check ping for mkrnb --- src/CatM1ConnectionHandler.cpp | 30 +++++++++++++++++++++------ src/CellularConnectionHandler.cpp | 19 +++++++++++++---- src/EthernetConnectionHandler.cpp | 34 +++++++++++++++++++++++-------- src/WiFiConnectionHandler.cpp | 28 +++++++++++++++++++------ 4 files changed, 87 insertions(+), 24 deletions(-) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index b739bea3..899d7c35 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -64,11 +64,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleInit() pinMode(ON_MKR2, OUTPUT); digitalWrite(ON_MKR2, HIGH); #endif - return NetworkConnectionState::CONNECTING; -} -NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting() -{ if(!GSM.begin( _settings.catm1.pin, _settings.catm1.apn, @@ -80,8 +76,30 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting() Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); return NetworkConnectionState::ERROR; } - Debug.print(DBG_INFO, F("Connected to Network")); - return NetworkConnectionState::CONNECTED; + + + return NetworkConnectionState::CONNECTING; +} + +NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting() +{ + if (!GSM.isConnected()) + { + return NetworkConnectionState::INIT; + } + int 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)]); + return NetworkConnectionState::CONNECTING; + } + else + { + Debug.print(DBG_INFO, F("Connected to Internet")); + return NetworkConnectionState::CONNECTED; + } } NetworkConnectionState CatM1ConnectionHandler::update_handleConnected() diff --git a/src/CellularConnectionHandler.cpp b/src/CellularConnectionHandler.cpp index d0877d3e..59be8026 100644 --- a/src/CellularConnectionHandler.cpp +++ b/src/CellularConnectionHandler.cpp @@ -62,16 +62,27 @@ NetworkConnectionState CellularConnectionHandler::update_handleInit() Debug.print(DBG_ERROR, F("SIM not present or wrong PIN")); return NetworkConnectionState::ERROR; } - return NetworkConnectionState::CONNECTING; -} -NetworkConnectionState CellularConnectionHandler::update_handleConnecting() -{ if (!_cellular.connect(String(_settings.cell.apn), String(_settings.cell.login), String(_settings.cell.pass))) { Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); return NetworkConnectionState::ERROR; } Debug.print(DBG_INFO, F("Connected to Network")); + return NetworkConnectionState::CONNECTING; +} + +NetworkConnectionState CellularConnectionHandler::update_handleConnecting() +{ + if (!_cellular.isConnectedToInternet()) { + return NetworkConnectionState::INIT; + } + + if(getTime() == 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)]); + return NetworkConnectionState::CONNECTING; + } + return NetworkConnectionState::CONNECTED; } diff --git a/src/EthernetConnectionHandler.cpp b/src/EthernetConnectionHandler.cpp index af5b118e..2c9049ce 100644 --- a/src/EthernetConnectionHandler.cpp +++ b/src/EthernetConnectionHandler.cpp @@ -20,6 +20,7 @@ #ifdef BOARD_HAS_ETHERNET /* Only compile if the board has ethernet */ #include "EthernetConnectionHandler.h" +#include /****************************************************************************** CTOR/DTOR @@ -72,11 +73,6 @@ NetworkConnectionState EthernetConnectionHandler::update_handleInit() Debug.print(DBG_ERROR, F("Error, ethernet shield was not found.")); return NetworkConnectionState::ERROR; } - return NetworkConnectionState::CONNECTING; -} - -NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() -{ IPAddress ip(_settings.eth.ip.type, _settings.eth.ip.bytes); // An ip address is provided -> static ip configuration @@ -91,7 +87,7 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() Debug.print(DBG_ERROR, F("Failed to configure Ethernet, check cable connection")); Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", _settings.eth.timeout, _settings.eth.response_timeout); - return NetworkConnectionState::CONNECTING; + return NetworkConnectionState::INIT; } // An ip address is not provided -> dhcp configuration } else { @@ -100,11 +96,33 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", _settings.eth.timeout, _settings.eth.response_timeout); - return NetworkConnectionState::CONNECTING; + return NetworkConnectionState::INIT; } } - return NetworkConnectionState::CONNECTED; + return NetworkConnectionState::CONNECTING; +} + +NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() +{ + if (Ethernet.linkStatus() == LinkOFF) { + return NetworkConnectionState::INIT; + } + + int ping_result = Ethernet.ping("time.arduino.cc"); + Debug.print(DBG_INFO, F("Ethernet.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)]); + return NetworkConnectionState::CONNECTING; + } + else + { + Debug.print(DBG_INFO, F("Connected to Internet")); + return NetworkConnectionState::CONNECTED; + } + } NetworkConnectionState EthernetConnectionHandler::update_handleConnected() diff --git a/src/WiFiConnectionHandler.cpp b/src/WiFiConnectionHandler.cpp index efc30fa9..4e2d9a85 100644 --- a/src/WiFiConnectionHandler.cpp +++ b/src/WiFiConnectionHandler.cpp @@ -96,11 +96,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() #else WiFi.mode(WIFI_STA); #endif /* #if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) */ - return NetworkConnectionState::CONNECTING; -} -NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() -{ if (WiFi.status() != WL_CONNECTED) { WiFi.begin(_settings.wifi.ssid, _settings.wifi.pwd); @@ -120,7 +116,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() Debug.print(DBG_ERROR, F("Connection to \"%s\" failed"), _settings.wifi.ssid); Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); #endif - return NetworkConnectionState::CONNECTING; + return NetworkConnectionState::INIT; } else { @@ -130,8 +126,28 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) configTime(0, 0, "time.arduino.cc", "pool.ntp.org", "time.nist.gov"); #endif - return NetworkConnectionState::CONNECTED; + return NetworkConnectionState::CONNECTING; + } +} + +NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() +{ + if (WiFi.status() != WL_CONNECTED){ + return NetworkConnectionState::INIT; } + #if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) + int ping_result = WiFi.ping("time.arduino.cc"); + Debug.print(DBG_INFO, F("WiFi.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)]); + return NetworkConnectionState::CONNECTING; + } + #endif + Debug.print(DBG_INFO, F("Connected to Internet")); + return NetworkConnectionState::CONNECTED; + } NetworkConnectionState WiFiConnectionHandler::update_handleConnected() From a5cf9a06c9d40c303cb923d43a43e3cbd8250672 Mon Sep 17 00:00:00 2001 From: fabik111 Date: Wed, 15 Jan 2025 15:38:42 +0100 Subject: [PATCH 175/203] update init interval --- src/ConnectionHandlerDefinitions.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ConnectionHandlerDefinitions.h b/src/ConnectionHandlerDefinitions.h index 9297dc0c..4cefc5de 100644 --- a/src/ConnectionHandlerDefinitions.h +++ b/src/ConnectionHandlerDefinitions.h @@ -191,12 +191,12 @@ enum class NetworkAdapter { static unsigned int const CHECK_INTERVAL_TABLE[] = { - /* INIT */ 100, #if defined(BOARD_HAS_NOTECARD) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - /* CONNECTING */ 4000, + /* INIT */ 4000, #else - /* CONNECTING */ 500, + /* INIT */ 500, #endif + /* CONNECTING */ 500, /* CONNECTED */ 10000, /* DISCONNECTING */ 100, /* DISCONNECTED */ 1000, From c2a81e593716b752dcec7eb6c84a44512d4c1092 Mon Sep 17 00:00:00 2001 From: fabik111 Date: Tue, 8 Apr 2025 11:15:25 +0200 Subject: [PATCH 176/203] enable or disable check internet availability --- src/CatM1ConnectionHandler.cpp | 7 +++++-- src/CellularConnectionHandler.cpp | 4 ++++ src/ConnectionHandlerInterface.cpp | 1 + src/ConnectionHandlerInterface.h | 4 ++++ src/EthernetConnectionHandler.cpp | 4 ++++ src/GSMConnectionHandler.cpp | 6 ++++++ src/GenericConnectionHandler.cpp | 1 + src/WiFiConnectionHandler.cpp | 5 +++++ 8 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index 899d7c35..2a63dea0 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -76,8 +76,6 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleInit() Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); return NetworkConnectionState::ERROR; } - - return NetworkConnectionState::CONNECTING; } @@ -87,6 +85,11 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting() { return NetworkConnectionState::INIT; } + + if(!_check_internet_availability){ + return NetworkConnectionState::CONNECTED; + } + int ping_result = GSM.ping("time.arduino.cc"); Debug.print(DBG_INFO, F("GSM.ping(): %d"), ping_result); if (ping_result < 0) diff --git a/src/CellularConnectionHandler.cpp b/src/CellularConnectionHandler.cpp index 59be8026..c6a90774 100644 --- a/src/CellularConnectionHandler.cpp +++ b/src/CellularConnectionHandler.cpp @@ -77,6 +77,10 @@ NetworkConnectionState CellularConnectionHandler::update_handleConnecting() return NetworkConnectionState::INIT; } + if (!_check_internet_availability) { + return NetworkConnectionState::CONNECTED; + } + if(getTime() == 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)]); diff --git a/src/ConnectionHandlerInterface.cpp b/src/ConnectionHandlerInterface.cpp index 1f62bde2..237b465d 100644 --- a/src/ConnectionHandlerInterface.cpp +++ b/src/ConnectionHandlerInterface.cpp @@ -29,6 +29,7 @@ ConnectionHandler::ConnectionHandler(bool const keep_alive, NetworkAdapter inter : _keep_alive{keep_alive} , _interface{interface} , _lastConnectionTickTime{millis()} +, _check_internet_availability{false} , _current_net_connection_state{NetworkConnectionState::INIT} { diff --git a/src/ConnectionHandlerInterface.h b/src/ConnectionHandlerInterface.h index 80819605..6af40d47 100644 --- a/src/ConnectionHandlerInterface.h +++ b/src/ConnectionHandlerInterface.h @@ -76,6 +76,9 @@ class ConnectionHandler { virtual void connect(); virtual void disconnect(); + void enableCheckInternetAvailability(bool enable) { + _check_internet_availability = enable; + } virtual void addCallback(NetworkConnectionEvent const event, OnNetworkEventCallback callback); void addConnectCallback(OnNetworkEventCallback callback) __attribute__((deprecated)); @@ -106,6 +109,7 @@ class ConnectionHandler { virtual void updateCallback(NetworkConnectionState next_net_connection_state); bool _keep_alive; + bool _check_internet_availability; NetworkAdapter _interface; virtual NetworkConnectionState update_handleInit () = 0; diff --git a/src/EthernetConnectionHandler.cpp b/src/EthernetConnectionHandler.cpp index 2c9049ce..543f0737 100644 --- a/src/EthernetConnectionHandler.cpp +++ b/src/EthernetConnectionHandler.cpp @@ -109,6 +109,10 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() return NetworkConnectionState::INIT; } + if (!_check_internet_availability) { + return NetworkConnectionState::CONNECTED; + } + int ping_result = Ethernet.ping("time.arduino.cc"); Debug.print(DBG_INFO, F("Ethernet.ping(): %d"), ping_result); if (ping_result < 0) diff --git a/src/GSMConnectionHandler.cpp b/src/GSMConnectionHandler.cpp index 75f9e536..64b04d0e 100644 --- a/src/GSMConnectionHandler.cpp +++ b/src/GSMConnectionHandler.cpp @@ -53,6 +53,8 @@ GSMConnectionHandler::GSMConnectionHandler(const char * pin, const char * apn, c : ConnectionHandler{keep_alive, NetworkAdapter::GSM} { _settings.type = NetworkAdapter::GSM; + // To keep the backward compatibility, the user can call enableCheckInternetAvailability(false) for disabling the check + _check_internet_availability = true; strncpy(_settings.gsm.pin, pin, sizeof(_settings.gsm.pin)-1); strncpy(_settings.gsm.apn, apn, sizeof(_settings.gsm.apn)-1); strncpy(_settings.gsm.login, login, sizeof(_settings.gsm.login)-1); @@ -105,6 +107,10 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit() NetworkConnectionState GSMConnectionHandler::update_handleConnecting() { + if(!_check_internet_availability){ + return NetworkConnectionState::CONNECTED; + } + Debug.print(DBG_INFO, F("Sending PING to outer space...")); int const ping_result = _gprs.ping("time.arduino.cc"); Debug.print(DBG_INFO, F("GPRS.ping(): %d"), ping_result); diff --git a/src/GenericConnectionHandler.cpp b/src/GenericConnectionHandler.cpp index f1f9eb6b..ce6c198c 100644 --- a/src/GenericConnectionHandler.cpp +++ b/src/GenericConnectionHandler.cpp @@ -37,6 +37,7 @@ bool GenericConnectionHandler::updateSetting(const models::NetworkSetting& s) { if(_ch != nullptr) { _interface = s.type; _ch->setKeepAlive(_keep_alive); + _ch->enableCheckInternetAvailability(_check_internet_availability); return _ch->updateSetting(s); } else { _interface = NetworkAdapter::NONE; diff --git a/src/WiFiConnectionHandler.cpp b/src/WiFiConnectionHandler.cpp index 4e2d9a85..218e1cc1 100644 --- a/src/WiFiConnectionHandler.cpp +++ b/src/WiFiConnectionHandler.cpp @@ -135,6 +135,11 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() if (WiFi.status() != WL_CONNECTED){ return NetworkConnectionState::INIT; } + + if(!_check_internet_availability){ + return NetworkConnectionState::CONNECTED; + } + #if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) int ping_result = WiFi.ping("time.arduino.cc"); Debug.print(DBG_INFO, F("WiFi.ping(): %d"), ping_result); From f3412f69876f3f867a02cc2f22680e29a3bca5d6 Mon Sep 17 00:00:00 2001 From: fabik111 Date: Thu, 8 May 2025 12:04:17 +0200 Subject: [PATCH 177/203] add example --- .github/workflows/compile-examples.yml | 1 + .../CheckInternetAvailabilityDemo.ino | 152 ++++++++++++++++++ .../arduino_secrets.h | 19 +++ 3 files changed, 172 insertions(+) create mode 100644 examples/CheckInternetAvailabilityDemo/CheckInternetAvailabilityDemo.ino create mode 100644 examples/CheckInternetAvailabilityDemo/arduino_secrets.h diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 808258ed..5541359d 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -38,6 +38,7 @@ jobs: - name: Blues Wireless Notecard SKETCH_PATHS: | - examples/ConnectionHandlerDemo + - examples/CheckInternetAvailabilityDemo ARDUINOCORE_MBED_STAGING_PATH: extras/ArduinoCore-mbed ARDUINOCORE_API_STAGING_PATH: extras/ArduinoCore-API SKETCHES_REPORTS_PATH: sketches-reports diff --git a/examples/CheckInternetAvailabilityDemo/CheckInternetAvailabilityDemo.ino b/examples/CheckInternetAvailabilityDemo/CheckInternetAvailabilityDemo.ino new file mode 100644 index 00000000..ca530ddf --- /dev/null +++ b/examples/CheckInternetAvailabilityDemo/CheckInternetAvailabilityDemo.ino @@ -0,0 +1,152 @@ +/* SECRET_ fields are in `arduino_secrets.h` (included below) + * + * If using a WiFi board (Arduino MKR1000, MKR WiFi 1010, Nano 33 IoT, UNO + * WiFi Rev 2 or ESP8266/32), create a WiFiConnectionHandler object by adding + * Network Name (SECRET_WIFI_SSID) and password (SECRET_WIFI_PASS) in the + * arduino_secrets.h file (or Secrets tab in Create Web Editor). + * + * WiFiConnectionHandler conMan(SECRET_WIFI_SSID, SECRET_WIFI_PASS); + * + * If using a MKR GSM 1400 or other GSM boards supporting the same API you'll + * need a GSMConnectionHandler object as follows + * + * GSMConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); + * + * If using a MKR NB1500 you'll need a NBConnectionHandler object as follows + * + * NBConnectionHandler conMan(SECRET_PIN); + * + * If using a Portenta + Ethernet shield you'll need a EthernetConnectionHandler object as follows: + * + * DHCP mode + * EthernetConnectionHandler conMan; + * + * Manual configuration + * EthernetConnectionHandler conMan(SECRET_IP, SECRET_DNS, SECRET_GATEWAY, SECRET_NETMASK); + * + * Manual configuration will fallback on DHCP mode if SECRET_IP is invalid or equal to INADDR_NONE. + * + * This sketch enables the ConnectionHandler to check for internet availability (only for IP based connectivity) + * before reporting the Connected state. By default the check is disabled. + * + */ + +#include + +#include "arduino_secrets.h" + +#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)) + #error "Please check Arduino Connection Handler supported boards list: https://github.com/arduino-libraries/Arduino_ConnectionHandler/blob/master/README.md" +#endif + +#if defined(BOARD_HAS_ETHERNET) +EthernetConnectionHandler conMan(SECRET_IP, SECRET_DNS, SECRET_GATEWAY, SECRET_NETMASK); +#elif defined(BOARD_HAS_WIFI) +WiFiConnectionHandler conMan(SECRET_WIFI_SSID, SECRET_WIFI_PASS); +#elif defined(BOARD_HAS_GSM) +GSMConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); +#elif defined(BOARD_HAS_NB) +NBConnectionHandler conMan(SECRET_PIN); +#elif defined(BOARD_HAS_LORA) +LoRaConnectionHandler conMan(SECRET_APP_EUI, SECRET_APP_KEY); +#elif defined(BOARD_HAS_CATM1_NBIOT) +CatM1ConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); +#elif defined(BOARD_HAS_CELLULAR) +CellularConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); +#endif + +bool attemptConnect = false; +uint32_t lastConnToggleMs = 0; + +void setup() { + /* Initialize serial debug port and wait up to 5 seconds for port to open */ + Serial.begin(9600); + for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { } + +#ifndef __AVR__ + /* Set the debug message level: + * - DBG_ERROR: Only show error messages + * - DBG_WARNING: Show warning and error messages + * - DBG_INFO: Show info, warning, and error messages + * - DBG_DEBUG: Show debug, info, warning, and error messages + * - DBG_VERBOSE: Show all messages + */ + setDebugMessageLevel(DBG_INFO); +#endif + /* Enable the connection handler to check for internet availability. + * By default is disabled. + */ + conMan.enableCheckInternetAvailability(true); + /* Add callbacks to the ConnectionHandler object to get notified of network + * connection events. */ + conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect); + conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect); + conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError); + + Serial.print("Network Adapter Interface: "); + switch (conMan.getInterface()) { + case NetworkAdapter::WIFI: + Serial.println("Wi-Fi"); + break; + case NetworkAdapter::ETHERNET: + Serial.println("Ethernet"); + break; + case NetworkAdapter::NB: + Serial.println("Narrowband"); + break; + case NetworkAdapter::GSM: + Serial.println("GSM"); + break; + case NetworkAdapter::LORA: + Serial.println("LoRa"); + break; + case NetworkAdapter::CATM1: + Serial.println("Category M1"); + break; + case NetworkAdapter::CELL: + Serial.println("Cellular"); + break; + default: + Serial.println("Unknown"); + break; + } +} + +void loop() { + /* Toggle the connection every `CONN_TOGGLE_MS` milliseconds */ + if ((millis() - lastConnToggleMs) > CONN_TOGGLE_MS) { + Serial.println("Toggling connection..."); + if (attemptConnect) { + conMan.connect(); + } else { + conMan.disconnect(); + } + attemptConnect = !attemptConnect; + lastConnToggleMs = millis(); + } + + /* The following code keeps on running connection workflows on our + * ConnectionHandler object, hence allowing reconnection in case of failure + * and notification of connect/disconnect event if enabled (see + * addConnectCallback/addDisconnectCallback) NOTE: any use of delay() within + * the loop or methods called from it will delay the execution of .update(), + * which might not guarantee the correct functioning of the ConnectionHandler + * object. + */ + conMan.check(); +} + +void onNetworkConnect() { + Serial.println(">>>> CONNECTED to network"); +} + +void onNetworkDisconnect() { + Serial.println(">>>> DISCONNECTED from network"); +} + +void onNetworkError() { + Serial.println(">>>> ERROR"); +} diff --git a/examples/CheckInternetAvailabilityDemo/arduino_secrets.h b/examples/CheckInternetAvailabilityDemo/arduino_secrets.h new file mode 100644 index 00000000..f9906f69 --- /dev/null +++ b/examples/CheckInternetAvailabilityDemo/arduino_secrets.h @@ -0,0 +1,19 @@ +// Required for WiFiConnectionHandler +const char SECRET_WIFI_SSID[] = "NETWORK NAME"; +const char SECRET_WIFI_PASS[] = "NETWORK PASSWORD"; + +// Required for GSMConnectionHandler +const char SECRET_APN[] = "MOBILE PROVIDER APN ADDRESS"; +const char SECRET_PIN[] = "0000"; // Required for NBConnectionHandler +const char SECRET_GSM_USER[] = "GSM USERNAME"; +const char SECRET_GSM_PASS[] = "GSM PASSWORD"; + +// Required for LoRaConnectionHandler +const char SECRET_APP_EUI[] = "APP_EUI"; +const char SECRET_APP_KEY[] = "APP_KEY"; + +// Required for EthernetConnectionHandler (without DHCP mode) +const char SECRET_IP[] = "IP ADDRESS"; +const char SECRET_DNS[] = "DNS ADDRESS"; +const char SECRET_GATEWAY[] = "GATEWAY ADDRESS"; +const char SECRET_NETMASK[] = "NETWORK MASK"; From 510d8e512a22d9960d19f0d07670554f238da874 Mon Sep 17 00:00:00 2001 From: fabik111 Date: Thu, 8 May 2025 14:59:33 +0200 Subject: [PATCH 178/203] fix debug message for retrying in init state --- src/WiFiConnectionHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WiFiConnectionHandler.cpp b/src/WiFiConnectionHandler.cpp index 218e1cc1..37d3ff66 100644 --- a/src/WiFiConnectionHandler.cpp +++ b/src/WiFiConnectionHandler.cpp @@ -114,7 +114,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() { #if !defined(__AVR__) Debug.print(DBG_ERROR, F("Connection to \"%s\" failed"), _settings.wifi.ssid); - 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"), CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::INIT)]); #endif return NetworkConnectionState::INIT; } From 4f3731efa31f4889095e6191d212a98a3cc21a70 Mon Sep 17 00:00:00 2001 From: fabik111 Date: Thu, 8 May 2025 15:28:17 +0200 Subject: [PATCH 179/203] remove udp include --- src/EthernetConnectionHandler.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/EthernetConnectionHandler.cpp b/src/EthernetConnectionHandler.cpp index 543f0737..6e730381 100644 --- a/src/EthernetConnectionHandler.cpp +++ b/src/EthernetConnectionHandler.cpp @@ -20,7 +20,6 @@ #ifdef BOARD_HAS_ETHERNET /* Only compile if the board has ethernet */ #include "EthernetConnectionHandler.h" -#include /****************************************************************************** CTOR/DTOR From 34a52e4f20ac1263ca3df1d6c00b9ef8d2b0f254 Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Mon, 12 May 2025 08:41:56 +0200 Subject: [PATCH 180/203] Release 1.1.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 4539afee..3592a568 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=1.0.2 +version=1.1.0 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet], Notecard) From f8756e97d28fc32e31b33063063db05ee0aa07bd Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 8 Oct 2024 09:55:12 +0200 Subject: [PATCH 181/203] 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 2a63dea0..316ee5a7 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 182/203] 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 316ee5a7..dd8699e3 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 183/203] 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 dd8699e3..b430034e 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 184/203] 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 b430034e..6169d318 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 185/203] 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 6169d318..7b29e005 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 186/203] 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 7b29e005..c8bd7fcd 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 67f317b7..37c92058 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; }; From 7a9f07bd87f57f4c26556ec941d966ea52a80564 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Mon, 12 May 2025 15:00:30 +0200 Subject: [PATCH 187/203] Defined TimeoutTable for the user to customize timeouts changing the approach from defining a static array CHECK_INTERVAL_TABLE we can allow the user to change timeout values at runtime depending on his needs. --- src/CatM1ConnectionHandler.cpp | 2 +- src/CellularConnectionHandler.cpp | 2 +- src/ConnectionHandlerDefinitions.h | 36 +++++++++++++++++++++--------- src/ConnectionHandlerInterface.cpp | 4 +++- src/ConnectionHandlerInterface.h | 8 +++++++ src/EthernetConnectionHandler.cpp | 2 +- src/GSMConnectionHandler.cpp | 2 +- src/LoRaConnectionHandler.cpp | 2 +- src/NotecardConnectionHandler.cpp | 2 +- src/WiFiConnectionHandler.cpp | 4 ++-- 10 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index c8bd7fcd..ef9edb62 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -107,7 +107,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting() if (ping_result < 0) { Debug.print(DBG_ERROR, F("Internet check failed")); - Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), 2 * CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::CONNECTING)]); + Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.connecting); return NetworkConnectionState::CONNECTING; } else diff --git a/src/CellularConnectionHandler.cpp b/src/CellularConnectionHandler.cpp index c6a90774..62cb93b2 100644 --- a/src/CellularConnectionHandler.cpp +++ b/src/CellularConnectionHandler.cpp @@ -83,7 +83,7 @@ NetworkConnectionState CellularConnectionHandler::update_handleConnecting() if(getTime() == 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"), _timeoutTable.timeout.connecting); return NetworkConnectionState::CONNECTING; } diff --git a/src/ConnectionHandlerDefinitions.h b/src/ConnectionHandlerDefinitions.h index 4cefc5de..3479d83f 100644 --- a/src/ConnectionHandlerDefinitions.h +++ b/src/ConnectionHandlerDefinitions.h @@ -185,21 +185,35 @@ enum class NetworkAdapter { NOTECARD }; +union TimeoutTable { + struct { + // Note: order of the following values must be preserved + // and match against NetworkConnectionState values + uint32_t init; + uint32_t connecting; + uint32_t connected; + uint32_t disconnecting; + uint32_t disconnected; + uint32_t closed; + uint32_t error; + } timeout; + uint32_t intervals[sizeof(timeout) / sizeof(uint32_t)]; +}; + /****************************************************************************** CONSTANTS ******************************************************************************/ -static unsigned int const CHECK_INTERVAL_TABLE[] = -{ +constexpr TimeoutTable DefaultTimeoutTable { #if defined(BOARD_HAS_NOTECARD) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) - /* INIT */ 4000, + 4000, // init #else - /* INIT */ 500, -#endif - /* CONNECTING */ 500, - /* CONNECTED */ 10000, - /* DISCONNECTING */ 100, - /* DISCONNECTED */ 1000, - /* CLOSED */ 1000, - /* ERROR */ 1000 + 500, // init +#endif + 500, // connecting + 10000, // connected + 100, // disconnecting + 1000, // disconnected + 1000, // closed + 1000, // error }; diff --git a/src/ConnectionHandlerInterface.cpp b/src/ConnectionHandlerInterface.cpp index 237b465d..fe52664d 100644 --- a/src/ConnectionHandlerInterface.cpp +++ b/src/ConnectionHandlerInterface.cpp @@ -31,6 +31,7 @@ ConnectionHandler::ConnectionHandler(bool const keep_alive, NetworkAdapter inter , _lastConnectionTickTime{millis()} , _check_internet_availability{false} , _current_net_connection_state{NetworkConnectionState::INIT} +, _timeoutTable(DefaultTimeoutTable) { } @@ -42,7 +43,8 @@ ConnectionHandler::ConnectionHandler(bool const keep_alive, NetworkAdapter inter NetworkConnectionState ConnectionHandler::check() { unsigned long const now = millis(); - unsigned int const connectionTickTimeInterval = CHECK_INTERVAL_TABLE[static_cast(_current_net_connection_state)]; + unsigned int const connectionTickTimeInterval = + _timeoutTable.intervals[static_cast(_current_net_connection_state)]; if((now - _lastConnectionTickTime) > connectionTickTimeInterval) { diff --git a/src/ConnectionHandlerInterface.h b/src/ConnectionHandlerInterface.h index 6af40d47..88c413c6 100644 --- a/src/ConnectionHandlerInterface.h +++ b/src/ConnectionHandlerInterface.h @@ -31,6 +31,8 @@ #include "ConnectionHandlerDefinitions.h" #include "connectionHandlerModels/settings.h" +#include + /****************************************************************************** TYPEDEFS ******************************************************************************/ @@ -103,6 +105,11 @@ class ConnectionHandler { virtual void setKeepAlive(bool keep_alive=true) { this->_keep_alive = keep_alive; } + inline void updateTimeoutTable(const TimeoutTable& t) { _timeoutTable = t; } + inline void updateTimeoutTable(TimeoutTable&& t) { _timeoutTable = std::move(t); } + inline void updateTimeoutInterval(NetworkConnectionState state, uint32_t interval) { + _timeoutTable.intervals[static_cast(state)] = interval; + } protected: virtual NetworkConnectionState updateConnectionState(); @@ -120,6 +127,7 @@ class ConnectionHandler { models::NetworkSetting _settings; + TimeoutTable _timeoutTable; private: unsigned long _lastConnectionTickTime; diff --git a/src/EthernetConnectionHandler.cpp b/src/EthernetConnectionHandler.cpp index 6e730381..ee3de244 100644 --- a/src/EthernetConnectionHandler.cpp +++ b/src/EthernetConnectionHandler.cpp @@ -117,7 +117,7 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() 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"), _timeoutTable.timeout.connecting); return NetworkConnectionState::CONNECTING; } else diff --git a/src/GSMConnectionHandler.cpp b/src/GSMConnectionHandler.cpp index 64b04d0e..edce9cd7 100644 --- a/src/GSMConnectionHandler.cpp +++ b/src/GSMConnectionHandler.cpp @@ -117,7 +117,7 @@ NetworkConnectionState GSMConnectionHandler::update_handleConnecting() if (ping_result < 0) { Debug.print(DBG_ERROR, F("PING 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"), _timeoutTable.timeout.connecting); return NetworkConnectionState::CONNECTING; } else diff --git a/src/LoRaConnectionHandler.cpp b/src/LoRaConnectionHandler.cpp index bc753fd2..1ed9168a 100644 --- a/src/LoRaConnectionHandler.cpp +++ b/src/LoRaConnectionHandler.cpp @@ -126,7 +126,7 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnecting() if (network_status != true) { Debug.print(DBG_ERROR, F("Connection to the network 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"), _timeoutTable.timeout.connecting); return NetworkConnectionState::INIT; } else diff --git a/src/NotecardConnectionHandler.cpp b/src/NotecardConnectionHandler.cpp index 466c74df..8b3d5b6e 100644 --- a/src/NotecardConnectionHandler.cpp +++ b/src/NotecardConnectionHandler.cpp @@ -518,7 +518,7 @@ NetworkConnectionState NotecardConnectionHandler::update_handleConnecting() if (!conn_status.connected_to_notehub) { if ((::millis() - _conn_start_ms) > NOTEHUB_CONN_TIMEOUT_MS) { Debug.print(DBG_ERROR, F("Timeout exceeded, connection to the network 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"), _timeoutTable.timeout.connecting); result = NetworkConnectionState::INIT; } else { // Continue awaiting the connection to Notehub diff --git a/src/WiFiConnectionHandler.cpp b/src/WiFiConnectionHandler.cpp index 37d3ff66..8db1b2c6 100644 --- a/src/WiFiConnectionHandler.cpp +++ b/src/WiFiConnectionHandler.cpp @@ -114,7 +114,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() { #if !defined(__AVR__) Debug.print(DBG_ERROR, F("Connection to \"%s\" failed"), _settings.wifi.ssid); - Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), CHECK_INTERVAL_TABLE[static_cast(NetworkConnectionState::INIT)]); + Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.init); #endif return NetworkConnectionState::INIT; } @@ -146,7 +146,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() 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"), _timeoutTable.timeout.connecting); return NetworkConnectionState::CONNECTING; } #endif From fa8e9578bdbfa5e3783f4bd7fe4ec38b18da1642 Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Wed, 14 May 2025 10:55:15 +0200 Subject: [PATCH 188/203] Release 1.1.1 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 3592a568..9c0b81d3 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=1.1.0 +version=1.1.1 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet], Notecard) From e5e9662ea5a61e7219e3b163d6b08d7a71956458 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 5 Jun 2025 14:27:17 +0200 Subject: [PATCH 189/203] fix: warning: missing initializer for member 'models::NetworkSetting::' --- src/connectionHandlerModels/settings_default.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connectionHandlerModels/settings_default.h b/src/connectionHandlerModels/settings_default.h index dc9a4efd..186cebff 100644 --- a/src/connectionHandlerModels/settings_default.h +++ b/src/connectionHandlerModels/settings_default.h @@ -23,7 +23,7 @@ namespace models { inline NetworkSetting settingsDefault(NetworkAdapter type) { #endif - NetworkSetting res = {type}; + NetworkSetting res = {type, {}}; switch(type) { #if defined(BOARD_HAS_ETHERNET) From f00637b1d2c2132405b000b58c839e02b3bcfa3d Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 5 Jun 2025 14:30:21 +0200 Subject: [PATCH 190/203] fix: initialization order warning --- src/ConnectionHandlerInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConnectionHandlerInterface.cpp b/src/ConnectionHandlerInterface.cpp index 237b465d..cf2342ca 100644 --- a/src/ConnectionHandlerInterface.cpp +++ b/src/ConnectionHandlerInterface.cpp @@ -27,9 +27,9 @@ ConnectionHandler::ConnectionHandler(bool const keep_alive, NetworkAdapter interface) : _keep_alive{keep_alive} +, _check_internet_availability{false} , _interface{interface} , _lastConnectionTickTime{millis()} -, _check_internet_availability{false} , _current_net_connection_state{NetworkConnectionState::INIT} { From c657b11c24c0d21ca0d716e1dd58c8276cb30c30 Mon Sep 17 00:00:00 2001 From: fabik111 Date: Fri, 30 May 2025 17:46:16 +0200 Subject: [PATCH 191/203] add get setting --- src/ConnectionHandlerInterface.h | 5 +++++ src/GenericConnectionHandler.cpp | 8 ++++++++ src/GenericConnectionHandler.h | 1 + 3 files changed, 14 insertions(+) diff --git a/src/ConnectionHandlerInterface.h b/src/ConnectionHandlerInterface.h index 6af40d47..251a1570 100644 --- a/src/ConnectionHandlerInterface.h +++ b/src/ConnectionHandlerInterface.h @@ -101,6 +101,11 @@ class ConnectionHandler { return false; } + virtual void getSetting(models::NetworkSetting& s) { + memcpy(&s, &_settings, sizeof(s)); + return; + } + virtual void setKeepAlive(bool keep_alive=true) { this->_keep_alive = keep_alive; } protected: diff --git a/src/GenericConnectionHandler.cpp b/src/GenericConnectionHandler.cpp index ce6c198c..14b76fc5 100644 --- a/src/GenericConnectionHandler.cpp +++ b/src/GenericConnectionHandler.cpp @@ -46,6 +46,14 @@ bool GenericConnectionHandler::updateSetting(const models::NetworkSetting& s) { } } +void GenericConnectionHandler::getSetting(models::NetworkSetting& s) { + if(_ch != nullptr) { + _ch->getSetting(s); + } else { + s.type = NetworkAdapter::NONE; + } +} + NetworkConnectionState GenericConnectionHandler::updateConnectionState() { return _ch != nullptr ? _ch->updateConnectionState() : NetworkConnectionState::INIT; } diff --git a/src/GenericConnectionHandler.h b/src/GenericConnectionHandler.h index e1b315e4..5468e438 100644 --- a/src/GenericConnectionHandler.h +++ b/src/GenericConnectionHandler.h @@ -49,6 +49,7 @@ class GenericConnectionHandler : public ConnectionHandler #endif bool updateSetting(const models::NetworkSetting& s) override; + void getSetting(models::NetworkSetting& s) override; void connect() override; void disconnect() override; From 0c52c56dc92a2acaf38faf5693f68cafc4e0128d Mon Sep 17 00:00:00 2001 From: fabik111 Date: Tue, 3 Jun 2025 11:31:28 +0200 Subject: [PATCH 192/203] set connection type for EthernetConnectionHandler --- src/EthernetConnectionHandler.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/EthernetConnectionHandler.cpp b/src/EthernetConnectionHandler.cpp index 6e730381..2cc1d51b 100644 --- a/src/EthernetConnectionHandler.cpp +++ b/src/EthernetConnectionHandler.cpp @@ -41,6 +41,7 @@ EthernetConnectionHandler::EthernetConnectionHandler( bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} { + _settings.type = NetworkAdapter::ETHERNET; memset(_settings.eth.ip.dword, 0, sizeof(_settings.eth.ip.dword)); memset(_settings.eth.dns.dword, 0, sizeof(_settings.eth.dns.dword)); memset(_settings.eth.gateway.dword, 0, sizeof(_settings.eth.gateway.dword)); @@ -54,6 +55,7 @@ EthernetConnectionHandler::EthernetConnectionHandler( unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} { + _settings.type = NetworkAdapter::ETHERNET; fromIPAddress(ip, _settings.eth.ip); fromIPAddress(dns, _settings.eth.dns); fromIPAddress(gateway, _settings.eth.gateway); From 98ca3322cb50ab9d409dd0611febd4fd52015ba0 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 2 Jul 2025 10:53:14 +0200 Subject: [PATCH 193/203] Added an example for updateTimeoutInterval usage --- .../ConnectionHandlerTimeoutTable.ino | 83 +++++++++++++++++++ .../arduino_secrets.h | 19 +++++ 2 files changed, 102 insertions(+) create mode 100644 examples/ConnectionHandlerTimeoutTable/ConnectionHandlerTimeoutTable.ino create mode 100644 examples/ConnectionHandlerTimeoutTable/arduino_secrets.h diff --git a/examples/ConnectionHandlerTimeoutTable/ConnectionHandlerTimeoutTable.ino b/examples/ConnectionHandlerTimeoutTable/ConnectionHandlerTimeoutTable.ino new file mode 100644 index 00000000..ab629053 --- /dev/null +++ b/examples/ConnectionHandlerTimeoutTable/ConnectionHandlerTimeoutTable.ino @@ -0,0 +1,83 @@ +/* SECRET_ fields are in `arduino_secrets.h` (included below) + * + * This example is a lightly modified version of ConnectionHandlerDemo to showcase + * the possibility of changing the timeout values for the different states a connectionhandler have + */ + +#include + +#include "arduino_secrets.h" + +#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)) + #error "Please check Arduino Connection Handler supported boards list: https://github.com/arduino-libraries/Arduino_ConnectionHandler/blob/master/README.md" +#endif + +#if defined(BOARD_HAS_ETHERNET) +EthernetConnectionHandler conMan(SECRET_IP, SECRET_DNS, SECRET_GATEWAY, SECRET_NETMASK); +#elif defined(BOARD_HAS_WIFI) +WiFiConnectionHandler conMan(SECRET_WIFI_SSID, SECRET_WIFI_PASS); +#elif defined(BOARD_HAS_GSM) +GSMConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); +#elif defined(BOARD_HAS_NB) +NBConnectionHandler conMan(SECRET_PIN); +#elif defined(BOARD_HAS_LORA) +LoRaConnectionHandler conMan(SECRET_APP_EUI, SECRET_APP_KEY); +#elif defined(BOARD_HAS_CATM1_NBIOT) +CatM1ConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); +#elif defined(BOARD_HAS_CELLULAR) +CellularConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); +#endif + +bool attemptConnect = false; +uint32_t lastConnToggleMs = 0; + +void setup() { + /* Initialize serial debug port and wait up to 5 seconds for port to open */ + Serial.begin(9600); + for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { } + +#ifndef __AVR__ + /* Set the debug message level: + * - DBG_ERROR: Only show error messages + * - DBG_WARNING: Show warning and error messages + * - DBG_INFO: Show info, warning, and error messages + * - DBG_DEBUG: Show debug, info, warning, and error messages + * - DBG_VERBOSE: Show all messages + */ + setDebugMessageLevel(DBG_INFO); +#endif + + /* Add callbacks to the ConnectionHandler object to get notified of network + * connection events. */ + conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect); + conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect); + conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError); + + /* By using updateTimeoutInterval I can change the timeout value for a specific + * state of the connection handler + */ + conMan.updateTimeoutInterval(NetworkConnectionState::INIT, 8000); + conMan.updateTimeoutInterval(NetworkConnectionState::CONNECTING, 1000); + conMan.updateTimeoutInterval(NetworkConnectionState::CONNECTED, 20000); + conMan.updateTimeoutInterval(NetworkConnectionState::DISCONNECTING, 200); + conMan.updateTimeoutInterval(NetworkConnectionState::DISCONNECTED, 2000); + conMan.updateTimeoutInterval(NetworkConnectionState::CLOSED, 2000); + conMan.updateTimeoutInterval(NetworkConnectionState::ERROR, 2000); +} + +void loop() { + conMan.check(); +} + +void onNetworkConnect() { + Serial.println(">>>> CONNECTED to network"); +} + +void onNetworkDisconnect() { + Serial.println(">>>> DISCONNECTED from network"); +} + +void onNetworkError() { + Serial.println(">>>> ERROR"); +} diff --git a/examples/ConnectionHandlerTimeoutTable/arduino_secrets.h b/examples/ConnectionHandlerTimeoutTable/arduino_secrets.h new file mode 100644 index 00000000..cecefa42 --- /dev/null +++ b/examples/ConnectionHandlerTimeoutTable/arduino_secrets.h @@ -0,0 +1,19 @@ +// Required for WiFiConnectionHandler +const char SECRET_WIFI_SSID[] = "SSID"; +const char SECRET_WIFI_PASS[] = "PASSWORD"; + +// Required for GSMConnectionHandler +const char SECRET_APN[] = "MOBILE PROVIDER APN ADDRESS"; +const char SECRET_PIN[] = "0000"; // Required for NBConnectionHandler +const char SECRET_GSM_USER[] = "GSM USERNAME"; +const char SECRET_GSM_PASS[] = "GSM PASSWORD"; + +// Required for LoRaConnectionHandler +const char SECRET_APP_EUI[] = "APP_EUI"; +const char SECRET_APP_KEY[] = "APP_KEY"; + +// Required for EthernetConnectionHandler (without DHCP mode) +const char SECRET_IP[] = "IP ADDRESS"; +const char SECRET_DNS[] = "DNS ADDRESS"; +const char SECRET_GATEWAY[] = "GATEWAY ADDRESS"; +const char SECRET_NETMASK[] = "NETWORK MASK"; From 7d685352c4419c3f453f84fb8c3f45ad4f0971d3 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 2 Jul 2025 11:19:20 +0200 Subject: [PATCH 194/203] Publish 1.1.2 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 9c0b81d3..04fd42ad 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=1.1.1 +version=1.1.2 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet], Notecard) From 56df9300b2abf67f6a18e0a0510562b6373c284c Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 9 Apr 2025 09:54:15 +0200 Subject: [PATCH 195/203] Refactoring debug messages into macro defined calls --- src/CatM1ConnectionHandler.cpp | 16 ++-- src/CellularConnectionHandler.cpp | 12 +-- src/EthernetConnectionHandler.cpp | 22 +++--- src/GSMConnectionHandler.cpp | 20 ++--- src/GenericConnectionHandler.cpp | 2 +- src/LoRaConnectionHandler.cpp | 56 +++++++++----- src/NBConnectionHandler.cpp | 18 ++--- src/NotecardConnectionHandler.cpp | 120 +++++++++++++++--------------- src/WiFiConnectionHandler.cpp | 32 ++++---- 9 files changed, 158 insertions(+), 140 deletions(-) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index ef9edb62..1d8db630 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -81,7 +81,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleInit() _settings.catm1.band, _reset)) { - Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); + DEBUG_ERROR(F("The board was not able to register to the network...")); _reset = true; return NetworkConnectionState::DISCONNECTED; } @@ -93,7 +93,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting() { if (!GSM.isConnected()) { - Debug.print(DBG_ERROR, F("GSM connection not alive... disconnecting")); + DEBUG_ERROR(F("GSM connection not alive... disconnecting")); return NetworkConnectionState::DISCONNECTED; } @@ -101,18 +101,18 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting() return NetworkConnectionState::CONNECTED; } - Debug.print(DBG_INFO, F("Sending PING to outer space...")); + DEBUG_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); + DEBUG_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"), _timeoutTable.timeout.connecting); + DEBUG_ERROR(F("Internet check failed")); + DEBUG_INFO(F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.connecting); return NetworkConnectionState::CONNECTING; } else { - Debug.print(DBG_INFO, F("Connected to Internet")); + DEBUG_INFO(F("Connected to Internet")); return NetworkConnectionState::CONNECTED; } } @@ -122,7 +122,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")); + DEBUG_ERROR(F("GSM connection not alive... disconnecting")); return NetworkConnectionState::DISCONNECTED; } return NetworkConnectionState::CONNECTED; diff --git a/src/CellularConnectionHandler.cpp b/src/CellularConnectionHandler.cpp index 62cb93b2..324bec43 100644 --- a/src/CellularConnectionHandler.cpp +++ b/src/CellularConnectionHandler.cpp @@ -46,7 +46,7 @@ unsigned long CellularConnectionHandler::getTime() UDP & CellularConnectionHandler::getUDP() { - Debug.print(DBG_ERROR, F("CellularConnectionHandler has no UDP support")); + DEBUG_ERROR(F("CellularConnectionHandler has no UDP support")); while(1) {}; } @@ -59,15 +59,15 @@ NetworkConnectionState CellularConnectionHandler::update_handleInit() _cellular.begin(); _cellular.setDebugStream(Serial); if (strlen(_settings.cell.pin) > 0 && !_cellular.unlockSIM(_settings.cell.pin)) { - Debug.print(DBG_ERROR, F("SIM not present or wrong PIN")); + DEBUG_ERROR(F("SIM not present or wrong PIN")); return NetworkConnectionState::ERROR; } if (!_cellular.connect(String(_settings.cell.apn), String(_settings.cell.login), String(_settings.cell.pass))) { - Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); + DEBUG_ERROR(F("The board was not able to register to the network...")); return NetworkConnectionState::ERROR; } - Debug.print(DBG_INFO, F("Connected to Network")); + DEBUG_INFO(F("Connected to Network")); return NetworkConnectionState::CONNECTING; } @@ -82,8 +82,8 @@ NetworkConnectionState CellularConnectionHandler::update_handleConnecting() } if(getTime() == 0){ - Debug.print(DBG_ERROR, F("Internet check failed")); - Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.connecting); + DEBUG_ERROR(F("Internet check failed")); + DEBUG_INFO(F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.connecting); return NetworkConnectionState::CONNECTING; } diff --git a/src/EthernetConnectionHandler.cpp b/src/EthernetConnectionHandler.cpp index 48f2f7e8..e86762f0 100644 --- a/src/EthernetConnectionHandler.cpp +++ b/src/EthernetConnectionHandler.cpp @@ -71,7 +71,7 @@ EthernetConnectionHandler::EthernetConnectionHandler( NetworkConnectionState EthernetConnectionHandler::update_handleInit() { if (Ethernet.hardwareStatus() == EthernetNoHardware) { - Debug.print(DBG_ERROR, F("Error, ethernet shield was not found.")); + DEBUG_ERROR(F("Error, ethernet shield was not found.")); return NetworkConnectionState::ERROR; } IPAddress ip(_settings.eth.ip.type, _settings.eth.ip.bytes); @@ -85,16 +85,16 @@ NetworkConnectionState EthernetConnectionHandler::update_handleInit() _settings.eth.timeout, _settings.eth.response_timeout) == 0) { - Debug.print(DBG_ERROR, F("Failed to configure Ethernet, check cable connection")); - Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", + DEBUG_ERROR(F("Failed to configure Ethernet, check cable connection")); + DEBUG_VERBOSE("timeout: %d, response timeout: %d", _settings.eth.timeout, _settings.eth.response_timeout); return NetworkConnectionState::INIT; } // An ip address is not provided -> dhcp configuration } else { if (Ethernet.begin(nullptr, _settings.eth.timeout, _settings.eth.response_timeout) == 0) { - Debug.print(DBG_ERROR, F("Waiting Ethernet configuration from DHCP server, check cable connection")); - Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", + DEBUG_ERROR(F("Waiting Ethernet configuration from DHCP server, check cable connection")); + DEBUG_VERBOSE("timeout: %d, response timeout: %d", _settings.eth.timeout, _settings.eth.response_timeout); return NetworkConnectionState::INIT; @@ -115,16 +115,16 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() } int ping_result = Ethernet.ping("time.arduino.cc"); - Debug.print(DBG_INFO, F("Ethernet.ping(): %d"), ping_result); + DEBUG_INFO(F("Ethernet.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"), _timeoutTable.timeout.connecting); + DEBUG_ERROR(F("Internet check failed")); + DEBUG_INFO(F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.connecting); return NetworkConnectionState::CONNECTING; } else { - Debug.print(DBG_INFO, F("Connected to Internet")); + DEBUG_INFO(F("Connected to Internet")); return NetworkConnectionState::CONNECTED; } @@ -133,10 +133,10 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() NetworkConnectionState EthernetConnectionHandler::update_handleConnected() { if (Ethernet.linkStatus() == LinkOFF) { - Debug.print(DBG_ERROR, F("Ethernet link OFF, connection lost.")); + DEBUG_ERROR(F("Ethernet link OFF, connection lost.")); if (_keep_alive) { - Debug.print(DBG_ERROR, F("Attempting reconnection")); + DEBUG_ERROR(F("Attempting reconnection")); } return NetworkConnectionState::DISCONNECTED; } diff --git a/src/GSMConnectionHandler.cpp b/src/GSMConnectionHandler.cpp index edce9cd7..3bd7b64e 100644 --- a/src/GSMConnectionHandler.cpp +++ b/src/GSMConnectionHandler.cpp @@ -80,13 +80,13 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit() if (_gsm.begin(_settings.gsm.pin) != GSM_READY) { - Debug.print(DBG_ERROR, F("SIM not present or wrong PIN")); + DEBUG_ERROR(F("SIM not present or wrong PIN")); return NetworkConnectionState::ERROR; } mkr_gsm_feed_watchdog(); - Debug.print(DBG_INFO, F("SIM card ok")); + DEBUG_INFO(F("SIM card ok")); _gsm.setTimeout(GSM_TIMEOUT); _gprs.setTimeout(GPRS_TIMEOUT); @@ -94,11 +94,11 @@ NetworkConnectionState GSMConnectionHandler::update_handleInit() GSM3_NetworkStatus_t const network_status = _gprs.attachGPRS( _settings.gsm.apn, _settings.gsm.login, _settings.gsm.pass, true); - Debug.print(DBG_DEBUG, F("GPRS.attachGPRS(): %d"), network_status); + DEBUG_DEBUG(F("GPRS.attachGPRS(): %d"), network_status); if (network_status == GSM3_NetworkStatus_t::ERROR) { - Debug.print(DBG_ERROR, F("GPRS attach failed")); - Debug.print(DBG_ERROR, F("Make sure the antenna is connected and reset your board.")); + DEBUG_ERROR(F("GPRS attach failed")); + DEBUG_ERROR(F("Make sure the antenna is connected and reset your board.")); return NetworkConnectionState::ERROR; } @@ -111,18 +111,18 @@ NetworkConnectionState GSMConnectionHandler::update_handleConnecting() return NetworkConnectionState::CONNECTED; } - Debug.print(DBG_INFO, F("Sending PING to outer space...")); + DEBUG_INFO(F("Sending PING to outer space...")); int const ping_result = _gprs.ping("time.arduino.cc"); - Debug.print(DBG_INFO, F("GPRS.ping(): %d"), ping_result); + DEBUG_INFO(F("GPRS.ping(): %d"), ping_result); if (ping_result < 0) { - Debug.print(DBG_ERROR, F("PING failed")); - Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.connecting); + DEBUG_ERROR(F("PING failed")); + DEBUG_INFO(F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.connecting); return NetworkConnectionState::CONNECTING; } else { - Debug.print(DBG_INFO, F("Connected to GPRS Network")); + DEBUG_INFO(F("Connected to GPRS Network")); return NetworkConnectionState::CONNECTED; } } diff --git a/src/GenericConnectionHandler.cpp b/src/GenericConnectionHandler.cpp index 14b76fc5..bcda5c12 100644 --- a/src/GenericConnectionHandler.cpp +++ b/src/GenericConnectionHandler.cpp @@ -154,7 +154,7 @@ static inline ConnectionHandler* instantiate_handler(NetworkAdapter adapter) { #endif default: - Debug.print(DBG_ERROR, "Network adapter not supported by this platform: %d", adapter); + DEBUG_ERROR("Network adapter not supported by this platform: %d", adapter); return nullptr; } } diff --git a/src/LoRaConnectionHandler.cpp b/src/LoRaConnectionHandler.cpp index 1ed9168a..612751fb 100644 --- a/src/LoRaConnectionHandler.cpp +++ b/src/LoRaConnectionHandler.cpp @@ -69,20 +69,38 @@ int LoRaConnectionHandler::write(const uint8_t * buf, size_t size) { switch (err) { - case LoRaCommunicationError::LORA_ERROR_ACK_NOT_RECEIVED: Debug.print(DBG_ERROR, F("Message ack was not received, the message could not be delivered")); break; - case LoRaCommunicationError::LORA_ERROR_GENERIC: Debug.print(DBG_ERROR, F("LoRa generic error (LORA_ERROR)")); break; - case LoRaCommunicationError::LORA_ERROR_WRONG_PARAM: Debug.print(DBG_ERROR, F("LoRa malformed param error (LORA_ERROR_PARAM")); break; - case LoRaCommunicationError::LORA_ERROR_COMMUNICATION_BUSY: Debug.print(DBG_ERROR, F("LoRa chip is busy (LORA_ERROR_BUSY)")); break; - case LoRaCommunicationError::LORA_ERROR_MESSAGE_OVERFLOW: Debug.print(DBG_ERROR, F("LoRa chip overflow error (LORA_ERROR_OVERFLOW)")); break; - case LoRaCommunicationError::LORA_ERROR_NO_NETWORK_AVAILABLE: Debug.print(DBG_ERROR, F("LoRa no network error (LORA_ERROR_NO_NETWORK)")); break; - case LoRaCommunicationError::LORA_ERROR_RX_PACKET: Debug.print(DBG_ERROR, F("LoRa rx error (LORA_ERROR_RX)")); break; - case LoRaCommunicationError::LORA_ERROR_REASON_UNKNOWN: Debug.print(DBG_ERROR, F("LoRa unknown error (LORA_ERROR_UNKNOWN)")); break; - case LoRaCommunicationError::LORA_ERROR_MAX_PACKET_SIZE: Debug.print(DBG_ERROR, F("Message length is bigger than max LoRa packet!")); break; + case LoRaCommunicationError::LORA_ERROR_ACK_NOT_RECEIVED: + DEBUG_ERROR(F("Message ack was not received, the message could not be delivered")); + break; + case LoRaCommunicationError::LORA_ERROR_GENERIC: + DEBUG_ERROR(F("LoRa generic error (LORA_ERROR)")); + break; + case LoRaCommunicationError::LORA_ERROR_WRONG_PARAM: + DEBUG_ERROR(F("LoRa malformed param error (LORA_ERROR_PARAM")); + break; + case LoRaCommunicationError::LORA_ERROR_COMMUNICATION_BUSY: + DEBUG_ERROR(F("LoRa chip is busy (LORA_ERROR_BUSY)")); + break; + case LoRaCommunicationError::LORA_ERROR_MESSAGE_OVERFLOW: + DEBUG_ERROR(F("LoRa chip overflow error (LORA_ERROR_OVERFLOW)")); + break; + case LoRaCommunicationError::LORA_ERROR_NO_NETWORK_AVAILABLE: + DEBUG_ERROR(F("LoRa no network error (LORA_ERROR_NO_NETWORK)")); + break; + case LoRaCommunicationError::LORA_ERROR_RX_PACKET: + DEBUG_ERROR(F("LoRa rx error (LORA_ERROR_RX)")); + break; + case LoRaCommunicationError::LORA_ERROR_REASON_UNKNOWN: + DEBUG_ERROR(F("LoRa unknown error (LORA_ERROR_UNKNOWN)")); + break; + case LoRaCommunicationError::LORA_ERROR_MAX_PACKET_SIZE: + DEBUG_ERROR(F("Message length is bigger than max LoRa packet!")); + break; } } else { - Debug.print(DBG_INFO, F("Message sent correctly!")); + DEBUG_INFO(F("Message sent correctly!")); } return err; } @@ -105,7 +123,7 @@ NetworkConnectionState LoRaConnectionHandler::update_handleInit() { if (!_modem.begin((_lora_band)_settings.lora.band)) { - Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry.")); + DEBUG_ERROR(F("Something went wrong; are you indoor? Move near a window, then reset and retry.")); return NetworkConnectionState::ERROR; } // Set channelmask based on configuration @@ -116,7 +134,7 @@ NetworkConnectionState LoRaConnectionHandler::update_handleInit() delay(100); _modem.configureClass((_lora_class)_settings.lora.deviceClass); delay(100); - Debug.print(DBG_INFO, F("Connecting to the network")); + DEBUG_INFO(F("Connecting to the network")); return NetworkConnectionState::CONNECTING; } @@ -125,13 +143,13 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnecting() bool const network_status = _modem.joinOTAA(_settings.lora.appeui, _settings.lora.appkey); if (network_status != true) { - Debug.print(DBG_ERROR, F("Connection to the network failed")); - Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.connecting); + DEBUG_ERROR(F("Connection to the network failed")); + DEBUG_INFO(F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.connecting); return NetworkConnectionState::INIT; } else { - Debug.print(DBG_INFO, F("Connected to the network")); + DEBUG_INFO(F("Connected to the network")); return NetworkConnectionState::CONNECTED; } } @@ -141,10 +159,10 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnected() bool const network_status = _modem.connected(); if (network_status != true) { - Debug.print(DBG_ERROR, F("Connection to the network lost.")); + DEBUG_ERROR(F("Connection to the network lost.")); if (_keep_alive) { - Debug.print(DBG_ERROR, F("Attempting reconnection")); + DEBUG_ERROR(F("Attempting reconnection")); } return NetworkConnectionState::DISCONNECTED; } @@ -153,10 +171,10 @@ NetworkConnectionState LoRaConnectionHandler::update_handleConnected() NetworkConnectionState LoRaConnectionHandler::update_handleDisconnecting() { - Debug.print(DBG_ERROR, F("Connection to the network lost.")); + DEBUG_ERROR(F("Connection to the network lost.")); if (_keep_alive) { - Debug.print(DBG_ERROR, F("Attempting reconnection")); + DEBUG_ERROR(F("Attempting reconnection")); } return NetworkConnectionState::DISCONNECTED; } diff --git a/src/NBConnectionHandler.cpp b/src/NBConnectionHandler.cpp index 02d62ba2..74db3d80 100644 --- a/src/NBConnectionHandler.cpp +++ b/src/NBConnectionHandler.cpp @@ -93,13 +93,13 @@ NetworkConnectionState NBConnectionHandler::update_handleInit() _settings.nb.login, _settings.nb.pass) == NB_READY) { - Debug.print(DBG_INFO, F("SIM card ok")); + DEBUG_INFO(F("SIM card ok")); _nb.setTimeout(NB_TIMEOUT); return NetworkConnectionState::CONNECTING; } else { - Debug.print(DBG_ERROR, F("SIM not present or wrong PIN")); + DEBUG_ERROR(F("SIM not present or wrong PIN")); return NetworkConnectionState::ERROR; } } @@ -107,15 +107,15 @@ NetworkConnectionState NBConnectionHandler::update_handleInit() NetworkConnectionState NBConnectionHandler::update_handleConnecting() { NB_NetworkStatus_t const network_status = _nb_gprs.attachGPRS(true); - Debug.print(DBG_DEBUG, F("GPRS.attachGPRS(): %d"), network_status); + DEBUG_DEBUG(F("GPRS.attachGPRS(): %d"), network_status); if (network_status == NB_NetworkStatus_t::NB_ERROR) { - Debug.print(DBG_ERROR, F("GPRS.attachGPRS() failed")); + DEBUG_ERROR(F("GPRS.attachGPRS() failed")); return NetworkConnectionState::ERROR; } else { - Debug.print(DBG_INFO, F("Connected to GPRS Network")); + DEBUG_INFO(F("Connected to GPRS Network")); return NetworkConnectionState::CONNECTED; } } @@ -123,22 +123,22 @@ NetworkConnectionState NBConnectionHandler::update_handleConnecting() NetworkConnectionState NBConnectionHandler::update_handleConnected() { int const nb_is_access_alive = _nb.isAccessAlive(); - Debug.print(DBG_VERBOSE, F("GPRS.isAccessAlive(): %d"), nb_is_access_alive); + DEBUG_VERBOSE(F("GPRS.isAccessAlive(): %d"), nb_is_access_alive); if (nb_is_access_alive != 1) { - Debug.print(DBG_INFO, F("Disconnected from cellular network")); + DEBUG_INFO(F("Disconnected from cellular network")); return NetworkConnectionState::DISCONNECTED; } else { - Debug.print(DBG_VERBOSE, F("Connected to Cellular Network")); + DEBUG_VERBOSE(F("Connected to Cellular Network")); return NetworkConnectionState::CONNECTED; } } NetworkConnectionState NBConnectionHandler::update_handleDisconnecting() { - Debug.print(DBG_VERBOSE, F("Disconnecting from Cellular Network")); + DEBUG_VERBOSE(F("Disconnecting from Cellular Network")); _nb.shutdown(); return NetworkConnectionState::DISCONNECTED; } diff --git a/src/NotecardConnectionHandler.cpp b/src/NotecardConnectionHandler.cpp index 8b3d5b6e..c26a7484 100644 --- a/src/NotecardConnectionHandler.cpp +++ b/src/NotecardConnectionHandler.cpp @@ -140,7 +140,7 @@ int NotecardConnectionHandler::initiateNotehubSync (SyncType type_) const { int result; - Debug.print(DBG_DEBUG, F("NotecardConnectionHandler::%s initiating Notehub sync..."), __FUNCTION__); + DEBUG_DEBUG(F("NotecardConnectionHandler::%s initiating Notehub sync..."), __FUNCTION__); if (J *req = _notecard.newRequest("hub.sync")) { if (type_ == SyncType::Inbound) { JAddBoolToObject(req, "in", true); @@ -151,19 +151,19 @@ int NotecardConnectionHandler::initiateNotehubSync (SyncType type_) const // Check the response for errors if (NoteResponseError(rsp)) { const char *err = JGetString(rsp, "err"); - Debug.print(DBG_ERROR, F("%s"), err); + DEBUG_ERROR(F("%s"), err); result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; } else { - Debug.print(DBG_DEBUG, F("NotecardConnectionHandler::%s successfully initiated Notehub sync."), __FUNCTION__); + DEBUG_DEBUG(F("NotecardConnectionHandler::%s successfully initiated Notehub sync."), __FUNCTION__); result = NotecardCommunicationError::NOTECARD_ERROR_NONE; } JDelete(rsp); } else { - Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + DEBUG_ERROR(F("Failed to receive response from Notecard.")); result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; } } else { - Debug.print(DBG_ERROR, "Failed to allocate request: hub.sync"); + DEBUG_ERROR("Failed to allocate request: hub.sync"); result = NotecardCommunicationError::HOST_ERROR_OUT_OF_MEMORY; } @@ -178,7 +178,7 @@ int NotecardConnectionHandler::setWiFiCredentials (const String & ssid_, const S const NetworkConnectionState current_net_connection_state = check(); if (NetworkConnectionState::INIT == current_net_connection_state) { - Debug.print(DBG_ERROR, F("Unable to set Wi-Fi credentials. Connection to Notecard uninitialized.")); + DEBUG_ERROR(F("Unable to set Wi-Fi credentials. Connection to Notecard uninitialized.")); result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; } else if (J *req = _notecard.newRequest("card.wifi")) { JAddStringToObject(req, "ssid", ssid_.c_str()); @@ -187,20 +187,20 @@ int NotecardConnectionHandler::setWiFiCredentials (const String & ssid_, const S // Check the response for errors if (NoteResponseError(rsp)) { const char *err = JGetString(rsp, "err"); - Debug.print(DBG_ERROR, F("%s"), err); - Debug.print(DBG_ERROR, F("Failed to set Wi-Fi credentials.")); + DEBUG_ERROR(F("%s"), err); + DEBUG_ERROR(F("Failed to set Wi-Fi credentials.")); result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; } else { - Debug.print(DBG_INFO, F("Wi-Fi credentials updated. ssid: \"%s\" password: \"%s\"."), ssid_.c_str(), password_.length() ? "**********" : ""); + DEBUG_INFO(F("Wi-Fi credentials updated. ssid: \"%s\" password: \"%s\"."), ssid_.c_str(), password_.length() ? "**********" : ""); result = NotecardCommunicationError::NOTECARD_ERROR_NONE; } JDelete(rsp); } else { - Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + DEBUG_ERROR(F("Failed to receive response from Notecard.")); result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; } } else { - Debug.print(DBG_ERROR, F("Failed to allocate request: wifi.set")); + DEBUG_ERROR(F("Failed to allocate request: wifi.set")); result = NotecardCommunicationError::HOST_ERROR_OUT_OF_MEMORY; } @@ -236,13 +236,13 @@ bool NotecardConnectionHandler::available() if (J *body = JGetObject(note, "body")) { _topic_type = static_cast(JGetInt(body, "topic")); if (_topic_type == TopicType::Invalid) { - Debug.print(DBG_WARNING, F("Note does not contain a topic")); + DEBUG_WARNING(F("Note does not contain a topic")); } else { buffered_data = JGetBinaryFromObject(note, "payload", &_inbound_buffer, &_inbound_buffer_size); if (!buffered_data) { - Debug.print(DBG_WARNING, F("Note does not contain payload data")); + DEBUG_WARNING(F("Note does not contain payload data")); } else { - Debug.print(DBG_DEBUG, F("NotecardConnectionHandler::%s buffered payload with size: %d"), __FUNCTION__, _inbound_buffer_size); + DEBUG_DEBUG(F("NotecardConnectionHandler::%s buffered payload with size: %d"), __FUNCTION__, _inbound_buffer_size); } } } else { @@ -263,7 +263,7 @@ unsigned long NotecardConnectionHandler::getTime() if (J *rsp = _notecard.requestAndResponse(_notecard.newRequest("card.time"))) { if (NoteResponseError(rsp)) { const char *err = JGetString(rsp, "err"); - Debug.print(DBG_ERROR, F("%s\n"), err); + DEBUG_ERROR(F("%s\n"), err); result = 0; } else { result = JGetInt(rsp, "time"); @@ -298,7 +298,7 @@ int NotecardConnectionHandler::write(const uint8_t * buf_, size_t size_) if ((NetworkConnectionState::INIT == current_net_connection_state) || (NetworkConnectionState::ERROR == current_net_connection_state)) { - Debug.print(DBG_ERROR, F("Unable to write message. Connection to Notecard uninitialized or in error state.")); + DEBUG_ERROR(F("Unable to write message. Connection to Notecard uninitialized or in error state.")); result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; } else if (J * req = _notecard.newRequest("note.add")) { JAddStringToObject(req, "file", NOTEFILE_SECURE_OUTBOUND); @@ -318,11 +318,11 @@ int NotecardConnectionHandler::write(const uint8_t * buf_, size_t size_) if (NoteErrorContains(err, "{hub-not-connected}")) { // _current_net_connection_state = NetworkConnectionState::DISCONNECTED; } - Debug.print(DBG_ERROR, F("%s\n"), err); + DEBUG_ERROR(F("%s\n"), err); result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; } else { result = NotecardCommunicationError::NOTECARD_ERROR_NONE; - Debug.print(DBG_INFO, F("Message sent correctly!")); + DEBUG_INFO(F("Message sent correctly!")); } JDelete(rsp); } else { @@ -404,18 +404,18 @@ NetworkConnectionState NotecardConnectionHandler::update_handleInit() // Check the response for errors if (NoteResponseError(rsp)) { const char *err = JGetString(rsp, "err"); - Debug.print(DBG_ERROR, F("%s"), err); + DEBUG_ERROR(F("%s"), err); result = NetworkConnectionState::ERROR; } else { result = NetworkConnectionState::INIT; } JDelete(rsp); } else { - Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + DEBUG_ERROR(F("Failed to receive response from Notecard.")); result = NetworkConnectionState::ERROR; // Assume the worst } } else { - Debug.print(DBG_ERROR, "Failed to allocate request: card.voltage"); + DEBUG_ERROR("Failed to allocate request: card.voltage"); result = NetworkConnectionState::ERROR; // Assume the worst } } @@ -433,23 +433,23 @@ NetworkConnectionState NotecardConnectionHandler::update_handleInit() // Check the response for errors if (NoteResponseError(rsp)) { const char *err = JGetString(rsp, "err"); - Debug.print(DBG_ERROR, F("%s"), err); + DEBUG_ERROR(F("%s"), err); result = NetworkConnectionState::ERROR; } else { result = NetworkConnectionState::INIT; } JDelete(rsp); } else { - Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + DEBUG_ERROR(F("Failed to receive response from Notecard.")); result = NetworkConnectionState::ERROR; // Assume the worst } } else { - Debug.print(DBG_ERROR, "Failed to allocate request: note.template:body"); + DEBUG_ERROR("Failed to allocate request: note.template:body"); JFree(req); result = NetworkConnectionState::ERROR; // Assume the worst } } else { - Debug.print(DBG_ERROR, "Failed to allocate request: note.template"); + DEBUG_ERROR("Failed to allocate request: note.template"); result = NetworkConnectionState::ERROR; // Assume the worst } } @@ -466,23 +466,23 @@ NetworkConnectionState NotecardConnectionHandler::update_handleInit() // Check the response for errors if (NoteResponseError(rsp)) { const char *err = JGetString(rsp, "err"); - Debug.print(DBG_ERROR, F("%s"), err); + DEBUG_ERROR(F("%s"), err); result = NetworkConnectionState::ERROR; } else { result = NetworkConnectionState::INIT; } JDelete(rsp); } else { - Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + DEBUG_ERROR(F("Failed to receive response from Notecard.")); result = NetworkConnectionState::ERROR; // Assume the worst } } else { - Debug.print(DBG_ERROR, "Failed to allocate request: note.template:body"); + DEBUG_ERROR("Failed to allocate request: note.template:body"); JFree(req); result = NetworkConnectionState::ERROR; // Assume the worst } } else { - Debug.print(DBG_ERROR, "Failed to allocate request: note.template"); + DEBUG_ERROR("Failed to allocate request: note.template"); result = NetworkConnectionState::ERROR; // Assume the worst } } @@ -492,13 +492,13 @@ NetworkConnectionState NotecardConnectionHandler::update_handleInit() if (!updateUidCache()) { result = NetworkConnectionState::ERROR; } else { - Debug.print(DBG_INFO, F("Notecard has been initialized.")); + DEBUG_INFO(F("Notecard has been initialized.")); if (_keep_alive) { _conn_start_ms = ::millis(); - Debug.print(DBG_INFO, F("Starting network connection...")); + DEBUG_INFO(F("Starting network connection...")); result = NetworkConnectionState::CONNECTING; } else { - Debug.print(DBG_INFO, F("Network is disconnected.")); + DEBUG_INFO(F("Network is disconnected.")); result = NetworkConnectionState::DISCONNECTED; } } @@ -517,23 +517,23 @@ NetworkConnectionState NotecardConnectionHandler::update_handleConnecting() // Update the connection state if (!conn_status.connected_to_notehub) { if ((::millis() - _conn_start_ms) > NOTEHUB_CONN_TIMEOUT_MS) { - Debug.print(DBG_ERROR, F("Timeout exceeded, connection to the network failed.")); - Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.connecting); + DEBUG_ERROR(F("Timeout exceeded, connection to the network failed.")); + DEBUG_INFO(F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.connecting); result = NetworkConnectionState::INIT; } else { // Continue awaiting the connection to Notehub if (conn_status.transport_connected) { - Debug.print(DBG_INFO, F("Establishing connection to Notehub...")); + DEBUG_INFO(F("Establishing connection to Notehub...")); } else { - Debug.print(DBG_INFO, F("Connecting to the network...")); + DEBUG_INFO(F("Connecting to the network...")); } result = NetworkConnectionState::CONNECTING; } } else { - Debug.print(DBG_INFO, F("Connected to Notehub!")); + DEBUG_INFO(F("Connected to Notehub!")); result = NetworkConnectionState::CONNECTED; if (initiateNotehubSync()) { - Debug.print(DBG_ERROR, F("Failed to initiate Notehub sync.")); + DEBUG_ERROR(F("Failed to initiate Notehub sync.")); } } @@ -547,9 +547,9 @@ NetworkConnectionState NotecardConnectionHandler::update_handleConnected() const NotecardConnectionStatus conn_status = connected(); if (!conn_status.connected_to_notehub) { if (!conn_status.transport_connected) { - Debug.print(DBG_ERROR, F("Connection to the network lost.")); + DEBUG_ERROR(F("Connection to the network lost.")); } else { - Debug.print(DBG_ERROR, F("Connection to Notehub lost.")); + DEBUG_ERROR(F("Connection to Notehub lost.")); } result = NetworkConnectionState::DISCONNECTED; } else { @@ -563,7 +563,7 @@ NetworkConnectionState NotecardConnectionHandler::update_handleDisconnecting() { NetworkConnectionState result; - Debug.print(DBG_ERROR, F("Connection to the network lost.")); + DEBUG_ERROR(F("Connection to the network lost.")); result = NetworkConnectionState::DISCONNECTED; return result; @@ -575,17 +575,17 @@ NetworkConnectionState NotecardConnectionHandler::update_handleDisconnected() if (_keep_alive) { - Debug.print(DBG_ERROR, F("Attempting reconnection...")); + DEBUG_ERROR(F("Attempting reconnection...")); result = NetworkConnectionState::INIT; } else { if (configureConnection(false)) { result = NetworkConnectionState::CLOSED; - Debug.print(DBG_INFO, F("Closing connection...")); + DEBUG_INFO(F("Closing connection...")); } else { result = NetworkConnectionState::ERROR; - Debug.print(DBG_INFO, F("Error closing connection...")); + DEBUG_INFO(F("Error closing connection...")); } } @@ -608,23 +608,23 @@ bool NotecardConnectionHandler::armInterrupt (void) const // Check the response for errors if (NoteResponseError(rsp)) { const char *err = JGetString(rsp, "err"); - Debug.print(DBG_ERROR, F("%s\n"), err); + DEBUG_ERROR(F("%s\n"), err); result = false; } else { result = true; } JDelete(rsp); } else { - Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + DEBUG_ERROR(F("Failed to receive response from Notecard.")); result = false; } } else { - Debug.print(DBG_ERROR, "Failed to allocate request: card.attn:files"); + DEBUG_ERROR("Failed to allocate request: card.attn:files"); JFree(req); result = false; } } else { - Debug.print(DBG_ERROR, "Failed to allocate request: card.attn"); + DEBUG_ERROR("Failed to allocate request: card.attn"); result = false; } @@ -659,18 +659,18 @@ bool NotecardConnectionHandler::configureConnection (bool connect_) const // Check the response for errors if (NoteResponseError(rsp)) { const char *err = JGetString(rsp, "err"); - Debug.print(DBG_ERROR, F("%s"), err); + DEBUG_ERROR(F("%s"), err); result = false; } else { result = true; } JDelete(rsp); } else { - Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + DEBUG_ERROR(F("Failed to receive response from Notecard.")); result = false; // Assume the worst } } else { - Debug.print(DBG_ERROR, "Failed to allocate request: hub.set"); + DEBUG_ERROR("Failed to allocate request: hub.set"); result = false; // Assume the worst } @@ -686,7 +686,7 @@ uint_fast8_t NotecardConnectionHandler::connected (void) const // Ensure the transaction doesn't return an error if (NoteResponseError(rsp)) { const char *err = JGetString(rsp, "err"); - Debug.print(DBG_ERROR, F("%s"),err); + DEBUG_ERROR(F("%s"),err); result.notecard_error = true; } else { // Parse the transport connection status @@ -703,7 +703,7 @@ uint_fast8_t NotecardConnectionHandler::connected (void) const // Free the response JDelete(rsp); } else { - Debug.print(DBG_ERROR, F("Failed to acquire Notecard connection status.")); + DEBUG_ERROR(F("Failed to acquire Notecard connection status.")); result.transport_connected = false; result.connected_to_notehub = false; result.notecard_error = false; @@ -744,11 +744,11 @@ J * NotecardConnectionHandler::getNote (bool pop_) const result = note; } } else { - Debug.print(DBG_ERROR, F("Failed to receive response from Notecard.")); + DEBUG_ERROR(F("Failed to receive response from Notecard.")); result = nullptr; } } else { - Debug.print(DBG_ERROR, "Failed to allocate request: note.get"); + DEBUG_ERROR("Failed to allocate request: note.get"); // Failed to retrieve a Note, therefore no Note is available. result = nullptr; } @@ -769,8 +769,8 @@ bool NotecardConnectionHandler::updateUidCache (void) // Check the response for errors if (NoteResponseError(rsp)) { const char *err = JGetString(rsp, "err"); - Debug.print(DBG_ERROR, F("Failed to read Notecard UID")); - Debug.print(DBG_ERROR, F("Error: %s"), err); + DEBUG_ERROR(F("Failed to read Notecard UID")); + DEBUG_ERROR(F("Error: %s"), err); result = false; } else { _notecard_uid = JGetString(rsp, "device"); @@ -778,14 +778,14 @@ bool NotecardConnectionHandler::updateUidCache (void) if (NoteGetEnv("_arduino_device_id", device_id, device_id, sizeof(device_id))) { _device_id = device_id; } else { - Debug.print(DBG_DEBUG, F("NotecardConnectionHandler::%s Arduino Device ID not cached on Notecard, using default value: <%s>"), __FUNCTION__, _device_id.c_str()); + DEBUG_DEBUG(F("NotecardConnectionHandler::%s Arduino Device ID not cached on Notecard, using default value: <%s>"), __FUNCTION__, _device_id.c_str()); } - Debug.print(DBG_DEBUG, F("NotecardConnectionHandler::%s updated local cache with Notecard UID: <%s> and Arduino Device ID: <%s>"), __FUNCTION__, _notecard_uid.c_str(), _device_id.c_str()); + DEBUG_DEBUG(F("NotecardConnectionHandler::%s updated local cache with Notecard UID: <%s> and Arduino Device ID: <%s>"), __FUNCTION__, _notecard_uid.c_str(), _device_id.c_str()); result = true; } JDelete(rsp); } else { - Debug.print(DBG_ERROR, F("Failed to read Notecard UID")); + DEBUG_ERROR(F("Failed to read Notecard UID")); result = false; } diff --git a/src/WiFiConnectionHandler.cpp b/src/WiFiConnectionHandler.cpp index 8db1b2c6..f6d4ce84 100644 --- a/src/WiFiConnectionHandler.cpp +++ b/src/WiFiConnectionHandler.cpp @@ -67,28 +67,28 @@ unsigned long WiFiConnectionHandler::getTime() NetworkConnectionState WiFiConnectionHandler::update_handleInit() { #if !defined(__AVR__) - Debug.print(DBG_INFO, F("WiFi.status(): %d"), WiFi.status()); + DEBUG_INFO(F("WiFi.status(): %d"), WiFi.status()); #endif #if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) if (WiFi.status() == NETWORK_HARDWARE_ERROR) { #if !defined(__AVR__) - Debug.print(DBG_ERROR, F("WiFi Hardware failure.\nMake sure you are using a WiFi enabled board/shield.")); - Debug.print(DBG_ERROR, F("Then reset and retry.")); + DEBUG_ERROR(F("WiFi Hardware failure.\nMake sure you are using a WiFi enabled board/shield.")); + DEBUG_ERROR(F("Then reset and retry.")); #endif return NetworkConnectionState::ERROR; } #if !defined(__AVR__) - Debug.print(DBG_INFO, F("Current WiFi Firmware: %s"), WiFi.firmwareVersion()); + DEBUG_INFO(F("Current WiFi Firmware: %s"), WiFi.firmwareVersion()); #endif #if defined(WIFI_FIRMWARE_VERSION_REQUIRED) if (String(WiFi.firmwareVersion()) < String(WIFI_FIRMWARE_VERSION_REQUIRED)) { #if !defined(__AVR__) - Debug.print(DBG_ERROR, F("Latest WiFi Firmware: %s"), WIFI_FIRMWARE_VERSION_REQUIRED); - Debug.print(DBG_ERROR, F("Please update to the latest version for best performance.")); + DEBUG_ERROR(F("Latest WiFi Firmware: %s"), WIFI_FIRMWARE_VERSION_REQUIRED); + DEBUG_ERROR(F("Please update to the latest version for best performance.")); #endif delay(5000); } @@ -113,15 +113,15 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit() if (WiFi.status() != NETWORK_CONNECTED) { #if !defined(__AVR__) - Debug.print(DBG_ERROR, F("Connection to \"%s\" failed"), _settings.wifi.ssid); - Debug.print(DBG_INFO, F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.init); + DEBUG_ERROR(F("Connection to \"%s\" failed"), _settings.wifi.ssid); + DEBUG_INFO(F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.init); #endif return NetworkConnectionState::INIT; } else { #if !defined(__AVR__) - Debug.print(DBG_INFO, F("Connected to \"%s\""), _settings.wifi.ssid); + DEBUG_INFO(F("Connected to \"%s\""), _settings.wifi.ssid); #endif #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) configTime(0, 0, "time.arduino.cc", "pool.ntp.org", "time.nist.gov"); @@ -142,15 +142,15 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting() #if !defined(ARDUINO_ARCH_ESP8266) && !defined(ARDUINO_ARCH_ESP32) int ping_result = WiFi.ping("time.arduino.cc"); - Debug.print(DBG_INFO, F("WiFi.ping(): %d"), ping_result); + DEBUG_INFO(F("WiFi.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"), _timeoutTable.timeout.connecting); + DEBUG_ERROR(F("Internet check failed")); + DEBUG_INFO(F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.connecting); return NetworkConnectionState::CONNECTING; } #endif - Debug.print(DBG_INFO, F("Connected to Internet")); + DEBUG_INFO(F("Connected to Internet")); return NetworkConnectionState::CONNECTED; } @@ -160,13 +160,13 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnected() if (WiFi.status() != WL_CONNECTED) { #if !defined(__AVR__) - Debug.print(DBG_VERBOSE, F("WiFi.status(): %d"), WiFi.status()); - Debug.print(DBG_ERROR, F("Connection to \"%s\" lost."), _settings.wifi.ssid); + DEBUG_VERBOSE(F("WiFi.status(): %d"), WiFi.status()); + DEBUG_ERROR(F("Connection to \"%s\" lost."), _settings.wifi.ssid); #endif if (_keep_alive) { #if !defined(__AVR__) - Debug.print(DBG_INFO, F("Attempting reconnection")); + DEBUG_INFO(F("Attempting reconnection")); #endif } From a624383eef4b35ef75603fda7f2ee87cc1ba7c68 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Aug 2025 13:27:55 +0000 Subject: [PATCH 196/203] Bump actions/download-artifact from 4 to 5 Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 4 to 5. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 53a9f54f..72ec06b0 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -108,7 +108,7 @@ jobs: uses: actions/checkout@v4 - name: Download configuration files artifact - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v5 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} path: ${{ env.CONFIGURATIONS_FOLDER }} From ac92c2607337c4135f62ca7e19baa87096b99939 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Aug 2025 18:32:16 +0000 Subject: [PATCH 197/203] Bump actions/checkout from 4 to 5 Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/check-arduino.yml | 2 +- .github/workflows/compile-examples.yml | 6 +++--- .github/workflows/spell-check.yml | 2 +- .github/workflows/sync-labels.yml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index e8186852..e13b9907 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Arduino Lint uses: arduino/arduino-lint-action@v2 diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 5541359d..ff8b3839 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -195,13 +195,13 @@ jobs: - examples/ConnectionHandlerDemo-Notecard steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 # It's necessary to checkout the platform before installing it so that the ArduinoCore-API dependency can be added - name: Checkout ArduinoCore-mbed # this step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used if: matrix.board.platform-name == 'arduino:mbed' - uses: actions/checkout@v4 + uses: actions/checkout@v5 with: repository: arduino/ArduinoCore-mbed # The arduino/actions/libraries/compile-examples action will install the platform from this path @@ -210,7 +210,7 @@ jobs: - name: Checkout ArduinoCore-API # This step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used if: matrix.board.platform-name == 'arduino:mbed' - uses: actions/checkout@v4 + uses: actions/checkout@v5 with: repository: arduino/ArduinoCore-API path: ${{ env.ARDUINOCORE_API_STAGING_PATH }} diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index ef7d8941..19f5d38f 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Spell check uses: codespell-project/actions-codespell@master diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 72ec06b0..62c898a4 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Download JSON schema for labels configuration file id: download-schema @@ -105,7 +105,7 @@ jobs: echo "::set-output name=flag::--dry-run" - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Download configuration files artifact uses: actions/download-artifact@v5 From 1e4189fc811fa89db16dcdf63f1cd50c0b5f431f Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 8 Sep 2025 15:29:53 +0200 Subject: [PATCH 198/203] library: change license to MPL --- LICENSE | 1047 ++++++++++------------------ src/Arduino_ConnectionHandler.h | 19 +- src/CatM1ConnectionHandler.cpp | 25 +- src/CatM1ConnectionHandler.h | 21 +- src/CellularConnectionHandler.cpp | 8 +- src/CellularConnectionHandler.h | 4 +- src/ConnectionHandlerDefinitions.h | 23 +- src/ConnectionHandlerInterface.cpp | 23 +- src/ConnectionHandlerInterface.h | 24 +- src/EthernetConnectionHandler.cpp | 24 +- src/EthernetConnectionHandler.h | 22 +- src/GSMConnectionHandler.cpp | 29 +- src/GSMConnectionHandler.h | 21 +- src/GenericConnectionHandler.cpp | 2 +- src/GenericConnectionHandler.h | 4 +- src/LoRaConnectionHandler.cpp | 27 +- src/LoRaConnectionHandler.h | 21 +- src/NBConnectionHandler.cpp | 29 +- src/NBConnectionHandler.h | 21 +- src/NotecardConnectionHandler.cpp | 26 +- src/NotecardConnectionHandler.h | 6 +- src/WiFiConnectionHandler.cpp | 27 +- src/WiFiConnectionHandler.h | 21 +- 23 files changed, 533 insertions(+), 941 deletions(-) diff --git a/LICENSE b/LICENSE index f288702d..dbdb0fa8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,674 +1,373 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at https://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. \ No newline at end of file diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index 48327268..c7a2dcf4 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -1,25 +1,18 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2019 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef ARDUINO_CONNECTION_HANDLER_H_ #define ARDUINO_CONNECTION_HANDLER_H_ /****************************************************************************** - INCLUDES + INCLUDES ******************************************************************************/ #if !defined(__AVR__) diff --git a/src/CatM1ConnectionHandler.cpp b/src/CatM1ConnectionHandler.cpp index 1d8db630..16f0db93 100644 --- a/src/CatM1ConnectionHandler.cpp +++ b/src/CatM1ConnectionHandler.cpp @@ -1,22 +1,15 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2023 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerDefinitions.h" @@ -25,7 +18,7 @@ #include "CatM1ConnectionHandler.h" /****************************************************************************** - CTOR/DTOR + CTOR/DTOR ******************************************************************************/ CatM1ConnectionHandler::CatM1ConnectionHandler() @@ -49,7 +42,7 @@ CatM1ConnectionHandler::CatM1ConnectionHandler( } /****************************************************************************** - PUBLIC MEMBER FUNCTIONS + PUBLIC MEMBER FUNCTIONS ******************************************************************************/ unsigned long CatM1ConnectionHandler::getTime() @@ -61,7 +54,7 @@ unsigned long CatM1ConnectionHandler::getTime() } /****************************************************************************** - PROTECTED MEMBER FUNCTIONS + PROTECTED MEMBER FUNCTIONS ******************************************************************************/ NetworkConnectionState CatM1ConnectionHandler::update_handleInit() diff --git a/src/CatM1ConnectionHandler.h b/src/CatM1ConnectionHandler.h index 37c92058..23115898 100644 --- a/src/CatM1ConnectionHandler.h +++ b/src/CatM1ConnectionHandler.h @@ -1,25 +1,18 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2023 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef ARDUINO_CATM1_CONNECTION_HANDLER_H_ #define ARDUINO_CATM1_CONNECTION_HANDLER_H_ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerInterface.h" @@ -33,7 +26,7 @@ #endif /****************************************************************************** - CLASS DECLARATION + CLASS DECLARATION ******************************************************************************/ class CatM1ConnectionHandler : public ConnectionHandler diff --git a/src/CellularConnectionHandler.cpp b/src/CellularConnectionHandler.cpp index 324bec43..b73f5866 100644 --- a/src/CellularConnectionHandler.cpp +++ b/src/CellularConnectionHandler.cpp @@ -10,7 +10,7 @@ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerDefinitions.h" @@ -19,7 +19,7 @@ #include "CellularConnectionHandler.h" /****************************************************************************** - CTOR/DTOR + CTOR/DTOR ******************************************************************************/ CellularConnectionHandler::CellularConnectionHandler() : ConnectionHandler(true, NetworkAdapter::CELL) {} @@ -36,7 +36,7 @@ CellularConnectionHandler::CellularConnectionHandler(const char * pin, const cha } /****************************************************************************** - PUBLIC MEMBER FUNCTIONS + PUBLIC MEMBER FUNCTIONS ******************************************************************************/ unsigned long CellularConnectionHandler::getTime() @@ -51,7 +51,7 @@ UDP & CellularConnectionHandler::getUDP() } /****************************************************************************** - PROTECTED MEMBER FUNCTIONS + PROTECTED MEMBER FUNCTIONS ******************************************************************************/ NetworkConnectionState CellularConnectionHandler::update_handleInit() diff --git a/src/CellularConnectionHandler.h b/src/CellularConnectionHandler.h index fcc02c66..7a5f00b1 100644 --- a/src/CellularConnectionHandler.h +++ b/src/CellularConnectionHandler.h @@ -13,7 +13,7 @@ #define ARDUINO_CELLULAR_CONNECTION_HANDLER_H_ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerInterface.h" @@ -27,7 +27,7 @@ #endif /****************************************************************************** - CLASS DECLARATION + CLASS DECLARATION ******************************************************************************/ class CellularConnectionHandler : public ConnectionHandler diff --git a/src/ConnectionHandlerDefinitions.h b/src/ConnectionHandlerDefinitions.h index 3479d83f..1534e473 100644 --- a/src/ConnectionHandlerDefinitions.h +++ b/src/ConnectionHandlerDefinitions.h @@ -1,24 +1,17 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2024 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #pragma once /****************************************************************************** - INCLUDES + INCLUDES ******************************************************************************/ #if defined __has_include @@ -154,7 +147,7 @@ #endif // BOARD_HAS_NOTECARD /****************************************************************************** - TYPEDEFS + TYPEDEFS ******************************************************************************/ enum class NetworkConnectionState : unsigned int { @@ -201,7 +194,7 @@ union TimeoutTable { }; /****************************************************************************** - CONSTANTS + CONSTANTS ******************************************************************************/ constexpr TimeoutTable DefaultTimeoutTable { diff --git a/src/ConnectionHandlerInterface.cpp b/src/ConnectionHandlerInterface.cpp index 44dbd72e..e206b850 100644 --- a/src/ConnectionHandlerInterface.cpp +++ b/src/ConnectionHandlerInterface.cpp @@ -1,28 +1,21 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2024 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerInterface.h" /****************************************************************************** - CONSTRUCTOR/DESTRUCTOR + CONSTRUCTOR/DESTRUCTOR ******************************************************************************/ ConnectionHandler::ConnectionHandler(bool const keep_alive, NetworkAdapter interface) @@ -37,7 +30,7 @@ ConnectionHandler::ConnectionHandler(bool const keep_alive, NetworkAdapter inter } /****************************************************************************** - PUBLIC MEMBER FUNCTIONS + PUBLIC MEMBER FUNCTIONS ******************************************************************************/ NetworkConnectionState ConnectionHandler::check() diff --git a/src/ConnectionHandlerInterface.h b/src/ConnectionHandlerInterface.h index e76f1036..cfdebd38 100644 --- a/src/ConnectionHandlerInterface.h +++ b/src/ConnectionHandlerInterface.h @@ -1,24 +1,17 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2024 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #pragma once /****************************************************************************** - INCLUDES + INCLUDES ******************************************************************************/ #if !defined(__AVR__) @@ -34,13 +27,13 @@ #include /****************************************************************************** - TYPEDEFS + TYPEDEFS ******************************************************************************/ typedef void (*OnNetworkEventCallback)(); /****************************************************************************** - CLASS DECLARATION + CLASS DECLARATION ******************************************************************************/ // forward declaration FIXME @@ -143,4 +136,3 @@ class ConnectionHandler { friend GenericConnectionHandler; }; - diff --git a/src/EthernetConnectionHandler.cpp b/src/EthernetConnectionHandler.cpp index e86762f0..9ef06cfb 100644 --- a/src/EthernetConnectionHandler.cpp +++ b/src/EthernetConnectionHandler.cpp @@ -1,19 +1,15 @@ /* - This file is part of ArduinoIoTCloud. - Copyright 2020 ARDUINO SA (http://www.arduino.cc/) - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This file is part of the Arduino_ConnectionHandler library. + + Copyright (c) 2020 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerDefinitions.h" @@ -22,7 +18,7 @@ #include "EthernetConnectionHandler.h" /****************************************************************************** - CTOR/DTOR + CTOR/DTOR ******************************************************************************/ static inline void fromIPAddress(const IPAddress src, models::ip_addr& dst) { @@ -65,7 +61,7 @@ EthernetConnectionHandler::EthernetConnectionHandler( } /****************************************************************************** - PROTECTED MEMBER FUNCTIONS + PROTECTED MEMBER FUNCTIONS ******************************************************************************/ NetworkConnectionState EthernetConnectionHandler::update_handleInit() diff --git a/src/EthernetConnectionHandler.h b/src/EthernetConnectionHandler.h index 738b6a8c..82dc8933 100644 --- a/src/EthernetConnectionHandler.h +++ b/src/EthernetConnectionHandler.h @@ -1,22 +1,18 @@ /* - This file is part of ArduinoIoTCloud. - Copyright 2020 ARDUINO SA (http://www.arduino.cc/) - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This file is part of the Arduino_ConnectionHandler library. + + Copyright (c) 2020 Arduino SA + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef ARDUINO_ETHERNET_CONNECTION_HANDLER_H_ #define ARDUINO_ETHERNET_CONNECTION_HANDLER_H_ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerInterface.h" @@ -37,7 +33,7 @@ #endif /****************************************************************************** - CLASS DECLARATION + CLASS DECLARATION ******************************************************************************/ class EthernetConnectionHandler : public ConnectionHandler diff --git a/src/GSMConnectionHandler.cpp b/src/GSMConnectionHandler.cpp index 3bd7b64e..82362f88 100644 --- a/src/GSMConnectionHandler.cpp +++ b/src/GSMConnectionHandler.cpp @@ -1,22 +1,15 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2019 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerDefinitions.h" @@ -25,14 +18,14 @@ #include "GSMConnectionHandler.h" /****************************************************************************** - CONSTANTS + CONSTANTS ******************************************************************************/ static int const GSM_TIMEOUT = 30000; static int const GPRS_TIMEOUT = 30000; /****************************************************************************** - FUNCTION DEFINITION + FUNCTION DEFINITION ******************************************************************************/ __attribute__((weak)) void mkr_gsm_feed_watchdog() @@ -44,7 +37,7 @@ __attribute__((weak)) void mkr_gsm_feed_watchdog() } /****************************************************************************** - CTOR/DTOR + CTOR/DTOR ******************************************************************************/ GSMConnectionHandler::GSMConnectionHandler() : ConnectionHandler(true, NetworkAdapter::GSM) {} @@ -62,7 +55,7 @@ GSMConnectionHandler::GSMConnectionHandler(const char * pin, const char * apn, c } /****************************************************************************** - PUBLIC MEMBER FUNCTIONS + PUBLIC MEMBER FUNCTIONS ******************************************************************************/ unsigned long GSMConnectionHandler::getTime() @@ -71,7 +64,7 @@ unsigned long GSMConnectionHandler::getTime() } /****************************************************************************** - PROTECTED MEMBER FUNCTIONS + PROTECTED MEMBER FUNCTIONS ******************************************************************************/ NetworkConnectionState GSMConnectionHandler::update_handleInit() diff --git a/src/GSMConnectionHandler.h b/src/GSMConnectionHandler.h index 891fb989..15e5047d 100644 --- a/src/GSMConnectionHandler.h +++ b/src/GSMConnectionHandler.h @@ -1,25 +1,18 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2019 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef GSM_CONNECTION_MANAGER_H_ #define GSM_CONNECTION_MANAGER_H_ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerInterface.h" @@ -33,7 +26,7 @@ #endif /****************************************************************************** - CLASS DECLARATION + CLASS DECLARATION ******************************************************************************/ class GSMConnectionHandler : public ConnectionHandler diff --git a/src/GenericConnectionHandler.cpp b/src/GenericConnectionHandler.cpp index bcda5c12..a6076819 100644 --- a/src/GenericConnectionHandler.cpp +++ b/src/GenericConnectionHandler.cpp @@ -9,7 +9,7 @@ */ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "GenericConnectionHandler.h" diff --git a/src/GenericConnectionHandler.h b/src/GenericConnectionHandler.h index 5468e438..81df0f79 100644 --- a/src/GenericConnectionHandler.h +++ b/src/GenericConnectionHandler.h @@ -12,13 +12,13 @@ #define ARDUINO_GENERIC_CONNECTION_HANDLER_H_ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerInterface.h" /****************************************************************************** - CLASS DECLARATION + CLASS DECLARATION ******************************************************************************/ /** GenericConnectionHandler class diff --git a/src/LoRaConnectionHandler.cpp b/src/LoRaConnectionHandler.cpp index 612751fb..19006bcd 100644 --- a/src/LoRaConnectionHandler.cpp +++ b/src/LoRaConnectionHandler.cpp @@ -1,22 +1,15 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2019 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerDefinitions.h" @@ -25,7 +18,7 @@ #include "LoRaConnectionHandler.h" /****************************************************************************** - TYPEDEF + TYPEDEF ******************************************************************************/ typedef enum @@ -42,7 +35,7 @@ typedef enum } LoRaCommunicationError; /****************************************************************************** - CTOR/DTOR + CTOR/DTOR ******************************************************************************/ LoRaConnectionHandler::LoRaConnectionHandler(char const * appeui, char const * appkey, _lora_band const band, char const * channelMask, _lora_class const device_class) : ConnectionHandler{false, NetworkAdapter::LORA} @@ -56,7 +49,7 @@ LoRaConnectionHandler::LoRaConnectionHandler(char const * appeui, char const * a } /****************************************************************************** - PUBLIC MEMBER FUNCTIONS + PUBLIC MEMBER FUNCTIONS ******************************************************************************/ int LoRaConnectionHandler::write(const uint8_t * buf, size_t size) @@ -116,7 +109,7 @@ bool LoRaConnectionHandler::available() } /****************************************************************************** - PROTECTED MEMBER FUNCTIONS + PROTECTED MEMBER FUNCTIONS ******************************************************************************/ NetworkConnectionState LoRaConnectionHandler::update_handleInit() diff --git a/src/LoRaConnectionHandler.h b/src/LoRaConnectionHandler.h index cecf8302..b56505a1 100644 --- a/src/LoRaConnectionHandler.h +++ b/src/LoRaConnectionHandler.h @@ -1,25 +1,18 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2019 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef ARDUINO_LORA_CONNECTION_HANDLER_H_ #define ARDUINO_LORA_CONNECTION_HANDLER_H_ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerInterface.h" @@ -34,7 +27,7 @@ /****************************************************************************** - CLASS DECLARATION + CLASS DECLARATION ******************************************************************************/ class LoRaConnectionHandler : public ConnectionHandler diff --git a/src/NBConnectionHandler.cpp b/src/NBConnectionHandler.cpp index 74db3d80..4da9fd62 100644 --- a/src/NBConnectionHandler.cpp +++ b/src/NBConnectionHandler.cpp @@ -1,22 +1,15 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2019 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerDefinitions.h" @@ -25,13 +18,13 @@ #include "NBConnectionHandler.h" /****************************************************************************** - CONSTANTS + CONSTANTS ******************************************************************************/ static int const NB_TIMEOUT = 30000; /****************************************************************************** - FUNCTION DEFINITION + FUNCTION DEFINITION ******************************************************************************/ __attribute__((weak)) void mkr_nb_feed_watchdog() @@ -43,7 +36,7 @@ __attribute__((weak)) void mkr_nb_feed_watchdog() } /****************************************************************************** - CTOR/DTOR + CTOR/DTOR ******************************************************************************/ NBConnectionHandler::NBConnectionHandler() @@ -72,7 +65,7 @@ NBConnectionHandler::NBConnectionHandler(char const * pin, char const * apn, cha } /****************************************************************************** - PUBLIC MEMBER FUNCTIONS + PUBLIC MEMBER FUNCTIONS ******************************************************************************/ unsigned long NBConnectionHandler::getTime() @@ -81,7 +74,7 @@ unsigned long NBConnectionHandler::getTime() } /****************************************************************************** - PRIVATE MEMBER FUNCTIONS + PRIVATE MEMBER FUNCTIONS ******************************************************************************/ NetworkConnectionState NBConnectionHandler::update_handleInit() diff --git a/src/NBConnectionHandler.h b/src/NBConnectionHandler.h index 6641bb69..a271199a 100644 --- a/src/NBConnectionHandler.h +++ b/src/NBConnectionHandler.h @@ -1,25 +1,18 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2019 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef NB_CONNECTION_MANAGER_H_ #define NB_CONNECTION_MANAGER_H_ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerInterface.h" @@ -33,7 +26,7 @@ #endif /****************************************************************************** - CLASS DECLARATION + CLASS DECLARATION ******************************************************************************/ class NBConnectionHandler : public ConnectionHandler diff --git a/src/NotecardConnectionHandler.cpp b/src/NotecardConnectionHandler.cpp index c26a7484..80cd0145 100644 --- a/src/NotecardConnectionHandler.cpp +++ b/src/NotecardConnectionHandler.cpp @@ -9,7 +9,7 @@ */ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerDefinitions.h" @@ -23,7 +23,7 @@ #include /****************************************************************************** - DEFINES + DEFINES ******************************************************************************/ #define NO_INBOUND_POLLING -1 @@ -40,7 +40,7 @@ #define NOTEFILE_SECURE_OUTBOUND NOTEFILE_BASE_NAME ".qos" /****************************************************************************** - STLINK DEBUG OUTPUT + STLINK DEBUG OUTPUT ******************************************************************************/ // Provide Notehub debug output via STLINK serial port when available @@ -50,7 +50,7 @@ #endif /****************************************************************************** - TYPEDEF + TYPEDEF ******************************************************************************/ struct NotecardConnectionStatus @@ -78,7 +78,7 @@ struct NotecardConnectionStatus static_assert(sizeof(NotecardConnectionStatus) == sizeof(uint_fast8_t)); /****************************************************************************** - CTOR/DTOR + CTOR/DTOR ******************************************************************************/ NotecardConnectionHandler::NotecardConnectionHandler( @@ -133,7 +133,7 @@ NotecardConnectionHandler::NotecardConnectionHandler( { } /****************************************************************************** - PUBLIC MEMBER FUNCTIONS + PUBLIC MEMBER FUNCTIONS ******************************************************************************/ int NotecardConnectionHandler::initiateNotehubSync (SyncType type_) const @@ -208,7 +208,7 @@ int NotecardConnectionHandler::setWiFiCredentials (const String & ssid_, const S } /****************************************************************************** - PUBLIC INTERFACE MEMBER FUNCTIONS + PUBLIC INTERFACE MEMBER FUNCTIONS ******************************************************************************/ bool NotecardConnectionHandler::available() @@ -337,15 +337,15 @@ int NotecardConnectionHandler::write(const uint8_t * buf_, size_t size_) } /****************************************************************************** - PROTECTED STATE MACHINE FUNCTIONS + PROTECTED STATE MACHINE FUNCTIONS ******************************************************************************/ NetworkConnectionState NotecardConnectionHandler::update_handleInit() { NetworkConnectionState result = NetworkConnectionState::INIT; - // Configure Hardware -/////////////////////// + // Configure Hardware + /////////////////////// #if defined(STLINK_DEBUG) // Output Notecard logs to the STLINK serial port @@ -363,7 +363,7 @@ NetworkConnectionState NotecardConnectionHandler::update_handleInit() _notecard.begin(_i2c_address, _i2c_max, *_wire); } - // Configure `note-c` + // Configure `note-c` /////////////////////// // Set the user agent @@ -377,7 +377,7 @@ NetworkConnectionState NotecardConnectionHandler::update_handleInit() JDelete(note); } - // Configure the Notecard + // Configure the Notecard /////////////////////////// // Set the project UID @@ -593,7 +593,7 @@ NetworkConnectionState NotecardConnectionHandler::update_handleDisconnected() } /****************************************************************************** - PRIVATE MEMBER FUNCTIONS + PRIVATE MEMBER FUNCTIONS ******************************************************************************/ bool NotecardConnectionHandler::armInterrupt (void) const diff --git a/src/NotecardConnectionHandler.h b/src/NotecardConnectionHandler.h index 4278c144..7e84fc51 100644 --- a/src/NotecardConnectionHandler.h +++ b/src/NotecardConnectionHandler.h @@ -12,7 +12,7 @@ #define ARDUINO_NOTECARD_CONNECTION_HANDLER_H_ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include @@ -24,7 +24,7 @@ #include "ConnectionHandlerInterface.h" /****************************************************************************** - DEFINES + DEFINES ******************************************************************************/ #define NOTECARD_CONNECTION_HANDLER_VERSION_MAJOR 1 @@ -34,7 +34,7 @@ #define NOTECARD_CONNECTION_HANDLER_VERSION NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_MAJOR) "." NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_MINOR) "." NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_PATCH) /****************************************************************************** - CLASS DECLARATION + CLASS DECLARATION ******************************************************************************/ /** diff --git a/src/WiFiConnectionHandler.cpp b/src/WiFiConnectionHandler.cpp index f6d4ce84..54dd61b5 100644 --- a/src/WiFiConnectionHandler.cpp +++ b/src/WiFiConnectionHandler.cpp @@ -1,22 +1,15 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2019 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerDefinitions.h" @@ -25,14 +18,14 @@ #include "WiFiConnectionHandler.h" /****************************************************************************** - CONSTANTS + CONSTANTS ******************************************************************************/ #if defined(ARDUINO_ARCH_ESP8266) static int const ESP_WIFI_CONNECTION_TIMEOUT = 3000; #endif /****************************************************************************** - CTOR/DTOR + CTOR/DTOR ******************************************************************************/ WiFiConnectionHandler::WiFiConnectionHandler() @@ -48,7 +41,7 @@ WiFiConnectionHandler::WiFiConnectionHandler(char const * ssid, char const * pas } /****************************************************************************** - PUBLIC MEMBER FUNCTIONS + PUBLIC MEMBER FUNCTIONS ******************************************************************************/ unsigned long WiFiConnectionHandler::getTime() @@ -61,7 +54,7 @@ unsigned long WiFiConnectionHandler::getTime() } /****************************************************************************** - PROTECTED MEMBER FUNCTIONS + PROTECTED MEMBER FUNCTIONS ******************************************************************************/ NetworkConnectionState WiFiConnectionHandler::update_handleInit() diff --git a/src/WiFiConnectionHandler.h b/src/WiFiConnectionHandler.h index 1d360b70..1c12c998 100644 --- a/src/WiFiConnectionHandler.h +++ b/src/WiFiConnectionHandler.h @@ -1,25 +1,18 @@ /* - This file is part of ArduinoIoTCloud. + This file is part of the Arduino_ConnectionHandler library. - Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + Copyright (c) 2019 Arduino SA - This software is released under the GNU General Public License version 3, - which covers the main part of arduino-cli. - The terms of this license can be found at: - https://www.gnu.org/licenses/gpl-3.0.en.html - - You can be released from the requirements of the above licenses by purchasing - a commercial license. Buying such a license is mandatory if you want to modify or - otherwise use the software for commercial activities involving the Arduino - software without disclosing the source code of your own applications. To purchase - a commercial license, send an email to license@arduino.cc. + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef ARDUINO_WIFI_CONNECTION_HANDLER_H_ #define ARDUINO_WIFI_CONNECTION_HANDLER_H_ /****************************************************************************** - INCLUDE + INCLUDE ******************************************************************************/ #include "ConnectionHandlerInterface.h" @@ -56,7 +49,7 @@ #endif /****************************************************************************** - CLASS DECLARATION + CLASS DECLARATION ******************************************************************************/ class WiFiConnectionHandler : public ConnectionHandler From b54a53be3d94d057faa5798bbe9bb52439a3f871 Mon Sep 17 00:00:00 2001 From: Mattia Pennasilico Date: Tue, 9 Sep 2025 08:30:10 +0200 Subject: [PATCH 199/203] Publish 1.2.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 04fd42ad..9ad0dc11 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_ConnectionHandler -version=1.1.2 +version=1.2.0 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet], Notecard) From 8657cc2ccb0e5de3b12fa065b523e63740069026 Mon Sep 17 00:00:00 2001 From: "Zachary J. Fields" Date: Thu, 23 Oct 2025 16:15:08 -0500 Subject: [PATCH 200/203] Deprecate Blues Notecard support --- .github/workflows/compile-examples.yml | 39 - README.md | 5 +- .../ConnectionHandlerDemo-Notecard.ino | 144 ---- .../ConnectionHandlerDemo-Notecard/README.md | 71 -- .../arduino_secrets.h | 5 - keywords.txt | 5 - library.properties | 4 +- src/Arduino_ConnectionHandler.h | 6 - src/ConnectionHandlerDefinitions.h | 15 +- src/NotecardConnectionHandler.cpp | 795 ------------------ src/NotecardConnectionHandler.h | 342 -------- 11 files changed, 5 insertions(+), 1426 deletions(-) delete mode 100644 examples/ConnectionHandlerDemo-Notecard/ConnectionHandlerDemo-Notecard.ino delete mode 100644 examples/ConnectionHandlerDemo-Notecard/README.md delete mode 100644 examples/ConnectionHandlerDemo-Notecard/arduino_secrets.h delete mode 100644 src/NotecardConnectionHandler.cpp delete mode 100644 src/NotecardConnectionHandler.h diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index ff8b3839..9bcd8314 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -35,7 +35,6 @@ jobs: - name: MKRNB - name: MKRWAN - name: Arduino_Cellular - - name: Blues Wireless Notecard SKETCH_PATHS: | - examples/ConnectionHandlerDemo - examples/CheckInternetAvailabilityDemo @@ -113,8 +112,6 @@ jobs: platforms: | # Install Arduino SAMD Boards via Boards Manager - name: arduino:samd - sketch-paths: | - - examples/ConnectionHandlerDemo-Notecard - board: platform-name: arduino:mbed platforms: | @@ -123,53 +120,21 @@ jobs: # Overwrite the Arduino mbed-Enabled Boards release version with version from the tip of the default branch (located in local path because of the need to first install ArduinoCore-API) - source-path: extras/ArduinoCore-mbed name: arduino:mbed - sketch-paths: | - - examples/ConnectionHandlerDemo-Notecard - - board: - platform-name: arduino:mbed_portenta - sketch-paths: | - - examples/ConnectionHandlerDemo-Notecard - - board: - platform-name: arduino:mbed_nano - sketch-paths: | - - examples/ConnectionHandlerDemo-Notecard - - board: - platform-name: arduino:mbed_nicla - sketch-paths: | - - examples/ConnectionHandlerDemo-Notecard - - board: - platform-name: arduino:mbed_opta - sketch-paths: | - - examples/ConnectionHandlerDemo-Notecard - - board: - platform-name: arduino:mbed_giga - sketch-paths: | - - examples/ConnectionHandlerDemo-Notecard - - board: - platform-name: arduino:mbed_edge - sketch-paths: | - - examples/ConnectionHandlerDemo-Notecard - board: platform-name: arduino:renesas_portenta platforms: | # Install Arduino Renesas portenta Boards via Boards Manager - name: arduino:renesas_portenta - sketch-paths: | - - examples/ConnectionHandlerDemo-Notecard - board: platform-name: arduino:renesas_uno platforms: | # Install Arduino Renesas uno Boards via Boards Manager - name: arduino:renesas_uno - sketch-paths: | - - examples/ConnectionHandlerDemo-Notecard - board: platform-name: arduino:esp32 platforms: | # Install Arduino ESP32 Boards via Boards Manager - name: arduino:esp32 - sketch-paths: | - - examples/ConnectionHandlerDemo-Notecard - board: platform-name: esp8266:esp8266 platforms: | @@ -183,16 +148,12 @@ jobs: # Install ESP32 platform via Boards Manager - name: esp32:esp32 source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - sketch-paths: | - - examples/ConnectionHandlerDemo-Notecard - board: platform-name: rp2040:rp2040 platforms: | # Install rp2040 platform via Boards Manager - name: rp2040:rp2040 source-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json - sketch-paths: | - - examples/ConnectionHandlerDemo-Notecard steps: - uses: actions/checkout@v5 diff --git a/README.md b/README.md index 139db7f9..40f9ee09 100644 --- a/README.md +++ b/README.md @@ -12,16 +12,13 @@ Library for handling and managing network connections by providing keep-alive fu * **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413) * **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) * **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Breakout`](https://store.arduino.cc/products/arduino-portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/products/arduino-portenta-machine-control), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`OPTA RS485`](https://store.arduino.cc/products/opta-rs485), [`OPTA Lite`](https://store.arduino.cc/products/opta-lite), [`Portenta C33`](https://store.arduino.cc/products/portenta-c33) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet) -* **Notecard**: [Provides Cellular/LoRa/Satellite/Wi-Fi to any modern board/architecture](examples/ConnectionHandlerDemo-Notecard/README.md) ### How-to-use ```C++ #include /* ... */ -#if defined(BOARD_HAS_NOTECARD) -NotecardConnectionHandler conMan("com.domain.you:product"); -#elif defined(BOARD_HAS_ETHERNET) +#if defined(BOARD_HAS_ETHERNET) EthernetConnectionHandler conMan; #elif defined(BOARD_HAS_WIFI) WiFiConnectionHandler conMan("SECRET_WIFI_SSID", "SECRET_WIFI_PASS"); diff --git a/examples/ConnectionHandlerDemo-Notecard/ConnectionHandlerDemo-Notecard.ino b/examples/ConnectionHandlerDemo-Notecard/ConnectionHandlerDemo-Notecard.ino deleted file mode 100644 index e4183618..00000000 --- a/examples/ConnectionHandlerDemo-Notecard/ConnectionHandlerDemo-Notecard.ino +++ /dev/null @@ -1,144 +0,0 @@ -/* SECRET_ fields are in `arduino_secrets.h` (included below) - * - * If using a Host + Notecard connected over I2C you'll need a - * NotecardConnectionHandler object as follows: - * - * NotecardConnectionHandler conMan(NOTECARD_PRODUCT_UID); - * - * If using a Host + Notecard connected over Serial you'll need a - * NotecardConnectionHandler object as follows: - * - * NotecardConnectionHandler conMan(NOTECARD_PRODUCT_UID, UART_INTERFACE); - */ - -#include // MUST include this first to enable Notecard support -#include - -#include "arduino_secrets.h" - -/* Uncomment the following line to use this example in a manner that is more - * compatible with LoRa. - */ -// #define USE_NOTE_LORA - -#ifndef USE_NOTE_LORA -#define CONN_TOGGLE_MS 60000 -#else -#define CONN_TOGGLE_MS 300000 -#endif - -/* The Notecard can provide connectivity to almost any board via ESLOV (I2C) - * or UART. An empty string (or the default value provided below) will not - * override the Notecard's existing configuration. - * Learn more at: https://dev.blues.io */ -#define NOTECARD_PRODUCT_UID "com.domain.you:product" - -/* Uncomment the following line to use the Notecard over UART */ -// #define UART_INTERFACE Serial1 - -#ifndef UART_INTERFACE -NotecardConnectionHandler conMan(NOTECARD_PRODUCT_UID); -#else -NotecardConnectionHandler conMan(NOTECARD_PRODUCT_UID, UART_INTERFACE); -#endif - -bool attemptConnect = false; -uint32_t lastConnToggleMs = 0; - -void setup() { - /* Initialize serial debug port and wait up to 5 seconds for port to open */ - Serial.begin(9600); - for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { } - - /* Set the debug message level: - * - DBG_ERROR: Only show error messages - * - DBG_WARNING: Show warning and error messages - * - DBG_INFO: Show info, warning, and error messages - * - DBG_DEBUG: Show debug, info, warning, and error messages - * - DBG_VERBOSE: Show all messages - */ - setDebugMessageLevel(DBG_INFO); - - /* Add callbacks to the ConnectionHandler object to get notified of network - * connection events. */ - conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect); - conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect); - conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError); - - /* First call to `check()` initializes the connection to the Notecard. While - * not strictly necessary, it cleans up the logging from this application. - */ - conMan.check(); - -#ifndef USE_NOTE_LORA - /* Set the Wi-Fi credentials for the Notecard */ - String ssid = SECRET_WIFI_SSID; - if (ssid.length() > 0 && ssid != "NETWORK NAME") { - conMan.setWiFiCredentials(SECRET_WIFI_SSID, SECRET_WIFI_PASS); - } -#else - conMan.setNotehubPollingInterval(720); // poll twice per day -#endif - - /* Confirm Interface */ - Serial.print("Network Adapter Interface: "); - if (NetworkAdapter::NOTECARD == conMan.getInterface()) { - Serial.print("Notecard "); - Serial.print(conMan.getNotecardUid()); -#ifndef UART_INTERFACE - Serial.println(" (via I2C)"); -#else - Serial.println(" (via UART)"); -#endif - } else { - Serial.println("ERROR: Unexpected Interface"); - while(1); - } - - /* Display the Arduino IoT Cloud Device ID */ - displayCachedDeviceId(); -} - -void loop() { - /* Toggle the connection every `CONN_TOGGLE_MS` milliseconds */ - if ((millis() - lastConnToggleMs) > CONN_TOGGLE_MS) { - Serial.println("Toggling connection..."); - if (attemptConnect) { - displayCachedDeviceId(); - conMan.connect(); - } else { - // Flush any queued Notecard requests before disconnecting - conMan.initiateNotehubSync(NotecardConnectionHandler::SyncType::Outbound); - conMan.disconnect(); - } - attemptConnect = !attemptConnect; - lastConnToggleMs = millis(); - } - - /* The following code keeps on running connection workflows on our - * ConnectionHandler object, hence allowing reconnection in case of failure - * and notification of connect/disconnect event if enabled (see - * addConnectCallback/addDisconnectCallback) NOTE: any use of delay() within - * the loop or methods called from it will delay the execution of .update(), - * which might not guarantee the correct functioning of the ConnectionHandler - * object. - */ - conMan.check(); -} - -void displayCachedDeviceId() { - Serial.print("Cached Arduino IoT Cloud Device ID: "); - Serial.println(conMan.getDeviceId()); -} - -void onNetworkConnect() { - Serial.println(">>>> CONNECTED to network"); -} - -void onNetworkDisconnect() { - Serial.println(">>>> DISCONNECTED from network"); -} - -void onNetworkError() { - Serial.println(">>>> ERROR"); -} diff --git a/examples/ConnectionHandlerDemo-Notecard/README.md b/examples/ConnectionHandlerDemo-Notecard/README.md deleted file mode 100644 index 7f90a7cf..00000000 --- a/examples/ConnectionHandlerDemo-Notecard/README.md +++ /dev/null @@ -1,71 +0,0 @@ -Notecard Connectivity -===================== - -The Notecard is a wireless, secure abstraction for device connectivity, that can -be used to enable _ANY*_ device with I2C, or UART, to connect to the Arduino IoT -Cloud via cellular, LoRa, satellite or Wi-Fi! - -As a result, your existing device architecture can now have first class support -in the Arduino IoT Cloud, by using a Notecard as a secure communication channel. - -> \*_While any device with I2C/UART may use the Notecard, the Arduino IoT Cloud -> library is not supported by the AVR toolchain. Therefore, devices based on the -> AVR architecture cannot access the Arduino IoT Cloud via the Notecard._ -> -> _However, any device (including AVR), may use the Notecard library to send data -> to Notehub, then that data may be routed to any endpoint of your choosing. See the -> [Notecard Routing Guide](https://dev.blues.io/guides-and-tutorials/routing-data-to-cloud) -> for more information..._ - -Wireless Connectivity Options ------------------------------ - -- [Cellular](https://shop.blues.com/collections/notecard/products/notecard-cellular) -- [Cellular + Wi-Fi](https://shop.blues.com/collections/notecard/products/notecard-cell-wifi) -- [Wi-Fi](https://shop.blues.com/collections/notecard/products/wifi-notecard) -- [LoRa](https://shop.blues.com/collections/notecard/products/notecard-lora) -- [Satellite](https://shop.blues.com/products/starnote) - -How it Works ------------- - -**Architecture Diagram:** - -``` --------- ------------ ----------- ----------- -| | | | | | | | -| Host | | | Secure | | | Arduino | -| MCU |------| Notecard | ( ( Wireless ) ) | Notehub |------| IoT | -| | | | Protocol | | | Cloud | -|______| |__________| |_________| |_________| -``` - -Getting Started ---------------- - -### Setup a Notehub Account - -Using the Notecard only requires a couple of easy steps: - -1. [Purchase a Notecard](https://shop.blues.com/collections/notecard) (and -[Notecarrier](https://shop.blues.com/collections/notecarrier)) that fits the -needs of your device. - > _**NOTE:** We recommend starting with our [Dev Kit](https://shop.blues.com/products/blues-global-starter-kit) - > if you are unsure._ -1. [Setup a Notehub account](https://dev.blues.io/quickstart/notecard-quickstart/notecard-and-notecarrier-f/#set-up-notehub). - > _**NOTE:** Notehub accounts are free (no credit card required)._ -1. [Create a project on your Notehub account](https://dev.blues.io/quickstart/notecard-quickstart/notecard-and-notecarrier-f/#create-a-notehub-project). -1. In `ConnectionHandlerDemo-Notecard`, replace "com.domain.you:product" (from -`NOTECARD_PRODUCT_UID`) with the ProductUID of your new Notehub project. - -### Power-up the Device - -1. [Connect the Notecard to your Host MCU](https://dev.blues.io/quickstart/notecard-quickstart/notecard-and-notecarrier-f/#connect-your-notecard-and-notecarrier) -1. Flash the `ConnectionHanderDemo-Notecard` example sketch to your device. You -should see the device reporting itself as online in your [Notehub Project](https://notehub.io). - -### More Information - -For more information about the Notecard and Notehub in general, please see our -[Quickstart Guide](https://dev.blues.io/quickstart/) for a general overview of -how the Notecard and Notehub are designed to work. diff --git a/examples/ConnectionHandlerDemo-Notecard/arduino_secrets.h b/examples/ConnectionHandlerDemo-Notecard/arduino_secrets.h deleted file mode 100644 index bd2a9d58..00000000 --- a/examples/ConnectionHandlerDemo-Notecard/arduino_secrets.h +++ /dev/null @@ -1,5 +0,0 @@ -/* If provided, the Wi-Fi Credentials will be passed along to the Notecard. If - * the Notecard supports Wi-Fi, it will attempt to connect to the network using - * these credentials, if not, the Notecard will safely ignore these values. */ -const char SECRET_WIFI_SSID[] = "NETWORK NAME"; -const char SECRET_WIFI_PASS[] = "NETWORK PASSWORD"; diff --git a/keywords.txt b/keywords.txt index 68e2be2d..f2176d69 100644 --- a/keywords.txt +++ b/keywords.txt @@ -12,7 +12,6 @@ NBConnectionHandler KEYWORD1 LoRaConnectionHandler KEYWORD1 EthernetConnectionHandler KEYWORD1 CatM1ConnectionHandler KEYWORD1 -NotecardConnectionHandler KEYWORD1 #################################################### # Methods and Functions (KEYWORD2) @@ -30,10 +29,6 @@ getTime KEYWORD2 getClient KEYWORD2 getUDP KEYWORD2 -# NotecardConnectionHandler.h -initiateNotehubSync KEYWORD2 -setWiFiCredentials KEYWORD2 - #################################################### # Constants (LITERAL1) #################################################### diff --git a/library.properties b/library.properties index 9ad0dc11..48f42491 100644 --- a/library.properties +++ b/library.properties @@ -2,9 +2,9 @@ name=Arduino_ConnectionHandler version=1.2.0 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. maintainer=Arduino -sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet], Notecard) +sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) 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_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN diff --git a/src/Arduino_ConnectionHandler.h b/src/Arduino_ConnectionHandler.h index c7a2dcf4..8153c45e 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -22,10 +22,6 @@ #include #include "ConnectionHandlerDefinitions.h" -#if defined(BOARD_HAS_NOTECARD) - #include "NotecardConnectionHandler.h" -#else - #if defined(BOARD_HAS_WIFI) #include "WiFiConnectionHandler.h" #endif @@ -54,6 +50,4 @@ #include "CellularConnectionHandler.h" #endif -#endif // BOARD_HAS_NOTECARD - #endif /* CONNECTION_HANDLER_H_ */ diff --git a/src/ConnectionHandlerDefinitions.h b/src/ConnectionHandlerDefinitions.h index 1534e473..969ecd19 100644 --- a/src/ConnectionHandlerDefinitions.h +++ b/src/ConnectionHandlerDefinitions.h @@ -14,16 +14,8 @@ INCLUDES ******************************************************************************/ -#if defined __has_include - #if __has_include () - #define BOARD_HAS_NOTECARD - #endif -#endif - #include -#ifndef BOARD_HAS_NOTECARD - #ifdef ARDUINO_SAMD_MKR1000 #define BOARD_HAS_WIFI #define NETWORK_HARDWARE_ERROR WL_NO_SHIELD @@ -144,8 +136,6 @@ #define NETWORK_CONNECTED WL_CONNECTED #endif -#endif // BOARD_HAS_NOTECARD - /****************************************************************************** TYPEDEFS ******************************************************************************/ @@ -174,8 +164,7 @@ enum class NetworkAdapter { GSM, LORA, CATM1, - CELL, - NOTECARD + CELL }; union TimeoutTable { @@ -198,7 +187,7 @@ union TimeoutTable { ******************************************************************************/ constexpr TimeoutTable DefaultTimeoutTable { -#if defined(BOARD_HAS_NOTECARD) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) 4000, // init #else 500, // init diff --git a/src/NotecardConnectionHandler.cpp b/src/NotecardConnectionHandler.cpp deleted file mode 100644 index 80cd0145..00000000 --- a/src/NotecardConnectionHandler.cpp +++ /dev/null @@ -1,795 +0,0 @@ -/* - This file is part of the ArduinoIoTCloud library. - - Copyright 2024 Blues (http://www.blues.com/) - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. -*/ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include "ConnectionHandlerDefinitions.h" - -#if defined(BOARD_HAS_NOTECARD) // Only compile if the Notecard is present - -#include "NotecardConnectionHandler.h" - -#include -#include -#include - -/****************************************************************************** - DEFINES - ******************************************************************************/ - -#define NO_INBOUND_POLLING -1 - -#define NOTEFILE_BASE_NAME "arduino_iot_cloud" - -// Notecard LoRa requires us to choose an arbitrary port between 1-99 -#define NOTEFILE_INBOUND_LORA_PORT 2 -#define NOTEFILE_OUTBOUND_LORA_PORT 3 - -// Note that we use "s" versions of the Notefile extensions to ensure that -// traffic always happens on a secure transport -#define NOTEFILE_SECURE_INBOUND NOTEFILE_BASE_NAME ".qis" -#define NOTEFILE_SECURE_OUTBOUND NOTEFILE_BASE_NAME ".qos" - -/****************************************************************************** - STLINK DEBUG OUTPUT - ******************************************************************************/ - -// Provide Notehub debug output via STLINK serial port when available -#if defined(ARDUINO_SWAN_R5) || defined(ARDUINO_CYGNET) - #define STLINK_DEBUG - HardwareSerial stlinkSerial(PIN_VCP_RX, PIN_VCP_TX); -#endif - -/****************************************************************************** - TYPEDEF - ******************************************************************************/ - -struct NotecardConnectionStatus -{ - NotecardConnectionStatus(void) : transport_connected(0), connected_to_notehub(0), notecard_error(0), host_error(0), reserved(0) { } - NotecardConnectionStatus(uint_fast8_t x) : transport_connected(x & 0x01), connected_to_notehub(x & 0x02), notecard_error(x & 0x04), host_error(x & 0x08), reserved(x & 0xF0) { } - NotecardConnectionStatus & operator=(uint_fast8_t x) { - transport_connected = (x & 0x01); - connected_to_notehub = (x & 0x02); - notecard_error = (x & 0x04); - host_error = (x & 0x08); - reserved = (x & 0xF0); - return *this; - } - operator uint_fast8_t () const { - return ((reserved << 4) | (host_error << 3) | (notecard_error << 2) | (connected_to_notehub << 1) | (transport_connected)); - } - - bool transport_connected : 1; - bool connected_to_notehub : 1; - bool notecard_error : 1; - bool host_error : 1; - uint_fast8_t reserved : 4; -}; -static_assert(sizeof(NotecardConnectionStatus) == sizeof(uint_fast8_t)); - -/****************************************************************************** - CTOR/DTOR - ******************************************************************************/ - -NotecardConnectionHandler::NotecardConnectionHandler( - const String & project_uid_, - uint32_t i2c_address_, - uint32_t i2c_max_, - TwoWire & wire_, - bool keep_alive_ -) : - ConnectionHandler{keep_alive_, NetworkAdapter::NOTECARD}, - _notecard{}, - _device_id{}, - _notecard_uid{}, - _project_uid(project_uid_), - _serial(nullptr), - _wire(&wire_), - _inbound_buffer(nullptr), - _conn_start_ms(0), - _i2c_address(i2c_address_), - _i2c_max(i2c_max_), - _inbound_buffer_index(0), - _inbound_buffer_size(0), - _inbound_polling_interval_min(NO_INBOUND_POLLING), - _uart_baud(0), - _en_hw_int(false), - _topic_type{TopicType::Invalid} -{ } - -NotecardConnectionHandler::NotecardConnectionHandler( - const String & project_uid_, - HardwareSerial & serial_, - uint32_t baud_, - bool keep_alive_ -) : - ConnectionHandler{keep_alive_, NetworkAdapter::NOTECARD}, - _notecard{}, - _device_id{}, - _notecard_uid{}, - _project_uid(project_uid_), - _serial(&serial_), - _wire(nullptr), - _inbound_buffer(nullptr), - _conn_start_ms(0), - _i2c_address(0), - _i2c_max(0), - _inbound_buffer_index(0), - _inbound_buffer_size(0), - _inbound_polling_interval_min(NO_INBOUND_POLLING), - _uart_baud(baud_), - _en_hw_int(false), - _topic_type{TopicType::Invalid} -{ } - -/****************************************************************************** - PUBLIC MEMBER FUNCTIONS - ******************************************************************************/ - -int NotecardConnectionHandler::initiateNotehubSync (SyncType type_) const -{ - int result; - - DEBUG_DEBUG(F("NotecardConnectionHandler::%s initiating Notehub sync..."), __FUNCTION__); - if (J *req = _notecard.newRequest("hub.sync")) { - if (type_ == SyncType::Inbound) { - JAddBoolToObject(req, "in", true); - } else if (type_ == SyncType::Outbound) { - JAddBoolToObject(req, "out", true); - } - if (J *rsp = _notecard.requestAndResponse(req)) { - // Check the response for errors - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - DEBUG_ERROR(F("%s"), err); - result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; - } else { - DEBUG_DEBUG(F("NotecardConnectionHandler::%s successfully initiated Notehub sync."), __FUNCTION__); - result = NotecardCommunicationError::NOTECARD_ERROR_NONE; - } - JDelete(rsp); - } else { - DEBUG_ERROR(F("Failed to receive response from Notecard.")); - result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; - } - } else { - DEBUG_ERROR("Failed to allocate request: hub.sync"); - result = NotecardCommunicationError::HOST_ERROR_OUT_OF_MEMORY; - } - - return result; -} - -int NotecardConnectionHandler::setWiFiCredentials (const String & ssid_, const String & password_) -{ - int result; - - // Validate the connection state is not in an initialization state - const NetworkConnectionState current_net_connection_state = check(); - if (NetworkConnectionState::INIT == current_net_connection_state) - { - DEBUG_ERROR(F("Unable to set Wi-Fi credentials. Connection to Notecard uninitialized.")); - result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; - } else if (J *req = _notecard.newRequest("card.wifi")) { - JAddStringToObject(req, "ssid", ssid_.c_str()); - JAddStringToObject(req, "password", password_.c_str()); - if (J *rsp = _notecard.requestAndResponse(req)) { - // Check the response for errors - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - DEBUG_ERROR(F("%s"), err); - DEBUG_ERROR(F("Failed to set Wi-Fi credentials.")); - result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; - } else { - DEBUG_INFO(F("Wi-Fi credentials updated. ssid: \"%s\" password: \"%s\"."), ssid_.c_str(), password_.length() ? "**********" : ""); - result = NotecardCommunicationError::NOTECARD_ERROR_NONE; - } - JDelete(rsp); - } else { - DEBUG_ERROR(F("Failed to receive response from Notecard.")); - result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; - } - } else { - DEBUG_ERROR(F("Failed to allocate request: wifi.set")); - result = NotecardCommunicationError::HOST_ERROR_OUT_OF_MEMORY; - } - - return result; -} - -/****************************************************************************** - PUBLIC INTERFACE MEMBER FUNCTIONS - ******************************************************************************/ - -bool NotecardConnectionHandler::available() -{ - bool buffered_data = (_inbound_buffer_index < _inbound_buffer_size); - bool flush_required = !buffered_data && _inbound_buffer_size; - - // When the buffer is empty, look for a Note in the - // NOTEFILE_SECURE_INBOUND file to reload the buffer. - if (!buffered_data) { - // Reset the buffer - free(_inbound_buffer); - _inbound_buffer = nullptr; - _inbound_buffer_index = 0; - _inbound_buffer_size = 0; - - // Do NOT attempt to buffer the next Note immediately after buffer - // exhaustion (a.k.a. flush required). Returning `false` between Notes, - // will break the read loop, force the CBOR buffer to be parsed, and the - // property containers to be updated. - if (!flush_required) { - // Reload the buffer - J *note = getNote(true); - if (note) { - if (J *body = JGetObject(note, "body")) { - _topic_type = static_cast(JGetInt(body, "topic")); - if (_topic_type == TopicType::Invalid) { - DEBUG_WARNING(F("Note does not contain a topic")); - } else { - buffered_data = JGetBinaryFromObject(note, "payload", &_inbound_buffer, &_inbound_buffer_size); - if (!buffered_data) { - DEBUG_WARNING(F("Note does not contain payload data")); - } else { - DEBUG_DEBUG(F("NotecardConnectionHandler::%s buffered payload with size: %d"), __FUNCTION__, _inbound_buffer_size); - } - } - } else { - _topic_type = TopicType::Invalid; - } - JDelete(note); - } - } - } - - return buffered_data; -} - -unsigned long NotecardConnectionHandler::getTime() -{ - unsigned long result; - - if (J *rsp = _notecard.requestAndResponse(_notecard.newRequest("card.time"))) { - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - DEBUG_ERROR(F("%s\n"), err); - result = 0; - } else { - result = JGetInt(rsp, "time"); - } - JDelete(rsp); - } else { - result = 0; - } - - return result; -} - -int NotecardConnectionHandler::read() -{ - int result; - - if (_inbound_buffer_index < _inbound_buffer_size) { - result = _inbound_buffer[_inbound_buffer_index++]; - } else { - result = NotecardCommunicationError::NOTECARD_ERROR_NO_DATA_AVAILABLE; - } - - return result; -} - -int NotecardConnectionHandler::write(const uint8_t * buf_, size_t size_) -{ - int result; - - // Validate the connection state is not uninitialized or in error state - const NetworkConnectionState current_net_connection_state = check(); - if ((NetworkConnectionState::INIT == current_net_connection_state) - || (NetworkConnectionState::ERROR == current_net_connection_state)) - { - DEBUG_ERROR(F("Unable to write message. Connection to Notecard uninitialized or in error state.")); - result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; - } else if (J * req = _notecard.newRequest("note.add")) { - JAddStringToObject(req, "file", NOTEFILE_SECURE_OUTBOUND); - if (buf_) { - JAddBinaryToObject(req, "payload", buf_, size_); - } - // Queue the Note when `_keep_alive` is disabled or not connected to Notehub - if (_keep_alive && (NetworkConnectionState::CONNECTED == current_net_connection_state)) { - JAddBoolToObject(req, "live", true); - JAddBoolToObject(req, "sync", true); - } - if (J *body = JAddObjectToObject(req, "body")) { - JAddIntToObject(body, "topic", static_cast(_topic_type)); - J * rsp = _notecard.requestAndResponse(req); - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - if (NoteErrorContains(err, "{hub-not-connected}")) { - // _current_net_connection_state = NetworkConnectionState::DISCONNECTED; - } - DEBUG_ERROR(F("%s\n"), err); - result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC; - } else { - result = NotecardCommunicationError::NOTECARD_ERROR_NONE; - DEBUG_INFO(F("Message sent correctly!")); - } - JDelete(rsp); - } else { - JFree(req); - result = NotecardCommunicationError::HOST_ERROR_OUT_OF_MEMORY; - } - } else { - result = NotecardCommunicationError::HOST_ERROR_OUT_OF_MEMORY; - } - - return result; -} - -/****************************************************************************** - PROTECTED STATE MACHINE FUNCTIONS - ******************************************************************************/ - -NetworkConnectionState NotecardConnectionHandler::update_handleInit() -{ - NetworkConnectionState result = NetworkConnectionState::INIT; - - // Configure Hardware - /////////////////////// - -#if defined(STLINK_DEBUG) - // Output Notecard logs to the STLINK serial port - stlinkSerial.end(); // necessary to handle multiple initializations (e.g. reconnections) - stlinkSerial.begin(115200); - const size_t usb_timeout_ms = 3000; - for (const size_t start_ms = millis(); !stlinkSerial && (millis() - start_ms) < usb_timeout_ms;); - _notecard.setDebugOutputStream(stlinkSerial); -#endif - - // Initialize the Notecard based on the configuration - if (_serial) { - _notecard.begin(*_serial, _uart_baud); - } else { - _notecard.begin(_i2c_address, _i2c_max, *_wire); - } - - // Configure `note-c` - /////////////////////// - - // Set the user agent - NoteSetUserAgent((char *) ("arduino-iot-cloud " NOTECARD_CONNECTION_HANDLER_VERSION)); - - // Configure the ATTN pin to be used as an interrupt to indicate when a Note - // is available to read. `getNote()` will only arm the interrupt if no old - // Notes are available. If `ATTN` remains unarmed, it signals the user - // application that outstanding Notes are queued and need to be processed. - if (J *note = getNote(false)) { - JDelete(note); - } - - // Configure the Notecard - /////////////////////////// - - // Set the project UID - if (NetworkConnectionState::INIT == result) { - if (configureConnection(true)) { - result = NetworkConnectionState::INIT; - } else { - result = NetworkConnectionState::ERROR; - } - } - -#if defined(ARDUINO_OPTA) - // The Opta Extension has an onboard Li-Ion capacitor, that can be utilized - // to monitor the power state of the device and automatically report loss of - // power to Notehub. The following command enables that detection by default - // for the Opta Wirelss Extension. - if (NetworkConnectionState::INIT == result) { - if (J *req = _notecard.newRequest("card.voltage")) { - JAddStringToObject(req, "mode", "lic"); - JAddBoolToObject(req, "alert", true); - JAddBoolToObject(req, "sync", true); - JAddBoolToObject(req, "usb", true); - if (J *rsp = _notecard.requestAndResponse(req)) { - // Check the response for errors - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - DEBUG_ERROR(F("%s"), err); - result = NetworkConnectionState::ERROR; - } else { - result = NetworkConnectionState::INIT; - } - JDelete(rsp); - } else { - DEBUG_ERROR(F("Failed to receive response from Notecard.")); - result = NetworkConnectionState::ERROR; // Assume the worst - } - } else { - DEBUG_ERROR("Failed to allocate request: card.voltage"); - result = NetworkConnectionState::ERROR; // Assume the worst - } - } -#endif - - // Set inbound template to support LoRa/Satellite Notecard - if (NetworkConnectionState::INIT == result) { - if (J *req = _notecard.newRequest("note.template")) { - JAddStringToObject(req, "file", NOTEFILE_SECURE_INBOUND); - JAddStringToObject(req, "format", "compact"); // Support LoRa/Satellite Notecards - JAddIntToObject(req, "port", NOTEFILE_INBOUND_LORA_PORT); // Support LoRa/Satellite Notecards - if (J *body = JAddObjectToObject(req, "body")) { - JAddIntToObject(body, "topic", TUINT8); - if (J *rsp = _notecard.requestAndResponse(req)) { - // Check the response for errors - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - DEBUG_ERROR(F("%s"), err); - result = NetworkConnectionState::ERROR; - } else { - result = NetworkConnectionState::INIT; - } - JDelete(rsp); - } else { - DEBUG_ERROR(F("Failed to receive response from Notecard.")); - result = NetworkConnectionState::ERROR; // Assume the worst - } - } else { - DEBUG_ERROR("Failed to allocate request: note.template:body"); - JFree(req); - result = NetworkConnectionState::ERROR; // Assume the worst - } - } else { - DEBUG_ERROR("Failed to allocate request: note.template"); - result = NetworkConnectionState::ERROR; // Assume the worst - } - } - - // Set outbound template to remove payload size restrictions - if (NetworkConnectionState::INIT == result) { - if (J *req = _notecard.newRequest("note.template")) { - JAddStringToObject(req, "file", NOTEFILE_SECURE_OUTBOUND); - JAddStringToObject(req, "format", "compact"); // Support LoRa/Satellite Notecards - JAddIntToObject(req, "port", NOTEFILE_OUTBOUND_LORA_PORT); // Support LoRa/Satellite Notecards - if (J *body = JAddObjectToObject(req, "body")) { - JAddIntToObject(body, "topic", TUINT8); - if (J *rsp = _notecard.requestAndResponse(req)) { - // Check the response for errors - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - DEBUG_ERROR(F("%s"), err); - result = NetworkConnectionState::ERROR; - } else { - result = NetworkConnectionState::INIT; - } - JDelete(rsp); - } else { - DEBUG_ERROR(F("Failed to receive response from Notecard.")); - result = NetworkConnectionState::ERROR; // Assume the worst - } - } else { - DEBUG_ERROR("Failed to allocate request: note.template:body"); - JFree(req); - result = NetworkConnectionState::ERROR; // Assume the worst - } - } else { - DEBUG_ERROR("Failed to allocate request: note.template"); - result = NetworkConnectionState::ERROR; // Assume the worst - } - } - - // Get the device UID - if (NetworkConnectionState::INIT == result) { - if (!updateUidCache()) { - result = NetworkConnectionState::ERROR; - } else { - DEBUG_INFO(F("Notecard has been initialized.")); - if (_keep_alive) { - _conn_start_ms = ::millis(); - DEBUG_INFO(F("Starting network connection...")); - result = NetworkConnectionState::CONNECTING; - } else { - DEBUG_INFO(F("Network is disconnected.")); - result = NetworkConnectionState::DISCONNECTED; - } - } - } - - return result; -} - -NetworkConnectionState NotecardConnectionHandler::update_handleConnecting() -{ - NetworkConnectionState result; - - // Check the connection status - const NotecardConnectionStatus conn_status = connected(); - - // Update the connection state - if (!conn_status.connected_to_notehub) { - if ((::millis() - _conn_start_ms) > NOTEHUB_CONN_TIMEOUT_MS) { - DEBUG_ERROR(F("Timeout exceeded, connection to the network failed.")); - DEBUG_INFO(F("Retrying in \"%d\" milliseconds"), _timeoutTable.timeout.connecting); - result = NetworkConnectionState::INIT; - } else { - // Continue awaiting the connection to Notehub - if (conn_status.transport_connected) { - DEBUG_INFO(F("Establishing connection to Notehub...")); - } else { - DEBUG_INFO(F("Connecting to the network...")); - } - result = NetworkConnectionState::CONNECTING; - } - } else { - DEBUG_INFO(F("Connected to Notehub!")); - result = NetworkConnectionState::CONNECTED; - if (initiateNotehubSync()) { - DEBUG_ERROR(F("Failed to initiate Notehub sync.")); - } - } - - return result; -} - -NetworkConnectionState NotecardConnectionHandler::update_handleConnected() -{ - NetworkConnectionState result; - - const NotecardConnectionStatus conn_status = connected(); - if (!conn_status.connected_to_notehub) { - if (!conn_status.transport_connected) { - DEBUG_ERROR(F("Connection to the network lost.")); - } else { - DEBUG_ERROR(F("Connection to Notehub lost.")); - } - result = NetworkConnectionState::DISCONNECTED; - } else { - result = NetworkConnectionState::CONNECTED; - } - - return result; -} - -NetworkConnectionState NotecardConnectionHandler::update_handleDisconnecting() -{ - NetworkConnectionState result; - - DEBUG_ERROR(F("Connection to the network lost.")); - result = NetworkConnectionState::DISCONNECTED; - - return result; -} - -NetworkConnectionState NotecardConnectionHandler::update_handleDisconnected() -{ - NetworkConnectionState result; - - if (_keep_alive) - { - DEBUG_ERROR(F("Attempting reconnection...")); - result = NetworkConnectionState::INIT; - } - else - { - if (configureConnection(false)) { - result = NetworkConnectionState::CLOSED; - DEBUG_INFO(F("Closing connection...")); - } else { - result = NetworkConnectionState::ERROR; - DEBUG_INFO(F("Error closing connection...")); - } - } - - return result; -} - -/****************************************************************************** - PRIVATE MEMBER FUNCTIONS - ******************************************************************************/ - -bool NotecardConnectionHandler::armInterrupt (void) const -{ - bool result; - - if (J *req = _notecard.newRequest("card.attn")) { - JAddStringToObject(req, "mode","rearm,files"); - if (J *files = JAddArrayToObject(req, "files")) { - JAddItemToArray(files, JCreateString(NOTEFILE_SECURE_INBOUND)); - if (J *rsp = _notecard.requestAndResponse(req)) { - // Check the response for errors - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - DEBUG_ERROR(F("%s\n"), err); - result = false; - } else { - result = true; - } - JDelete(rsp); - } else { - DEBUG_ERROR(F("Failed to receive response from Notecard.")); - result = false; - } - } else { - DEBUG_ERROR("Failed to allocate request: card.attn:files"); - JFree(req); - result = false; - } - } else { - DEBUG_ERROR("Failed to allocate request: card.attn"); - result = false; - } - - return result; -} - -bool NotecardConnectionHandler::configureConnection (bool connect_) const -{ - bool result; - - if (J *req = _notecard.newRequest("hub.set")) { - // Only update the product if it is not empty or the default value - if (_project_uid.length() > 0 && _project_uid != "com.domain.you:product") { - JAddStringToObject(req, "product", _project_uid.c_str()); - } - - // Configure the connection mode based on the `connect_` parameter - if (connect_) { - JAddStringToObject(req, "mode", "continuous"); - JAddIntToObject(req, "inbound", _inbound_polling_interval_min); - JAddBoolToObject(req, "sync", true); - } else { - JAddStringToObject(req, "mode", "periodic"); - JAddIntToObject(req, "inbound", NO_INBOUND_POLLING); - JAddIntToObject(req, "outbound", -1); - JAddStringToObject(req, "vinbound", "-"); - JAddStringToObject(req, "voutbound", "-"); - } - - // Send the request to the Notecard - if (J *rsp = _notecard.requestAndResponseWithRetry(req, 30)) { - // Check the response for errors - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - DEBUG_ERROR(F("%s"), err); - result = false; - } else { - result = true; - } - JDelete(rsp); - } else { - DEBUG_ERROR(F("Failed to receive response from Notecard.")); - result = false; // Assume the worst - } - } else { - DEBUG_ERROR("Failed to allocate request: hub.set"); - result = false; // Assume the worst - } - - return result; -} - -uint_fast8_t NotecardConnectionHandler::connected (void) const -{ - NotecardConnectionStatus result; - - // Query the connection status from the Notecard - if (J *rsp = _notecard.requestAndResponse(_notecard.newRequest("hub.status"))) { - // Ensure the transaction doesn't return an error - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - DEBUG_ERROR(F("%s"),err); - result.notecard_error = true; - } else { - // Parse the transport connection status - result.transport_connected = (strstr(JGetString(rsp,"status"),"{connected}") != nullptr); - - // Parse the status of the connection to Notehub - result.connected_to_notehub = JGetBool(rsp,"connected"); - - // Set the Notecard error status - result.notecard_error = false; - result.host_error = false; - } - - // Free the response - JDelete(rsp); - } else { - DEBUG_ERROR(F("Failed to acquire Notecard connection status.")); - result.transport_connected = false; - result.connected_to_notehub = false; - result.notecard_error = false; - result.host_error = true; - } - - return result; -} - -J * NotecardConnectionHandler::getNote (bool pop_) const -{ - J * result; - - // Look for a Note in the NOTEFILE_SECURE_INBOUND file - if (J *req = _notecard.newRequest("note.get")) { - JAddStringToObject(req, "file", NOTEFILE_SECURE_INBOUND); - if (pop_) { - JAddBoolToObject(req, "delete", true); - } - if (J *note = _notecard.requestAndResponse(req)) { - // Ensure the transaction doesn't return an error - if (NoteResponseError(note)) { - const char *jErr = JGetString(note, "err"); - if (NoteErrorContains(jErr, "{note-noexist}")) { - // The Notefile is empty, thus no Note is available. - if (_en_hw_int) { - armInterrupt(); - } - } else { - // Any other error indicates that we were unable to - // retrieve a Note, therefore no Note is available. - } - result = nullptr; - JDelete(note); - } else { - // The Note was successfully retrieved, and it now - // becomes the callers responsibility to free it. - result = note; - } - } else { - DEBUG_ERROR(F("Failed to receive response from Notecard.")); - result = nullptr; - } - } else { - DEBUG_ERROR("Failed to allocate request: note.get"); - // Failed to retrieve a Note, therefore no Note is available. - result = nullptr; - } - - return result; -} - -bool NotecardConnectionHandler::updateUidCache (void) -{ - bool result; - - // This operation is safe to perform before a sync has occurred, because the - // Notecard UID is static and the cloud value of Serial Number is strictly - // informational with regard to the host firmware operations. - - // Read the Notecard UID from the Notehub configuration - if (J *rsp = _notecard.requestAndResponse(_notecard.newRequest("hub.get"))) { - // Check the response for errors - if (NoteResponseError(rsp)) { - const char *err = JGetString(rsp, "err"); - DEBUG_ERROR(F("Failed to read Notecard UID")); - DEBUG_ERROR(F("Error: %s"), err); - result = false; - } else { - _notecard_uid = JGetString(rsp, "device"); - char device_id[] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; - if (NoteGetEnv("_arduino_device_id", device_id, device_id, sizeof(device_id))) { - _device_id = device_id; - } else { - DEBUG_DEBUG(F("NotecardConnectionHandler::%s Arduino Device ID not cached on Notecard, using default value: <%s>"), __FUNCTION__, _device_id.c_str()); - } - DEBUG_DEBUG(F("NotecardConnectionHandler::%s updated local cache with Notecard UID: <%s> and Arduino Device ID: <%s>"), __FUNCTION__, _notecard_uid.c_str(), _device_id.c_str()); - result = true; - } - JDelete(rsp); - } else { - DEBUG_ERROR(F("Failed to read Notecard UID")); - result = false; - } - - return result; -} - -#endif /* BOARD_HAS_NOTECARD */ diff --git a/src/NotecardConnectionHandler.h b/src/NotecardConnectionHandler.h deleted file mode 100644 index 7e84fc51..00000000 --- a/src/NotecardConnectionHandler.h +++ /dev/null @@ -1,342 +0,0 @@ -/* - This file is part of the ArduinoIoTCloud library. - - Copyright 2024 Blues (http://www.blues.com/) - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. -*/ - -#ifndef ARDUINO_NOTECARD_CONNECTION_HANDLER_H_ -#define ARDUINO_NOTECARD_CONNECTION_HANDLER_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include - -#include -#include -#include - -#include "ConnectionHandlerInterface.h" - -/****************************************************************************** - DEFINES - ******************************************************************************/ - -#define NOTECARD_CONNECTION_HANDLER_VERSION_MAJOR 1 -#define NOTECARD_CONNECTION_HANDLER_VERSION_MINOR 1 -#define NOTECARD_CONNECTION_HANDLER_VERSION_PATCH 1 - -#define NOTECARD_CONNECTION_HANDLER_VERSION NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_MAJOR) "." NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_MINOR) "." NOTE_C_STRINGIZE(NOTECARD_CONNECTION_HANDLER_VERSION_PATCH) - -/****************************************************************************** - CLASS DECLARATION - ******************************************************************************/ - -/** - * @brief The NotecardConnectionHandler class - * - * The NotecardConnectionHandler class is a concrete implementation of the - * ConnectionHandler interface that provides connectivity to the Arduino IoT - * Cloud using a Notecard. - */ -class NotecardConnectionHandler final : public ConnectionHandler -{ - public: - /** - * @brief The manner in which the Notecard is synchronized with Notehub - * - * The SyncType enum defines the valid types of synchronization operations - * that can be performed by the NotecardConnectionHandler class. - * - * @par - * - Full - synchronize both the inbound and outbound queues. - * - Inbound - synchronize only the inbound queues. - * - Outbound - synchronize only the outbound queues. - */ - enum class SyncType : uint8_t { - Full, - Inbound, - Outbound, - }; - - /** - * @brief The type of topic to be used for R/W operations - * - * The Notecard uses topics to identify the target of a read or write - * operation. The TopicType enum defines the valid types of topics. - * - * @par - * - Command - used to interact with the Arduino IoT Cloud. - * - Thing - used to send application data to the Arduino IoT Cloud. - */ - enum class TopicType : uint8_t { - Invalid = 0, - Command, - Thing, - }; - - /** - * @brief The error codes for communicating with the Notecard - * - * The NotecardCommunicationError enum defines the error codes that can be - * returned by the NotecardConnectionHandler class. - * - * @par - * - NOTECARD_ERROR_NONE - No error occurred. - * - NOTECARD_ERROR_NO_DATA_AVAILABLE - No data is available. - * - NOTECARD_ERROR_GENERIC - A generic error occurred. - * - HOST_ERROR_OUT_OF_MEMORY - The host is out of memory. - */ - typedef enum { - NOTECARD_ERROR_NONE = 0, - NOTECARD_ERROR_NO_DATA_AVAILABLE = -1, - NOTECARD_ERROR_GENERIC = -2, - HOST_ERROR_OUT_OF_MEMORY = -3, - } NotecardCommunicationError; - - /** - * @brief The default timeout for the Notecard to connect to Notehub - */ - static const uint32_t NOTEHUB_CONN_TIMEOUT_MS = 185000; - - /** - * @brief The I2C constructor for the Notecard - * - * @param project_uid[in] The project UID of the related Notehub account - * @param i2c_address[in] The I2C address of the Notecard - * @param i2c_max[in] The maximum I2C transaction size (MTU) - * @param wire[in] The I2C bus to use - * @param keep_alive[in] Keep the connection alive if connection to Notehub drops - */ - NotecardConnectionHandler( - const String & project_uid, - uint32_t i2c_address = NOTE_I2C_ADDR_DEFAULT, - uint32_t i2c_max = NOTE_I2C_MAX_DEFAULT, - TwoWire & wire = Wire, - bool keep_alive = true - ); - - /** - * @brief The UART constructor for the Notecard - * - * @param project_uid[in] The project UID of the related Notehub account - * @param serial[in] The serial port to use - * @param baud[in] The baud rate of the serial port - * @param keep_alive[in] Keep the connection alive if connection to Notehub drops - */ - NotecardConnectionHandler( - const String & project_uid, - HardwareSerial & serial, - uint32_t baud = 9600, - bool keep_alive = true - ); - - /** - * @brief Disable hardware interrupts - * - * When hardware interrupts are disabled, the `NotecardConnectionHandler` - * must be polled for incoming data. This is necessary when the host - * microcontroller is unable to use the ATTN pin of the Notecard. - */ - inline void disableHardwareInterrupts (void) { - _en_hw_int = false; - } - - /** - * @brief Enable hardware interrupts - * - * Hardware interrupts allow the `NotecardConnectionHandler` to leverage the - * ATTN pin of the Notecard. This improves the responsiveness of the - * `NotecardConnectionHandler` by eliminating the need for the host - * microcontroller to poll the Notecard for incoming data. - */ - inline void enableHardwareInterrupts (void) { - _en_hw_int = true; - } - - /** - * @brief Get the Arduino IoT Cloud Device ID - * - * The Arduino IoT Cloud Device ID is set as the serial number of the - * Notecard when the device is provisioned in Notehub. The serial number is - * updated on each sync between the Notecard and Notehub and cached by the - * Notecard. As a result, this value can lag behind the actual value of the - * Arduino IoT Cloud Device ID used by the Notehub. However, this value is - * typically unchanged during the life of the Notecard, so this is rarely, - * if ever, an issue. - * - * @return The Arduino IoT Cloud Device ID - */ - inline const String & getDeviceId (void) { - check(); // Ensure the connection to the Notecard is initialized - return _device_id; - } - - /** - * @brief Get the Notecard object - * - * The Notecard object is used to interact with the Notecard. This object - * provides methods to read and write data to the Notecard, as well as - * methods to configure the Notecard. - * - * @return The Notecard object - */ - inline const Notecard & getNotecard (void) { - return _notecard; - } - - /** - * @brief Get the Notecard Device ID - * - * The Notecard Device ID is the unique identifier of the Notecard. This - * value is set at time of manufacture, and is used to identify the Notecard - * in Notehub. - * - * @return The Notecard Device ID - */ - inline const String & getNotecardUid (void) { - check(); // Ensure the connection to the Notecard is initialized - return _notecard_uid; - } - - /** - * @brief Get the topic type of the most recent R/W operations - * - * @return The current topic type - * - * @see TopicType - */ - TopicType getTopicType (void) const { - return _topic_type; - } - - /** - * @brief Initiate a synchronization operation with Notehub - * - * The Notecard maintains two queues: an inbound queue and an outbound - * queue. The inbound queue is used to receive data from Notehub, while the - * outbound queue is used to send data to Notehub. This method initiates a - * synchronization operation between the Notecard and Notehub. - * - * As the name implies, this method is asynchronous and will only initiate - * the synchronization operation. The actual synchronization operation will - * be performed by the Notecard in the background. - * - * @param type[in] The type of synchronization operation to perform - * @par - * - SyncType::Full - synchronize both the inbound and outbound queues (default) - * - SyncType::Inbound - synchronize only the inbound queues. - * - SyncType::Outbound - synchronize only the outbound queues. - * - * @return 0 if successful, otherwise an error code - * - * @see SyncType - * @see NotecardCommunicationError - */ - int initiateNotehubSync (SyncType type = SyncType::Full) const; - - /** - * @brief Set the inbound polling interval (in minutes) - * - * A cellular Notecard will receive inbound traffic from the Arduino IoT - * Cloud in real-time. As such, the polling interval is used as a fail-safe - * to ensure the Notecard is guaranteed to receive inbound traffic at the - * interval specified by this method. - * - * Alternatively, a LoRa (or Satellite) Notecard does not maintain a - * continuous connection, and therefore must rely on the polling interval to - * establish the maximum acceptable delay before receiving any unsolicited, - * inbound traffic from the Arduino IoT Cloud. The polling interval must - * balance the needs of the application against the regulatory limitations - * of LoRa (or bandwidth limitations and cost of Satellite). - * - * LoRaWAN Fair Use Policy: - * https://www.thethingsnetwork.org/forum/t/fair-use-policy-explained/1300 - * - * @param interval_min[in] The inbound polling interval (in minutes) - * - * @note Set the interval to 0 to disable inbound polling. - * @note Must be set prior to initializing the connection to the Notecard. - */ - inline void setNotehubPollingInterval (int32_t interval_min) { - _inbound_polling_interval_min = (interval_min ? interval_min : -1); - } - - /** - * @brief Set the topic type for R/W operations - * - * @param topic[in] The topic type - * @par - * - TopicType::Command - used to interact with the Arduino IoT Cloud. - * - TopicType::Thing - used to send application data to the Arduino IoT Cloud. - * - * @see TopicType - */ - void setTopicType (TopicType topic) { - _topic_type = topic; - } - - /** - * @brief Set the WiFi credentials to be used by the Notecard - * - * @param ssid[in] The SSID of the WiFi network - * @param pass[in] The password of the WiFi network - * - * @return 0 if successful, otherwise an error code - * - * @note This method is only applicable when using a Wi-Fi capable Notecard, - * and is unnecessary when using a Notecard with cellular connectivity. - * If the Notecard is not Wi-Fi capable, this method will be a no-op. - * - * @see NotecardCommunicationError - */ - int setWiFiCredentials (const String & ssid, const String & pass); - - // ConnectionHandler interface - virtual bool available() override; - virtual unsigned long getTime() override; - virtual int read() override; - virtual int write(const uint8_t *buf, size_t size) override; - - protected: - - virtual NetworkConnectionState update_handleInit () override; - virtual NetworkConnectionState update_handleConnecting () override; - virtual NetworkConnectionState update_handleConnected () override; - virtual NetworkConnectionState update_handleDisconnecting() override; - virtual NetworkConnectionState update_handleDisconnected () override; - - private: - - // Private members - Notecard _notecard; - String _device_id; - String _notecard_uid; - String _project_uid; - HardwareSerial * _serial; - TwoWire * _wire; - uint8_t * _inbound_buffer; - uint32_t _conn_start_ms; - uint32_t _i2c_address; - uint32_t _i2c_max; - uint32_t _inbound_buffer_index; - uint32_t _inbound_buffer_size; - int32_t _inbound_polling_interval_min; - uint32_t _uart_baud; - bool _en_hw_int; - TopicType _topic_type; - - // Private methods - bool armInterrupt (void) const; - bool configureConnection (bool connect) const; - uint_fast8_t connected (void) const; - J * getNote (bool pop = false) const; - bool updateUidCache (void); -}; - -#endif /* ARDUINO_NOTECARD_CONNECTION_HANDLER_H_ */ From 533bba6c2abaf82fabcec5a0beb55f2e1e9870c8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Oct 2025 13:52:08 +0000 Subject: [PATCH 201/203] Bump actions/download-artifact from 5 to 6 Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 5 to 6. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 62c898a4..96b99142 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -108,7 +108,7 @@ jobs: uses: actions/checkout@v5 - name: Download configuration files artifact - uses: actions/download-artifact@v5 + uses: actions/download-artifact@v6 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} path: ${{ env.CONFIGURATIONS_FOLDER }} From 62676bcdeea1b8f59ad4775984a24e40dd0c8a9d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Oct 2025 14:20:59 +0000 Subject: [PATCH 202/203] Bump actions/upload-artifact from 4 to 5 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4 to 5. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/compile-examples.yml | 2 +- .github/workflows/sync-labels.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index ff8b3839..6ac1e7c0 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -239,7 +239,7 @@ jobs: - name: Save memory usage change report as artifact if: github.event_name == 'pull_request' - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 with: if-no-files-found: error name: sketches-report-${{ matrix.board.artifact-name-suffix }} diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 62c898a4..23a751a0 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -70,7 +70,7 @@ jobs: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} - name: Pass configuration files to next job via workflow artifact - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 with: path: | *.yaml From 49df2cab63e02132838ad97c23a604cff30a93af Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 21 Nov 2025 13:01:38 +0000 Subject: [PATCH 203/203] Bump actions/checkout from 5 to 6 Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/check-arduino.yml | 2 +- .github/workflows/compile-examples.yml | 6 +++--- .github/workflows/spell-check.yml | 2 +- .github/workflows/sync-labels.yml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index e13b9907..97b2bf2a 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v5 + uses: actions/checkout@v6 - name: Arduino Lint uses: arduino/arduino-lint-action@v2 diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 17fe688a..27478a98 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -156,13 +156,13 @@ jobs: source-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 # It's necessary to checkout the platform before installing it so that the ArduinoCore-API dependency can be added - name: Checkout ArduinoCore-mbed # this step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used if: matrix.board.platform-name == 'arduino:mbed' - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: repository: arduino/ArduinoCore-mbed # The arduino/actions/libraries/compile-examples action will install the platform from this path @@ -171,7 +171,7 @@ jobs: - name: Checkout ArduinoCore-API # This step only needed when the Arduino mbed-Enabled Boards platform sourced from the repository is being used if: matrix.board.platform-name == 'arduino:mbed' - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: repository: arduino/ArduinoCore-API path: ${{ env.ARDUINOCORE_API_STAGING_PATH }} diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 19f5d38f..8fc4b8c6 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v5 + uses: actions/checkout@v6 - name: Spell check uses: codespell-project/actions-codespell@master diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index cb552119..d49c1cb6 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v5 + uses: actions/checkout@v6 - name: Download JSON schema for labels configuration file id: download-schema @@ -105,7 +105,7 @@ jobs: echo "::set-output name=flag::--dry-run" - name: Checkout repository - uses: actions/checkout@v5 + uses: actions/checkout@v6 - name: Download configuration files artifact uses: actions/download-artifact@v6