From 36aa0080e9ecd699e8fc53157f9ea00e2c957639 Mon Sep 17 00:00:00 2001 From: Giampaolo Mancini Date: Wed, 13 Dec 2023 13:06:49 +0100 Subject: [PATCH 01/16] 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 02/16] 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 03/16] 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 04/16] 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 05/16] 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 06/16] 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 07/16] 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 08/16] 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 09/16] 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 10/16] 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 11/16] 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 12/16] 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 13/16] 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 14/16] 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 15/16] 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 16/16] 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]) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy