Skip to content

Commit c3db60b

Browse files
committed
feat: NotecardConnectionManager
1 parent d05d54c commit c3db60b

6 files changed

+1174
-13
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vscode/

examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
/* SECRET_ fields are in arduino_secrets.h included above
2-
* if using a WiFi board (Arduino MKR1000, MKR WiFi 1010, Nano 33 IoT, UNO
2+
*
3+
* If using a Host + Notecard connected over I2C you'll need a
4+
* NotecardConnectionHandler object as follows
5+
*
6+
* NotecardConnectionHandler conMan(NOTECARD_PRODUCT_UID);
7+
*
8+
* If using a Host + Notecard connected over Serial you'll need a
9+
* NotecardConnectionHandler object as follows
10+
*
11+
* NotecardConnectionHandler conMan(NOTECARD_PRODUCT_UID, Serial);
12+
*
13+
* If using a WiFi board (Arduino MKR1000, MKR WiFi 1010, Nano 33 IoT, UNO
314
* WiFi Rev 2 or ESP8266/32), create a WiFiConnectionHandler object by adding
415
* Network Name (SECRET_SSID) and password (SECRET_PASS) in the arduino_secrets.h
516
* file (or Secrets tab in Create Web Editor).
@@ -31,7 +42,17 @@
3142

3243
#include <Arduino_ConnectionHandler.h>
3344

34-
#if defined(BOARD_HAS_ETHERNET)
45+
#if defined(USE_NOTECARD)
46+
/* The Notecard can provide connectivity to almost any board via ESLOV (I2C)
47+
* or UART. An empty string (or the default value provided below) will not
48+
* override the Notecard's existing configuration.
49+
* Learn more at: https://dev.blues.io */
50+
#define NOTECARD_PRODUCT_UID "com.domain.you:product"
51+
#endif
52+
53+
#if defined(USE_NOTECARD)
54+
NotecardConnectionHandler conMan(NOTECARD_PRODUCT_UID);
55+
#elif defined(BOARD_HAS_ETHERNET)
3556
EthernetConnectionHandler conMan(SECRET_IP, SECRET_DNS, SECRET_GATEWAY, SECRET_NETMASK);
3657
#elif defined(BOARD_HAS_WIFI)
3758
WiFiConnectionHandler conMan(SECRET_SSID, SECRET_PASS);
@@ -48,9 +69,9 @@ CellularConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET
4869
#endif
4970

5071
void setup() {
72+
/* Initialize serial and wait up to 5 seconds for port to open */
5173
Serial.begin(9600);
52-
/* Give a few seconds for the Serial connection to be available */
53-
delay(4000);
74+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
5475
#ifndef __AVR__
5576
setDebugMessageLevel(DBG_INFO);
5677
#endif

library.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name=Arduino_ConnectionHandler
22
version=0.9.0
33
author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al.
44
maintainer=Arduino <[email protected]>
5-
sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet])
5+
sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet], Notecard)
66
paragraph=Originally part of ArduinoIoTCloud
77
category=Communication
88
url=https://github.com/arduino-libraries/Arduino_ConnectionHandler
9-
architectures=samd,esp32,esp8266,mbed,megaavr,mbed_nano,mbed_portenta,mbed_nicla,mbed_opta,mbed_giga,renesas_portenta,renesas_uno,mbed_edge
10-
depends=Arduino_DebugUtils, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN
9+
architectures=samd,esp32,esp8266,mbed,megaavr,mbed_nano,mbed_portenta,mbed_nicla,mbed_opta,mbed_giga,renesas_portenta,renesas_uno,mbed_edge,stm32
10+
depends=Arduino_DebugUtils, Blues Wireless Notecard (>=1.6.0), WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN

src/Arduino_ConnectionHandler.h

+16-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
#include <Arduino.h>
3030

31+
#ifndef USE_NOTECARD
32+
3133
#ifdef ARDUINO_SAMD_MKR1000
3234
#include <WiFi101.h>
3335
#include <WiFiUdp.h>
@@ -179,6 +181,8 @@
179181
#define NETWORK_HARDWARE_ERROR
180182
#endif
181183

184+
#endif // USE_NOTECARD
185+
182186
/******************************************************************************
183187
TYPEDEFS
184188
******************************************************************************/
@@ -206,7 +210,8 @@ enum class NetworkAdapter {
206210
GSM,
207211
LORA,
208212
CATM1,
209-
CELL
213+
CELL,
214+
NOTECARD
210215
};
211216

212217
typedef void (*OnNetworkEventCallback)();
@@ -239,11 +244,13 @@ class ConnectionHandler {
239244

240245
ConnectionHandler(bool const keep_alive, NetworkAdapter interface);
241246

242-
243247
NetworkConnectionState check();
244248

245249
#if !defined(BOARD_HAS_LORA)
246250
virtual unsigned long getTime() = 0;
251+
#endif
252+
253+
#if !defined(BOARD_HAS_LORA) && !defined(USE_NOTECARD)
247254
virtual Client &getClient() = 0;
248255
virtual UDP &getUDP() = 0;
249256
#else
@@ -279,16 +286,19 @@ class ConnectionHandler {
279286
virtual NetworkConnectionState update_handleDisconnecting() = 0;
280287
virtual NetworkConnectionState update_handleDisconnected () = 0;
281288

282-
283289
private:
284290

285291
unsigned long _lastConnectionTickTime;
286292
NetworkConnectionState _current_net_connection_state;
287-
OnNetworkEventCallback _on_connect_event_callback = NULL,
288-
_on_disconnect_event_callback = NULL,
289-
_on_error_event_callback = NULL;
293+
OnNetworkEventCallback _on_connect_event_callback = NULL,
294+
_on_disconnect_event_callback = NULL,
295+
_on_error_event_callback = NULL;
290296
};
291297

298+
#if defined(USE_NOTECARD)
299+
#include "Arduino_NotecardConnectionHandler.h"
300+
#endif
301+
292302
#if defined(BOARD_HAS_WIFI)
293303
#include "Arduino_WiFiConnectionHandler.h"
294304
#elif defined(BOARD_HAS_GSM)

0 commit comments

Comments
 (0)