diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 87aaa450..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 @@ -42,42 +43,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: @@ -165,8 +185,8 @@ 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 }} + 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-.+ diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 9cde1acc..53a9f54f 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 @@ -108,13 +108,13 @@ 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 }} - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v2 + uses: geekyeggo/delete-artifact@v5 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} diff --git a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino index a5be6a7e..13ad117c 100644 --- a/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino +++ b/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino @@ -36,13 +36,15 @@ 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 void setup() { 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"; diff --git a/library.properties b/library.properties index 7739c63f..16239e46 100644 --- a/library.properties +++ b/library.properties @@ -1,7 +1,7 @@ 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.cc +maintainer=Arduino sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) paragraph=Originally part of ArduinoIoTCloud category=Communication diff --git a/src/Arduino_CellularConnectionHandler.cpp b/src/Arduino_CellularConnectionHandler.cpp new file mode 100644 index 00000000..7e543b0e --- /dev/null +++ b/src/Arduino_CellularConnectionHandler.cpp @@ -0,0 +1,95 @@ +/* + 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(); +} + +UDP & CellularConnectionHandler::getUDP() +{ + Debug.print(DBG_ERROR, F("CellularConnectionHandler has no UDP support")); + while(1) {}; +} + +/****************************************************************************** + 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..0c4d5f89 --- /dev/null +++ b/src/Arduino_CellularConnectionHandler.h @@ -0,0 +1,61 @@ +/* + 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; + + + 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..b4f8e315 100644 --- a/src/Arduino_ConnectionHandler.h +++ b/src/Arduino_ConnectionHandler.h @@ -57,10 +57,12 @@ #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 @@ -73,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 @@ -150,7 +154,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 +205,8 @@ enum class NetworkAdapter { NB, GSM, LORA, - CATM1 + CATM1, + CELL }; typedef void (*OnNetworkEventCallback)(); @@ -237,13 +242,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 +307,8 @@ class ConnectionHandler { #include "Arduino_CatM1ConnectionHandler.h" #endif +#if defined(BOARD_HAS_CELLULAR) + #include "Arduino_CellularConnectionHandler.h" +#endif + #endif /* CONNECTION_HANDLER_H_ */ 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; 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_ */ 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