Skip to content

Commit 2903300

Browse files
committed
feat: ArduinoIoTCloudNotecard
1 parent 796d687 commit 2903300

18 files changed

+951
-51
lines changed

Diff for: .github/workflows/compile-examples.yml

+35-1
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,12 @@ jobs:
103103
- name: arduino:samd
104104
libraries: |
105105
- name: ArduinoECCX08
106+
- name: Blues Wireless Notecard
106107
- name: RTCZero
107108
- name: WiFi101
108109
- source-url: https://github.com/adafruit/Adafruit_SleepyDog.git
109110
sketch-paths: |
111+
- examples/ArduinoIoTCloud-Notecard
110112
- examples/utility/Provisioning
111113
# MKR WiFi 1010, Nano 33 IoT, Nano RP2040 Connect
112114
- board:
@@ -117,12 +119,14 @@ jobs:
117119
- name: arduino:mbed_nano
118120
libraries: |
119121
- name: ArduinoECCX08
122+
- name: Blues Wireless Notecard
120123
- name: RTCZero
121124
- name: WiFiNINA
122125
- name: Arduino_JSON
123126
- source-url: https://github.com/adafruit/Adafruit_SleepyDog.git
124127
sketch-paths: |
125128
- examples/ArduinoIoTCloud-DeferredOTA
129+
- examples/ArduinoIoTCloud-Notecard
126130
- examples/utility/Provisioning
127131
- examples/utility/SelfProvisioning
128132
- board:
@@ -132,10 +136,12 @@ jobs:
132136
- name: arduino:samd
133137
libraries: |
134138
- name: ArduinoECCX08
139+
- name: Blues Wireless Notecard
135140
- name: RTCZero
136141
- name: MKRWAN
137142
- source-url: https://github.com/adafruit/Adafruit_SleepyDog.git
138-
sketch-paths:
143+
sketch-paths: |
144+
- examples/ArduinoIoTCloud-Notecard
139145
# GSM boards
140146
- board:
141147
type: gsm
@@ -144,10 +150,12 @@ jobs:
144150
- name: arduino:samd
145151
libraries: |
146152
- name: ArduinoECCX08
153+
- name: Blues Wireless Notecard
147154
- name: RTCZero
148155
- name: MKRGSM
149156
- source-url: https://github.com/adafruit/Adafruit_SleepyDog.git
150157
sketch-paths: |
158+
- examples/ArduinoIoTCloud-Notecard
151159
- examples/utility/Provisioning
152160
# NB boards
153161
- board:
@@ -157,10 +165,12 @@ jobs:
157165
- name: arduino:samd
158166
libraries: |
159167
- name: ArduinoECCX08
168+
- name: Blues Wireless Notecard
160169
- name: RTCZero
161170
- name: MKRNB
162171
- source-url: https://github.com/adafruit/Adafruit_SleepyDog.git
163172
sketch-paths: |
173+
- examples/ArduinoIoTCloud-Notecard
164174
- examples/utility/Provisioning
165175
# Portenta
166176
- board:
@@ -171,8 +181,10 @@ jobs:
171181
libraries: |
172182
- name: ArduinoECCX08
173183
- name: Arduino_Cellular
184+
- name: Blues Wireless Notecard
174185
sketch-paths: |
175186
- examples/ArduinoIoTCloud-DeferredOTA
187+
- examples/ArduinoIoTCloud-Notecard
176188
- examples/utility/Provisioning
177189
# Nicla Vision
178190
- board:
@@ -181,8 +193,10 @@ jobs:
181193
# Install mbed_nicla platform via Boards Manager
182194
- name: arduino:mbed_nicla
183195
libraries: |
196+
- name: Blues Wireless Notecard
184197
sketch-paths: |
185198
- examples/ArduinoIoTCloud-DeferredOTA
199+
- examples/ArduinoIoTCloud-Notecard
186200
- examples/utility/Provisioning
187201
# Opta
188202
- board:
@@ -192,8 +206,10 @@ jobs:
192206
- name: arduino:mbed_opta
193207
libraries: |
194208
- name: ArduinoECCX08
209+
- name: Blues Wireless Notecard
195210
sketch-paths: |
196211
- examples/ArduinoIoTCloud-DeferredOTA
212+
- examples/ArduinoIoTCloud-Notecard
197213
- examples/utility/Provisioning
198214
# GIGA
199215
- board:
@@ -203,8 +219,10 @@ jobs:
203219
- name: arduino:mbed_giga
204220
libraries: |
205221
- name: ArduinoECCX08
222+
- name: Blues Wireless Notecard
206223
sketch-paths: |
207224
- examples/ArduinoIoTCloud-DeferredOTA
225+
- examples/ArduinoIoTCloud-Notecard
208226
- examples/utility/Provisioning
209227
# Portenta C33
210228
- board:
@@ -214,28 +232,41 @@ jobs:
214232
- name: arduino:renesas_portenta
215233
libraries: |
216234
- name: Arduino_Cellular
235+
- name: Blues Wireless Notecard
217236
sketch-paths: |
237+
- examples/ArduinoIoTCloud-Notecard
218238
- examples/utility/Provisioning
219239
# UNO R4 WiFi
220240
- board:
221241
type: renesas_uno
222242
platforms: |
223243
# Install renesas_uno platform via Boards Manager
224244
- name: arduino:renesas_uno
245+
libraries: |
246+
- name: Blues Wireless Notecard
247+
sketch-paths: |
248+
- examples/ArduinoIoTCloud-Notecard
225249
# Nano ESP32
226250
- board:
227251
type: arduino_esp32
228252
platforms: |
229253
# Install arduino_esp32 platform via Boards Manager
230254
- name: arduino:esp32
255+
libraries: |
256+
- name: Blues Wireless Notecard
231257
sketch-paths: |
232258
- examples/ArduinoIoTCloud-DeferredOTA
259+
- examples/ArduinoIoTCloud-Notecard
233260
# Edge Control
234261
- board:
235262
type: mbed_edge
236263
platforms: |
237264
# Install mbed_edge platform via Boards Manager
238265
- name: arduino:mbed_edge
266+
libraries: |
267+
- name: Blues Wireless Notecard
268+
sketch-paths: |
269+
- examples/ArduinoIoTCloud-Notecard
239270
# ESP8266 boards
240271
- board:
241272
type: esp8266
@@ -254,8 +285,11 @@ jobs:
254285
# Install ESP32 platform via Boards Manager
255286
- name: esp32:esp32
256287
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
288+
libraries: |
289+
- name: Blues Wireless Notecard
257290
sketch-paths: |
258291
- examples/ArduinoIoTCloud-DeferredOTA
292+
- examples/ArduinoIoTCloud-Notecard
259293
260294
steps:
261295
- name: Checkout

Diff for: README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The `ArduinoIoTCloud` library is the central element of the firmware enabling ce
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](examples/ArduinoIoTCloud-Notecard/README.md)
1819

1920
### How?
2021
1) Register your Arduino IoT Cloud capable board via [Arduino IoT Cloud](https://create.arduino.cc/iot) (Devices Section).
@@ -70,7 +71,7 @@ void onLedChange() {
7071

7172
### FAQ
7273
#### Watchdog
73-
The [1.0.0](https://github.com/arduino-libraries/ArduinoIoTCloud/releases/tag/1.0.0) release of this library adds watchdog functionality to all ATSAMD21G18 based cloud connected boards. A watchdog is simply an electronic timer counting down from a preset start value which, upon reaching zero, triggers a reset of the microcontroller. It can be used to automatically recover from temporary hardware faults or unrecoverable software errors. In order to avoid the watchdog from reaching zero the countdown timer needs to be regularly re-set to its start value. This is happening within `ArduinoCloud.update()` which is periodically called at the start of the `loop()` function. Although the watchdog is automatically enabled it can be disabled by setting the second parameter of `ArduinoCloud.begin(...)` to `false`:
74+
The [1.0.0](https://github.com/arduino-libraries/ArduinoIoTCloud/releases/tag/1.0.0) release of this library adds watchdog functionality to all ATSAMD21G18 based cloud connected boards. A watchdog is simply an electronic timer counting down from a preset start value which, upon reaching zero, triggers a reset of the microcontroller. It can be used to automatically recover from temporary hardware faults or unrecoverable software errors. In order to avoid the watchdog from reaching zero the countdown timer needs to be regularly re-set to its start value. This is happening within `ArduinoCloud.update()` which is periodically called at the start of the `loop()` function. Although the watchdog is automatically enabled it can be disabled by setting the second parameter of `ArduinoCloud.begin(...)` to `false`:
7475
```C++
7576
ArduinoCloud.begin(ArduinoIoTPreferredConnection, false).
7677
```
@@ -95,5 +96,3 @@ Boards can authenticate to the ArduinoIoTCloud servers using 3 methods:
9596
* `DEVICE_CERTIFICATE` and `PRIVATE_KEY`. This values are stored inside the board secure element during the device provisioning phase. Boards that are using this method are: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415), [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413), [`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), [`OPTA RS485`](https://store.arduino.cc/products/opta-rs485), [`OPTA Lite`](https://store.arduino.cc/products/opta-lite), [`GIGA R1 WiFi`](https://store.arduino.cc/products/giga-r1-wifi), [`Portenta C33`](https://store.arduino.cc/products/portenta-c33)
9697

9798
* `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)
98-
99-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
/* Set the debug message level:
35+
* - DBG_ERROR: Only show error messages
36+
* - DBG_WARNING: Show warning and error messages
37+
* - DBG_INFO: Show info, warning, and error messages
38+
* - DBG_DEBUG: Show debug, info, warning, and error messages
39+
* - DBG_VERBOSE: Show all messages
40+
*/
41+
setDebugMessageLevel(DBG_INFO);
42+
43+
/* Configure LED pin as an output */
44+
pinMode(LED_BUILTIN, OUTPUT);
45+
46+
/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
47+
initProperties();
48+
49+
/* Initialize Arduino IoT Cloud library */
50+
#ifndef ATTN_PIN
51+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
52+
ArduinoCloud.setNotecardPollingInterval(3000); // default: 1000ms, min: 250ms
53+
#else
54+
ArduinoCloud.begin(ArduinoIoTPreferredConnection, ATTN_PIN);
55+
#endif
56+
57+
ArduinoCloud.printDebugInfo();
58+
}
59+
60+
void loop() {
61+
ArduinoCloud.update();
62+
potentiometer = analogRead(A0);
63+
seconds = millis() / 1000;
64+
}
65+
66+
/*
67+
* 'onLedChange' is called when the "led" property of your Thing changes
68+
*/
69+
void onLedChange() {
70+
Serial.print("LED set to ");
71+
Serial.println(led);
72+
digitalWrite(LED_BUILTIN, led);
73+
}

Diff for: examples/ArduinoIoTCloud-Notecard/README.md

+78
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.

Diff for: examples/ArduinoIoTCloud-Notecard/arduino_secrets.h

+7
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"

Diff for: examples/ArduinoIoTCloud-Notecard/thingProperties.h

+36
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+
}

0 commit comments

Comments
 (0)