Skip to content

Commit a6fd3e2

Browse files
committed
feat: NotecardConnectionManager
1 parent f39958c commit a6fd3e2

10 files changed

+1232
-22
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

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include <Arduino.h>
3030
#include "Arduino_ConnectionHandlerDefinitions.h"
3131

32+
#if defined(USE_NOTECARD)
33+
#include "Arduino_NotecardConnectionHandler.h"
34+
#else
35+
3236
#if defined(BOARD_HAS_WIFI)
3337
#include "Arduino_WiFiConnectionHandler.h"
3438
#endif
@@ -57,4 +61,6 @@
5761
#include "Arduino_CellularConnectionHandler.h"
5862
#endif
5963

64+
#endif // USE_NOTECARD
65+
6066
#endif /* CONNECTION_HANDLER_H_ */

src/Arduino_ConnectionHandlerDefinitions.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@
2121
INCLUDES
2222
******************************************************************************/
2323

24+
#if defined __has_include
25+
#if __has_include (<Notecard.h>)
26+
#define USE_NOTECARD
27+
#endif
28+
#endif
29+
2430
#include <Arduino.h>
2531

32+
#ifndef USE_NOTECARD
33+
2634
#ifdef ARDUINO_SAMD_MKR1000
2735
#define BOARD_HAS_WIFI
2836
#define NETWORK_HARDWARE_ERROR WL_NO_SHIELD
@@ -136,6 +144,8 @@
136144
#define NETWORK_HARDWARE_ERROR
137145
#endif
138146

147+
#endif // USE_NOTECARD
148+
139149
/******************************************************************************
140150
TYPEDEFS
141151
******************************************************************************/
@@ -163,7 +173,8 @@ enum class NetworkAdapter {
163173
GSM,
164174
LORA,
165175
CATM1,
166-
CELL
176+
CELL,
177+
NOTECARD
167178
};
168179

169180
/******************************************************************************

src/Arduino_ConnectionHandlerInterface.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@ class ConnectionHandler {
4848

4949
NetworkConnectionState check();
5050

51-
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)
51+
#if not defined(BOARD_HAS_LORA)
5252
virtual unsigned long getTime() = 0;
53-
virtual Client &getClient() = 0;
54-
virtual UDP &getUDP() = 0;
5553
#endif
5654

57-
#if defined(BOARD_HAS_LORA)
58-
virtual int write(const uint8_t *buf, size_t size) = 0;
59-
virtual int read() = 0;
55+
#if defined(USE_NOTECARD) || defined(BOARD_HAS_LORA)
6056
virtual bool available() = 0;
57+
virtual int read() = 0;
58+
virtual int write(const uint8_t *buf, size_t size) = 0;
59+
#else
60+
virtual Client &getClient() = 0;
61+
virtual UDP &getUDP() = 0;
6162
#endif
6263

6364
NetworkConnectionState getStatus() __attribute__((deprecated)) {
@@ -87,7 +88,6 @@ class ConnectionHandler {
8788
virtual NetworkConnectionState update_handleDisconnecting() = 0;
8889
virtual NetworkConnectionState update_handleDisconnected () = 0;
8990

90-
9191
private:
9292

9393
unsigned long _lastConnectionTickTime;

0 commit comments

Comments
 (0)