Skip to content

Commit 33e3384

Browse files
committed
feat: ArduinoIoTCloudNotecard
1 parent 12e9def commit 33e3384

27 files changed

+971
-55
lines changed

.github/workflows/compile-examples.yml

+2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ jobs:
192192
- name: arduino:mbed_opta
193193
libraries: |
194194
- name: ArduinoECCX08
195+
- name: Blues Wireless Notecard
195196
sketch-paths: |
196197
- examples/ArduinoIoTCloud-DeferredOTA
198+
- examples/ArduinoIoTCloud-Notecard
197199
- examples/utility/Provisioning
198200
# GIGA
199201
- board:

README.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,27 @@
1010
### What?
1111
The `ArduinoIoTCloud` library is the central element of the firmware enabling certain Arduino boards to connect to the [Arduino IoT Cloud](https://www.arduino.cc/en/IoT/HomePage). The following boards are supported:
1212

13-
* **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`GIGA R1 WiFi`](https://store.arduino.cc/products/giga-r1-wifi), [`Portenta C33`](https://store.arduino.cc/products/portenta-c33), [`UNO R4 WiFi`](https://store.arduino.cc/products/uno-r4-wifi), [`Nano ESP32`](https://store.arduino.cc/products/nano-esp32), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32/releases/tag/2.0.5)
13+
* **Wi-Fi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`GIGA R1 WiFi`](https://store.arduino.cc/products/giga-r1-wifi), [`Portenta C33`](https://store.arduino.cc/products/portenta-c33), [`UNO R4 WiFi`](https://store.arduino.cc/products/uno-r4-wifi), [`Nano ESP32`](https://store.arduino.cc/products/nano-esp32), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32/releases/tag/2.0.5)
1414
* **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415)
1515
* **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413)
1616
* **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310)
1717
* **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Breakout`](https://store.arduino.cc/products/arduino-portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/products/arduino-portenta-machine-control), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`OPTA RS485`](https://store.arduino.cc/products/opta-rs485), [`OPTA Lite`](https://store.arduino.cc/products/opta-lite), [`Portenta C33`](https://store.arduino.cc/products/portenta-c33) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet)
18+
* **Notecard**: [Provides Cellular/LoRa/Satellite/Wi-Fi to any modern board/architecture](https://shop.blues.com/collections/notecard)
19+
20+
#### More About Notecard Connectivity
21+
22+
The Notecard is a wireless, secure abstraction for device connectivity, that can
23+
be used to enable _ANY*_ device with I2C, or UART, to connect to the Arduino IoT
24+
Cloud via cellular, LoRa, satellite or Wi-Fi (including the devices listed
25+
above)!
26+
27+
As a result, the STM32 architecture has now been added to this library. If you
28+
have an STM32 device, you are now able to connect it to the Arduino IoT Cloud by
29+
using a Notecard to provide a secure communication channel.
30+
31+
> \*_Unfortunately, the AVR architecture is not supported by the Arduino IoT
32+
> Cloud library. Therefore, those devices are ineligible for use with the
33+
> Notecard._
1834
1935
### How?
2036
1) Register your Arduino IoT Cloud capable board via [Arduino IoT Cloud](https://create.arduino.cc/iot) (Devices Section).
@@ -96,4 +112,3 @@ Boards can authenticate to the ArduinoIoTCloud servers using 3 methods:
96112

97113
* `APP_EUI` and `APP_KEY`. This values are defined in the `thingProperties.h` file and included in the Sketch. Boards that are using this method are: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310)
98114

99-

examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ void setup() {
1717
Serial.begin(9600);
1818
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
1919

20+
/* Specify the level of detail for debug messages */
21+
setDebugMessageLevel(DBG_INFO);
22+
2023
/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
2124
initProperties();
2225

2326
/* Initialize Arduino IoT Cloud library */
2427
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
2528

26-
setDebugMessageLevel(DBG_INFO);
2729
ArduinoCloud.printDebugInfo();
2830
}
2931

examples/ArduinoIoTCloud-Advanced/thingProperties.h

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1212
#endif
1313

14+
#if defined(BOARD_HAS_LORA)
15+
#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
16+
#endif
17+
1418
void onSwitchButtonChange();
1519
void onColorChange();
1620

@@ -23,6 +27,9 @@ void initProperties() {
2327
ArduinoCloud.setBoardId(BOARD_ID);
2428
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
2529
#endif
30+
#if defined(BOARD_HAS_LORA)
31+
ArduinoCloud.setThingId(THING_ID);
32+
#endif
2633
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)
2734
ArduinoCloud.addProperty(switchButton, Permission::Write).onUpdate(onSwitchButtonChange);
2835
ArduinoCloud.addProperty(location, Permission::Read).publishOnChange(0.0f);

examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ void setup() {
2525
Serial.begin(9600);
2626
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
2727

28+
/* Specify the level of detail for debug messages */
29+
setDebugMessageLevel(DBG_INFO);
30+
2831
/* Configure LED pin as an output */
2932
pinMode(LED_BUILTIN, OUTPUT);
3033

@@ -34,7 +37,6 @@ void setup() {
3437
/* Initialize Arduino IoT Cloud library */
3538
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
3639

37-
setDebugMessageLevel(DBG_INFO);
3840
ArduinoCloud.printDebugInfo();
3941
}
4042

examples/ArduinoIoTCloud-Basic/thingProperties.h

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1212
#endif
1313

14+
#if defined(BOARD_HAS_LORA)
15+
#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
16+
#endif
17+
1418
void onLedChange();
1519

1620
bool led;
@@ -22,6 +26,9 @@ void initProperties() {
2226
ArduinoCloud.setBoardId(BOARD_ID);
2327
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
2428
#endif
29+
#if defined(BOARD_HAS_LORA)
30+
ArduinoCloud.setThingId(THING_ID);
31+
#endif
2532
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)
2633
ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
2734
ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);

examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ void setup() {
3333
Serial.begin(9600);
3434
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
3535

36+
/* Specify the level of detail for debug messages */
37+
setDebugMessageLevel(DBG_INFO);
38+
3639
/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
3740
initProperties();
3841

@@ -51,7 +54,6 @@ void setup() {
5154
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::SYNC, doThisOnSync);
5255
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::DISCONNECT, doThisOnDisconnect);
5356

54-
setDebugMessageLevel(DBG_INFO);
5557
ArduinoCloud.printDebugInfo();
5658
}
5759

examples/ArduinoIoTCloud-Callbacks/thingProperties.h

+7
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@
1111
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1212
#endif
1313

14+
#if defined(BOARD_HAS_LORA)
15+
#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
16+
#endif
17+
1418
void initProperties() {
1519
#if defined(BOARD_HAS_SECRET_KEY)
1620
ArduinoCloud.setBoardId(BOARD_ID);
1721
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
1822
#endif
23+
#if defined(BOARD_HAS_LORA)
24+
ArduinoCloud.setThingId(THING_ID);
25+
#endif
1926
}
2027

2128
#if defined(BOARD_HAS_WIFI)

examples/ArduinoIoTCloud-DeferredOTA/ArduinoIoTCloud-DeferredOTA.ino

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ void setup() {
5858
Serial.begin(9600);
5959
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
6060

61+
/* Specify the level of detail for debug messages */
62+
setDebugMessageLevel(DBG_INFO);
63+
6164
/* Configure LED pin as an output */
6265
pinMode(LED_BUILTIN, OUTPUT);
6366

@@ -70,7 +73,6 @@ void setup() {
7073
/* Setup OTA callback */
7174
ArduinoCloud.onOTARequestCb(onOTARequestCallback);
7275

73-
setDebugMessageLevel(DBG_INFO);
7476
ArduinoCloud.printDebugInfo();
7577
}
7678

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
This sketch demonstrates how to exchange data between your board and the
3+
Arduino IoT Cloud, while using the Notecard for wireless communication.
4+
5+
* Connect a potentiometer (or other analog sensor) to A0.
6+
* When the potentiometer (or sensor) value changes the data is sent to the Cloud.
7+
* When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF.
8+
9+
IMPORTANT:
10+
This sketch works with any Wi-Fi, Cellular, LoRa or Satellite enabled Notecard.
11+
12+
The full list of compatible boards can be found here:
13+
- https://github.com/arduino-libraries/ArduinoIoTCloud#what
14+
*/
15+
16+
#include <Notecard.h>
17+
#include "thingProperties.h"
18+
19+
#if !defined(LED_BUILTIN) && !defined(ARDUINO_NANO_ESP32)
20+
static int const LED_BUILTIN = 2;
21+
#endif
22+
23+
/*
24+
* Choose an interrupt capable pin to reduce polling and improve
25+
* the overall responsiveness of the ArduinoIoTCloud library
26+
*/
27+
// #define ATTN_PIN 9
28+
29+
void setup() {
30+
/* Initialize serial and wait up to 5 seconds for port to open */
31+
Serial.begin(9600);
32+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
33+
34+
/* Specify the level of detail for debug messages */
35+
setDebugMessageLevel(DBG_INFO);
36+
37+
/* Configure LED pin as an output */
38+
pinMode(LED_BUILTIN, OUTPUT);
39+
40+
/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
41+
initProperties();
42+
43+
/* Initialize Arduino IoT Cloud library */
44+
#ifndef ATTN_PIN
45+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
46+
ArduinoCloud.setNotecardPollingInterval(3000); // default: 1000ms, min: 250ms
47+
#else
48+
ArduinoCloud.begin(ArduinoIoTPreferredConnection, ATTN_PIN);
49+
#endif
50+
51+
ArduinoCloud.printDebugInfo();
52+
}
53+
54+
void loop() {
55+
ArduinoCloud.update();
56+
potentiometer = analogRead(A0);
57+
seconds = millis() / 1000;
58+
}
59+
60+
/*
61+
* 'onLedChange' is called when the "led" property of your Thing changes
62+
*/
63+
void onLedChange() {
64+
Serial.print("LED set to ");
65+
Serial.println(led);
66+
digitalWrite(LED_BUILTIN, led);
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
Notecard Connectivity
2+
=====================
3+
4+
The Notecard is a wireless, secure abstraction for device connectivity, that can
5+
be used to enable _ANY*_ device with I2C, or UART, to connect to the Arduino IoT
6+
Cloud via cellular, LoRa, satellite or Wi-Fi!
7+
8+
As a result, your existing device architecture can now have first class support
9+
in the Arduino IoT Cloud, by using a Notecard as a secure communication channel.
10+
11+
> \*_While any device with I2C/UART may use the Notecard, the Arduino IoT Cloud
12+
> library is not supported by the AVR toolchain. Therefore, devices based on the
13+
> AVR architecture cannot access the Arduino IoT Cloud via the Notecard._
14+
>
15+
> _However, any device (including AVR), may use the Notecard library to send data
16+
> to Notehub, then that data may be routed to any endpoint of your choosing. See the
17+
> [Notecard Routing Guide](https://dev.blues.io/guides-and-tutorials/routing-data-to-cloud)
18+
> for more information..._
19+
20+
Wireless Connectivity Options
21+
-----------------------------
22+
23+
- [Cellular](https://shop.blues.com/collections/notecard/products/notecard-cellular)
24+
- [Cellular + Wi-Fi](https://shop.blues.com/collections/notecard/products/notecard-cell-wifi)
25+
- [Wi-Fi](https://shop.blues.com/collections/notecard/products/wifi-notecard)
26+
- [LoRa](https://shop.blues.com/collections/notecard/products/notecard-lora)
27+
- [Satellite](https://shop.blues.com/products/starnote)
28+
29+
How it Works
30+
------------
31+
32+
**Architecture Diagram:**
33+
34+
```
35+
-------- ------------ ----------- -----------
36+
| | | | | | | |
37+
| Host | | | Secure | | | Arduino |
38+
| MCU |---<I2C/UART>---| Notecard | ( ( Wireless ) ) | Notehub |---<TLS>---| IoT |
39+
| | | | Protocol | | | Cloud |
40+
|______| |__________| |_________| |_________|
41+
```
42+
43+
Getting Started
44+
---------------
45+
46+
### Setup a Notehub Account
47+
48+
Using the Notecard only requires a couple of easy steps:
49+
50+
1. [Purchase a Notecard](https://shop.blues.com/collections/notecard) (and
51+
[Notecarrier](https://shop.blues.com/collections/notecarrier)) that fits the
52+
needs of your device.
53+
> _**NOTE:** We recommend starting with our [Dev Kit](https://shop.blues.com/products/blues-global-starter-kit)
54+
> if you are unsure._
55+
1. [Setup a Notehub account](https://dev.blues.io/quickstart/notecard-quickstart/notecard-and-notecarrier-f/#set-up-notehub).
56+
> _**NOTE:** Notehub accounts are free (no credit card required)._
57+
1. [Create a project on your Notehub account](https://dev.blues.io/quickstart/notecard-quickstart/notecard-and-notecarrier-f/#create-a-notehub-project).
58+
1. In `thingProperties.h`, replace "com.domain.you:product" (from
59+
`NOTECARD_PRODUCT_UID`) with the ProductUID of your new Notehub project.
60+
61+
### Power-up the Device
62+
63+
1. [Connect the Notecard to your Host MCU](https://dev.blues.io/quickstart/notecard-quickstart/notecard-and-notecarrier-f/#connect-your-notecard-and-notecarrier)
64+
1. Flash the `ArduinoIoTCloud-Notecard` example sketch to your device. You
65+
should see the device reporting itself as online in your [Notehub Project](https://notehub.io).
66+
67+
### Associate Notecard to Arduino IoT Cloud
68+
69+
1. Create a "MANUAL Device" in the Arduino IoT Cloud, then [add environment
70+
variables for the "Device ID" and "Secret Key" to your Notecard in Notehub](https://dev.blues.io/guides-and-tutorials/notecard-guides/understanding-environment-variables/#setting-a-notehub-device-variable).
71+
- `_sn`: \<Device ID\>
72+
- `_secret_key`: \<Secret Key\>
73+
74+
### More Information
75+
76+
For more information about the Notecard and Notehub in general, please see our
77+
[Quickstart Guide](https://dev.blues.io/quickstart/) for a general overview of
78+
how the Notecard and Notehub are designed to work.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <Arduino_ConnectionHandler.h>
2+
3+
/* If provided, the Wi-Fi Credentials will be passed along to the Notecard. If
4+
* the Notecard supports Wi-Fi, it will attempt to connect to the network using
5+
* these credentials, if not, the Notecard will safely ignore these values. */
6+
#define SECRET_WIFI_SSID "YOUR_WIFI_NETWORK_NAME"
7+
#define SECRET_WIFI_PASS "YOUR_WIFI_PASSWORD"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <string.h>
2+
3+
#include <ArduinoIoTCloud.h>
4+
#include <Arduino_ConnectionHandler.h>
5+
#include "arduino_secrets.h"
6+
7+
/* The Notecard can provide connectivity to almost any board via ESLOV (I2C)
8+
* or UART. An empty string (or the default value provided below) will not
9+
* override the Notecard's existing configuration.
10+
* Learn more at: https://dev.blues.io */
11+
#define NOTECARD_PRODUCT_UID "com.domain.you:product"
12+
13+
/* Uncomment the following line to use the Notecard over UART */
14+
// #define UART_INTERFACE Serial1
15+
16+
void onLedChange();
17+
18+
bool led;
19+
int potentiometer;
20+
int seconds;
21+
22+
#ifndef UART_INTERFACE
23+
NotecardConnectionHandler ArduinoIoTPreferredConnection(NOTECARD_PRODUCT_UID);
24+
#else
25+
NotecardConnectionHandler ArduinoIoTPreferredConnection(NOTECARD_PRODUCT_UID, UART_INTERFACE);
26+
#endif
27+
28+
void initProperties() {
29+
ArduinoCloud.addProperty(led, Permission::ReadWrite).onUpdate(onLedChange);
30+
ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
31+
ArduinoCloud.addProperty(seconds, Permission::Read).publishEvery(5 * MINUTES);
32+
33+
if (::strncmp(SECRET_WIFI_SSID, "YOUR_WIFI_NETWORK_NAME", sizeof(SECRET_WIFI_SSID))) {
34+
ArduinoIoTPreferredConnection.setWiFiCredentials(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
35+
}
36+
}

examples/ArduinoIoTCloud-Schedule/ArduinoIoTCloud-Schedule.ino

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ void setup() {
1717
Serial.begin(9600);
1818
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
1919

20+
/* Specify the level of detail for debug messages */
21+
setDebugMessageLevel(DBG_INFO);
22+
2023
/* Configure LED pin as an output */
2124
pinMode(LED_BUILTIN, OUTPUT);
2225

@@ -26,7 +29,6 @@ void setup() {
2629
/* Initialize Arduino IoT Cloud library */
2730
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
2831

29-
setDebugMessageLevel(DBG_INFO);
3032
ArduinoCloud.printDebugInfo();
3133

3234
/* Setup one shot schedule example */

0 commit comments

Comments
 (0)