Skip to content

Commit 434f694

Browse files
committed
feat: NotecardConnectionManager
1 parent d05d54c commit 434f694

8 files changed

+1233
-20
lines changed

.gitignore

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

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Library for handling and managing network connections by providing keep-alive fu
2020
#if defined(BOARD_HAS_ETHERNET)
2121
EthernetConnectionHandler conMan;
2222
#elif defined(BOARD_HAS_WIFI)
23-
WiFiConnectionHandler conMan("SECRET_SSID", "SECRET_PASS");
23+
WiFiConnectionHandler conMan("SECRET_WIFI_SSID", "SECRET_WIFI_PASS");
2424
#elif defined(BOARD_HAS_GSM)
2525
GSMConnectionHandler conMan("SECRET_PIN", "SECRET_APN", "SECRET_GSM_LOGIN", "SECRET_GSM_PASS");
2626
#elif defined(BOARD_HAS_NB)

examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino

+34-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
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
4-
* Network Name (SECRET_SSID) and password (SECRET_PASS) in the arduino_secrets.h
5-
* file (or Secrets tab in Create Web Editor).
15+
* Network Name (SECRET_WIFI_SSID) and password (SECRET_WIFI_PASS) in the
16+
* arduino_secrets.h file (or Secrets tab in Create Web Editor).
617
*
7-
* WiFiConnectionHandler conMan(SECRET_SSID, SECRET_PASS);
18+
* WiFiConnectionHandler conMan(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
819
*
920
* If using a MKR GSM 1400 or other GSM boards supporting the same API you'll
1021
* need a GSMConnectionHandler object as follows
@@ -31,10 +42,25 @@
3142

3243
#include <Arduino_ConnectionHandler.h>
3344

34-
#if defined(BOARD_HAS_ETHERNET)
45+
#if !(defined(USE_NOTECARD) || defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \
46+
defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT))
47+
#error "Please check Arduino Connection Handler supported boards list: https://github.com/arduino-libraries/Arduino_ConnectionHandler/blob/master/README.md"
48+
#endif
49+
50+
#if defined(USE_NOTECARD)
51+
/* The Notecard can provide connectivity to almost any board via ESLOV (I2C)
52+
* or UART. An empty string (or the default value provided below) will not
53+
* override the Notecard's existing configuration.
54+
* Learn more at: https://dev.blues.io */
55+
#define NOTECARD_PRODUCT_UID "com.domain.you:product"
56+
#endif
57+
58+
#if defined(USE_NOTECARD)
59+
NotecardConnectionHandler conMan(NOTECARD_PRODUCT_UID);
60+
#elif defined(BOARD_HAS_ETHERNET)
3561
EthernetConnectionHandler conMan(SECRET_IP, SECRET_DNS, SECRET_GATEWAY, SECRET_NETMASK);
3662
#elif defined(BOARD_HAS_WIFI)
37-
WiFiConnectionHandler conMan(SECRET_SSID, SECRET_PASS);
63+
WiFiConnectionHandler conMan(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
3864
#elif defined(BOARD_HAS_GSM)
3965
GSMConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS);
4066
#elif defined(BOARD_HAS_NB)
@@ -48,9 +74,9 @@ CellularConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET
4874
#endif
4975

5076
void setup() {
77+
/* Initialize serial and wait up to 5 seconds for port to open */
5178
Serial.begin(9600);
52-
/* Give a few seconds for the Serial connection to be available */
53-
delay(4000);
79+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
5480
#ifndef __AVR__
5581
setDebugMessageLevel(DBG_INFO);
5682
#endif

examples/ConnectionHandlerDemo/arduino_secrets.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Required for WiFiConnectionHandler
2-
const char SECRET_SSID[] = "NETWORK NAME";
3-
const char SECRET_PASS[] = "NETWORK PASSWORD";
2+
const char SECRET_WIFI_SSID[] = "NETWORK NAME";
3+
const char SECRET_WIFI_PASS[] = "NETWORK PASSWORD";
44

55
// Required for GSMConnectionHandler
66
const char SECRET_APN[] = "MOBILE PROVIDER APN ADDRESS";

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, WiFi101, WiFiNINA, MKRGSM, MKRNB, MKRWAN, Blues Wireless Notecard (>=1.6.0)

src/Arduino_ConnectionHandler.h

+22-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@
2222
INCLUDES
2323
******************************************************************************/
2424

25+
#if defined __has_include
26+
#if __has_include (<Notecard.h>)
27+
#define USE_NOTECARD
28+
#endif
29+
#endif
30+
2531
#if !defined(__AVR__)
2632
# include <Arduino_DebugUtils.h>
2733
#endif
2834

2935
#include <Arduino.h>
3036

37+
#ifndef USE_NOTECARD
38+
3139
#ifdef ARDUINO_SAMD_MKR1000
3240
#include <WiFi101.h>
3341
#include <WiFiUdp.h>
@@ -179,6 +187,8 @@
179187
#define NETWORK_HARDWARE_ERROR
180188
#endif
181189

190+
#endif // USE_NOTECARD
191+
182192
/******************************************************************************
183193
TYPEDEFS
184194
******************************************************************************/
@@ -206,7 +216,8 @@ enum class NetworkAdapter {
206216
GSM,
207217
LORA,
208218
CATM1,
209-
CELL
219+
CELL,
220+
NOTECARD
210221
};
211222

212223
typedef void (*OnNetworkEventCallback)();
@@ -239,11 +250,13 @@ class ConnectionHandler {
239250

240251
ConnectionHandler(bool const keep_alive, NetworkAdapter interface);
241252

242-
243253
NetworkConnectionState check();
244254

245255
#if !defined(BOARD_HAS_LORA)
246256
virtual unsigned long getTime() = 0;
257+
#endif
258+
259+
#if !defined(BOARD_HAS_LORA) && !defined(USE_NOTECARD)
247260
virtual Client &getClient() = 0;
248261
virtual UDP &getUDP() = 0;
249262
#else
@@ -279,16 +292,19 @@ class ConnectionHandler {
279292
virtual NetworkConnectionState update_handleDisconnecting() = 0;
280293
virtual NetworkConnectionState update_handleDisconnected () = 0;
281294

282-
283295
private:
284296

285297
unsigned long _lastConnectionTickTime;
286298
NetworkConnectionState _current_net_connection_state;
287-
OnNetworkEventCallback _on_connect_event_callback = NULL,
288-
_on_disconnect_event_callback = NULL,
289-
_on_error_event_callback = NULL;
299+
OnNetworkEventCallback _on_connect_event_callback = NULL,
300+
_on_disconnect_event_callback = NULL,
301+
_on_error_event_callback = NULL;
290302
};
291303

304+
#if defined(USE_NOTECARD)
305+
#include "Arduino_NotecardConnectionHandler.h"
306+
#endif
307+
292308
#if defined(BOARD_HAS_WIFI)
293309
#include "Arduino_WiFiConnectionHandler.h"
294310
#elif defined(BOARD_HAS_GSM)

0 commit comments

Comments
 (0)