Skip to content

Commit

Permalink
feat: NotecardConnectionManager
Browse files Browse the repository at this point in the history
  • Loading branch information
zfields committed Jul 25, 2024
1 parent d05d54c commit 434f694
Show file tree
Hide file tree
Showing 8 changed files with 1,233 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Library for handling and managing network connections by providing keep-alive fu
#if 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)
Expand Down
42 changes: 34 additions & 8 deletions examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
/* SECRET_ fields are in arduino_secrets.h included above
* if using a WiFi board (Arduino MKR1000, MKR WiFi 1010, Nano 33 IoT, UNO
*
* 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, Serial);
*
* 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
Expand All @@ -31,10 +42,25 @@

#include <Arduino_ConnectionHandler.h>

#if defined(BOARD_HAS_ETHERNET)
#if !(defined(USE_NOTECARD) || 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(USE_NOTECARD)
/* 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"
#endif

#if defined(USE_NOTECARD)
NotecardConnectionHandler conMan(NOTECARD_PRODUCT_UID);
#elif 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)
Expand All @@ -48,9 +74,9 @@ CellularConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET
#endif

void setup() {
/* Initialize serial 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__
setDebugMessageLevel(DBG_INFO);
#endif
Expand Down
4 changes: 2 additions & 2 deletions examples/ConnectionHandlerDemo/arduino_secrets.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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";
Expand Down
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
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.0)
28 changes: 22 additions & 6 deletions src/Arduino_ConnectionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@
INCLUDES
******************************************************************************/

#if defined __has_include
#if __has_include (<Notecard.h>)
#define USE_NOTECARD
#endif
#endif

#if !defined(__AVR__)
# include <Arduino_DebugUtils.h>
#endif

#include <Arduino.h>

#ifndef USE_NOTECARD

#ifdef ARDUINO_SAMD_MKR1000
#include <WiFi101.h>
#include <WiFiUdp.h>
Expand Down Expand Up @@ -179,6 +187,8 @@
#define NETWORK_HARDWARE_ERROR
#endif

#endif // USE_NOTECARD

/******************************************************************************
TYPEDEFS
******************************************************************************/
Expand Down Expand Up @@ -206,7 +216,8 @@ enum class NetworkAdapter {
GSM,
LORA,
CATM1,
CELL
CELL,
NOTECARD
};

typedef void (*OnNetworkEventCallback)();
Expand Down Expand Up @@ -239,11 +250,13 @@ class ConnectionHandler {

ConnectionHandler(bool const keep_alive, NetworkAdapter interface);


NetworkConnectionState check();

#if !defined(BOARD_HAS_LORA)
virtual unsigned long getTime() = 0;
#endif

#if !defined(BOARD_HAS_LORA) && !defined(USE_NOTECARD)
virtual Client &getClient() = 0;
virtual UDP &getUDP() = 0;
#else
Expand Down Expand Up @@ -279,16 +292,19 @@ class ConnectionHandler {
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;
OnNetworkEventCallback _on_connect_event_callback = NULL,
_on_disconnect_event_callback = NULL,
_on_error_event_callback = NULL;
};

#if defined(USE_NOTECARD)
#include "Arduino_NotecardConnectionHandler.h"
#endif

#if defined(BOARD_HAS_WIFI)
#include "Arduino_WiFiConnectionHandler.h"
#elif defined(BOARD_HAS_GSM)
Expand Down
Loading

0 comments on commit 434f694

Please sign in to comment.