Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 41d60bb

Browse files
committedAug 23, 2024·
feat: ArduinoIoTCloudNotecard
1 parent cb933c6 commit 41d60bb

18 files changed

+931
-51
lines changed
 

‎.github/workflows/compile-examples.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ jobs:
2626
- name: Arduino_DebugUtils
2727
- name: ArduinoMqttClient
2828
- name: Arduino_SecureElement
29+
- name: Blues Wireless Notecard
2930
# sketch paths to compile (recursive) for all boards
3031
UNIVERSAL_SKETCH_PATHS: |
3132
- examples/ArduinoIoTCloud-Advanced
3233
- examples/ArduinoIoTCloud-Basic
3334
- examples/ArduinoIoTCloud-Callbacks
35+
- examples/ArduinoIoTCloud-Notecard
3436
- examples/ArduinoIoTCloud-Schedule
3537
- examples/utility/ArduinoIoTCloud_Travis_CI
3638
SKETCHES_REPORTS_PATH: sketches-reports

‎README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@
88
[![codecov](https://codecov.io/gh/arduino-libraries/ArduinoIoTCloud/branch/master/graph/badge.svg)](https://codecov.io/gh/arduino-libraries/ArduinoIoTCloud)
99

1010
### What?
11+
1112
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:
1213

1314
* **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)
1415
* **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415)
1516
* **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413)
1617
* **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310)
1718
* **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)
19+
* **Notecard**: [Provides Cellular/LoRa/Satellite/Wi-Fi to any modern board/architecture](examples/ArduinoIoTCloud-Notecard/README.md)
1820

1921
### How?
22+
2023
1) Register your Arduino IoT Cloud capable board via [Arduino IoT Cloud](https://create.arduino.cc/iot) (Devices Section).
2124
2) Create a new logical representation known as a [Thing](https://create.arduino.cc/iot/things).
2225

@@ -29,7 +32,9 @@ The `ArduinoIoTCloud` library is the central element of the firmware enabling ce
2932
- **Properties**: Qualities defining the characteristics of a system. A _Property_ can be defined as *read-only* (`READ`) to indicate that Arduino IoT Cloud can read the data, but cannot change the value of such _Property_. On the other end, it may be designated to be **read-and-write** (`READWRITE`), allowing Arduino IoT Cloud to remotely change the property’s value and trigger an event notification on the device. It is also possible to mark properties as *write-only* (`WRITE`) which means the cloud can write to this property but not read its value (this limits data transmission for properties which are used to trigger events only).
3033

3134
### How-to-use
35+
3236
* `thingProperties.h`
37+
3338
```C++
3439
void onLedChange();
3540
/* ... */
@@ -46,6 +51,7 @@ WiFiConnectionHandler ArduinoIoTPreferredConnection("SECRET_SSID", "SECRET_PASS"
4651
```
4752
4853
* `MyCloudApplication.ino`
54+
4955
```C++
5056
#include "thingProperties.h"
5157
@@ -69,31 +75,36 @@ void onLedChange() {
6975
```
7076

7177
### FAQ
78+
7279
#### 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`:
80+
81+
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`:
82+
7483
```C++
7584
ArduinoCloud.begin(ArduinoIoTPreferredConnection, false).
7685
```
7786

7887
Whatchdog is enabled by default using the following boards: [`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), [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310), [`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)
7988

8089
#### Device can not subscribe to `THING_ID`
90+
8191
```
8292
ArduinoIoTCloudTCP::handle_SubscribeMqttTopics could not subscribe to /a/t/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/e/i
8393
```
94+
8495
In this case either the device has not been associated with the thing within the Arduino IoT Cloud GUI configuration or there's a typo in the thing ID.
8596

8697
#### OTA
98+
8799
OTA is supported by the following boards:
88100
[`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), [`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), [`Nano ESP32`](https://store.arduino.cc/products/nano-esp32), [`ESP32`](https://github.com/espressif/arduino-esp32/releases/tag/2.0.5)
89101

90102
#### Authentication
103+
91104
Boards can authenticate to the ArduinoIoTCloud servers using 3 methods:
92105

93106
* `DEVICE_LOGIN_NAME` and `DEVICE_KEY`. This values are defined in the `thingProperties.h` file and included in the Sketch. Boards that are using this method are: [`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)
94107

95108
* `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)
96109

97110
* `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-
Lines changed: 73 additions & 0 deletions
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+
}
Lines changed: 78 additions & 0 deletions
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.
Lines changed: 7 additions & 0 deletions
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"
Lines changed: 36 additions & 0 deletions
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+
}

‎keywords.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ getThingId KEYWORD2
2525
setDeviceId KEYWORD2
2626
getDeviceId KEYWORD2
2727
getConnection KEYWORD2
28+
getInternalTime KEYWORD2
29+
getLocalTime KEYWORD2
2830
addCallback KEYWORD2
2931
addProperty KEYWORD2
3032

@@ -46,6 +48,14 @@ getBrokerPort KEYWORD2
4648
setOTAStorage KEYWORD2
4749
reconnect KEYWORD2
4850

51+
# ArduinoIoTCloudNotecard.h
52+
begin KEYWORD2
53+
setNotecardPollingInterval KEYWORD2
54+
55+
# OTA
56+
onOTARequestCallbackFunc KEYWORD2
57+
onOTARequestCb KEYWORD2
58+
4959
#######################################
5060
# Constants (LITERAL1)
5161
#######################################

‎library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ sentence=This library allows connecting to the Arduino IoT Cloud service.
66
paragraph=It provides a ConnectionManager to handle connection/disconnection, property-change updates and events callbacks. The supported boards are MKR GSM, MKR1000 and WiFi101.
77
category=Communication
88
url=https://github.com/arduino-libraries/ArduinoIoTCloud
9-
architectures=mbed,samd,esp8266,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_opta,mbed_giga,renesas_portenta,renesas_uno,mbed_edge
9+
architectures=mbed,samd,esp8266,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_opta,mbed_giga,renesas_portenta,renesas_uno,mbed_edge,stm32
1010
includes=ArduinoIoTCloud.h
1111
depends=Arduino_ConnectionHandler,Arduino_DebugUtils,Arduino_SecureElement,ArduinoMqttClient,ArduinoECCX08,RTCZero,Adafruit SleepyDog Library,ArduinoHttpClient

‎src/AIoTC_Config.h

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
#ifndef ARDUINO_AIOTC_CONFIG_H_
1919
#define ARDUINO_AIOTC_CONFIG_H_
2020

21+
#if defined __has_include
22+
#if __has_include (<Notecard.h>)
23+
#define HAS_NOTECARD
24+
#endif
25+
#endif
26+
2127
#include <ArduinoECCX08Config.h>
2228

2329
/******************************************************************************
@@ -52,6 +58,8 @@
5258
* AUTOMATICALLY CONFIGURED DEFINES
5359
******************************************************************************/
5460

61+
#if !defined(HAS_NOTECARD)
62+
5563
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
5664
#define OTA_STORAGE_SNU (1)
5765
#else
@@ -114,11 +122,6 @@
114122
#define HAS_TCP
115123
#endif
116124

117-
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_OPTA) || defined(ARDUINO_GIGA)
118-
#define BEAR_SSL_CLIENT_IBUF_SIZE (16384 + 325) // Allows download from storage API
119-
#define BOARD_STM32H7
120-
#endif
121-
122125
#if defined(ARDUINO_NANO_RP2040_CONNECT)
123126
#define BEAR_SSL_CLIENT_IBUF_SIZE (16384 + 325) // Allows download from storage API
124127
#endif
@@ -138,6 +141,13 @@
138141
#define BOARD_HAS_SECURE_ELEMENT
139142
#endif
140143

144+
#endif // HAS_NOTECARD
145+
146+
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_OPTA) || defined(ARDUINO_GIGA)
147+
#define BEAR_SSL_CLIENT_IBUF_SIZE (16384 + 325) // Allows download from storage API
148+
#define BOARD_STM32H7
149+
#endif
150+
141151
/******************************************************************************
142152
* CONSTANTS
143153
******************************************************************************/
@@ -146,16 +156,23 @@
146156
#define AIOT_CONFIG_LPWAN_UPDATE_RETRY_DELAY_ms (10000UL)
147157
#endif
148158

149-
#if defined(HAS_TCP)
159+
#if defined(HAS_NOTECARD) || defined(HAS_TCP)
150160
#define AIOT_CONFIG_RECONNECTION_RETRY_DELAY_ms (1000UL)
151161
#define AIOT_CONFIG_MAX_RECONNECTION_RETRY_DELAY_ms (32000UL)
152162

153-
#define AIOT_CONFIG_THING_ID_REQUEST_RETRY_DELAY_ms (2000UL)
154-
#define AIOT_CONFIG_MAX_THING_ID_REQUEST_RETRY_DELAY_ms (32000UL)
163+
#if defined(HAS_NOTECARD)
164+
// 10x the standard delays for Notecard
165+
#define AIOT_CONFIG_THING_ID_REQUEST_RETRY_DELAY_ms (20000UL)
166+
#define AIOT_CONFIG_MAX_THING_ID_REQUEST_RETRY_DELAY_ms (320000UL)
167+
#else
168+
#define AIOT_CONFIG_THING_ID_REQUEST_RETRY_DELAY_ms (2000UL)
169+
#define AIOT_CONFIG_MAX_THING_ID_REQUEST_RETRY_DELAY_ms (32000UL)
170+
#endif
171+
155172
#define AIOT_CONFIG_THING_ID_REQUEST_MAX_RETRY_CNT (10UL)
156173

157174
#define AIOT_CONFIG_DEVICE_REGISTERED_RETRY_DELAY_k (10UL)
158-
#define AIOT_CONFIG_MAX_DEVICE_REGISTERED_RETRY_DELAY_k (4UL)
175+
#define AIOT_CONFIG_MAX_DEVICE_REGISTERED_RETRY_DELAY_k (40UL)
159176

160177
#define AIOT_CONFIG_TIMEOUT_FOR_LASTVALUES_SYNC_ms (30000UL)
161178
#define AIOT_CONFIG_LASTVALUES_SYNC_MAX_RETRY_CNT (10UL)

‎src/ArduinoIoTCloud.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ class ArduinoIoTCloudClass
161161
OnCloudEventCallback _cloud_event_callback[3];
162162
};
163163

164-
#ifdef HAS_TCP
164+
#if defined(HAS_NOTECARD)
165+
#include "ArduinoIoTCloudNotecard.h"
166+
#elif defined(HAS_TCP)
165167
#include "ArduinoIoTCloudTCP.h"
166168
#elif defined(HAS_LORA)
167169
#include "ArduinoIoTCloudLPWAN.h"

‎src/ArduinoIoTCloudDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include <AIoTC_Config.h>
1616

17-
#ifdef HAS_TCP
17+
#if defined(HAS_NOTECARD) || defined(HAS_TCP)
1818

1919
#include "ArduinoIoTCloudDevice.h"
2020
#include "interfaces/CloudProcess.h"
@@ -146,4 +146,4 @@ ArduinoCloudDevice::State ArduinoCloudDevice::handleDisconnected() {
146146
return State::Disconnected;
147147
}
148148

149-
#endif /* HAS_TCP */
149+
#endif /* HAS_NOTECARD || HAS_TCP */

‎src/ArduinoIoTCloudNotecard.cpp

Lines changed: 481 additions & 0 deletions
Large diffs are not rendered by default.

‎src/ArduinoIoTCloudNotecard.h

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
This file is part of the ArduinoIoTCloud library.
3+
4+
Copyright 2024 Blues (http://www.blues.com/)
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#ifndef ARDUINO_IOT_CLOUD_NOTECARD_H
12+
#define ARDUINO_IOT_CLOUD_NOTECARD_H
13+
14+
/******************************************************************************
15+
* INCLUDE
16+
******************************************************************************/
17+
18+
#include "ArduinoIoTCloud.h"
19+
#include "ArduinoIoTCloudThing.h"
20+
#include "ArduinoIoTCloudDevice.h"
21+
22+
/******************************************************************************
23+
* DEFINES
24+
******************************************************************************/
25+
26+
#define USE_LIGHT_PAYLOADS (false)
27+
28+
/******************************************************************************
29+
* CONSTANTS
30+
******************************************************************************/
31+
32+
/******************************************************************************
33+
* TYPEDEF
34+
******************************************************************************/
35+
36+
/******************************************************************************
37+
* CLASS DECLARATION
38+
******************************************************************************/
39+
40+
/**
41+
* @brief The ArduinoIoTCloudNotecard class
42+
*
43+
* This class is used to connect to the Arduino IoT Cloud using a Notecard.
44+
*/
45+
class ArduinoIoTCloudNotecard : public ArduinoIoTCloudClass
46+
{
47+
public:
48+
ArduinoIoTCloudNotecard();
49+
virtual ~ArduinoIoTCloudNotecard() { }
50+
51+
virtual void update () override;
52+
virtual int connected () override;
53+
virtual void printDebugInfo() override;
54+
55+
/**
56+
* @brief Begin the connection to the Arduino IoT Cloud.
57+
*
58+
* @param connection The connection handler to use.
59+
* @param interrupt_pin The interrupt pin to use for the Notecard.
60+
*
61+
* @note The interrupt pin is optional and only required if you want to
62+
* eliminate the need to poll the Notecard for new data. The pin only needs
63+
* to be specified, and will otherwise be configured by the library.
64+
*
65+
* @return 1 on success, 0 on failure.
66+
*/
67+
int begin(ConnectionHandler &connection, int interrupt_pin = -1);
68+
69+
/**
70+
* @brief Set the Notecard polling interval.
71+
*
72+
* The interval at which the Notecard is polled (via I2C/UART) for new data.
73+
* This is not a network transaction, but a local polling of the Notecard.
74+
*
75+
* @param interval_ms The interval in milliseconds.
76+
* @par
77+
* - Minimum: 250ms
78+
* - Default: 1000ms
79+
*
80+
* @note The Notecard poll interval is ignored if an interrupt pin is
81+
* provided to the `begin()` function.
82+
*/
83+
inline void setNotecardPollingInterval(uint32_t interval_ms) { _notecard_polling_interval_ms = ((interval_ms < 250) ? 250 : interval_ms); }
84+
85+
private:
86+
87+
enum class State
88+
{
89+
ConnectPhy,
90+
SyncTime,
91+
Connected,
92+
Disconnect,
93+
};
94+
95+
State _state;
96+
TimedAttempt _connection_attempt;
97+
MessageStream _message_stream;
98+
ArduinoCloudThing _thing;
99+
ArduinoCloudDevice _device;
100+
101+
// Notecard member variables
102+
uint32_t _notecard_last_poll_ms;
103+
uint32_t _notecard_polling_interval_ms;
104+
int _interrupt_pin;
105+
volatile bool _data_available;
106+
107+
inline virtual PropertyContainer &getThingPropertyContainer() override { return _thing.getPropertyContainer(); }
108+
109+
State handle_ConnectPhy();
110+
State handle_SyncTime();
111+
State handle_Connected();
112+
State handle_Disconnect();
113+
114+
void attachThing(String thingId);
115+
bool available (void);
116+
void detachThing();
117+
void fetchIncomingBytes(uint8_t *buf, size_t &len);
118+
void pollNotecard(void);
119+
void processCommand(const uint8_t *buf, size_t len);
120+
void processMessage(const uint8_t *buf, size_t len);
121+
void sendMessage(Message * msg);
122+
void sendCommandMsgToCloud(Message * msg_);
123+
void sendThingPropertyContainerToCloud(void);
124+
125+
friend void ISR_dataAvailable (void);
126+
};
127+
128+
/******************************************************************************
129+
* EXTERN DECLARATION
130+
******************************************************************************/
131+
132+
extern ArduinoIoTCloudNotecard ArduinoCloud;
133+
134+
#endif // ARDUINO_IOT_CLOUD_NOTECARD_H

‎src/ArduinoIoTCloudThing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include <AIoTC_Config.h>
1717

18-
#ifdef HAS_TCP
18+
#if defined(HAS_NOTECARD) || defined(HAS_TCP)
1919

2020
#include "ArduinoIoTCloudThing.h"
2121
#include "interfaces/CloudProcess.h"
@@ -180,4 +180,4 @@ ArduinoCloudThing::State ArduinoCloudThing::handleDisconnect() {
180180
return State::Disconnect;
181181
}
182182

183-
#endif /* HAS_TCP */
183+
#endif /* HAS_NOTECARD || HAS_TCP */

‎src/utility/time/RTCMillis.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
a commercial license, send an email to license@arduino.cc.
1616
*/
1717

18-
#ifdef ARDUINO_ARCH_ESP8266
19-
2018
/**************************************************************************************
2119
* INCLUDE
2220
**************************************************************************************/
2321

22+
#include "AIoTC_Config.h"
23+
24+
#if defined(HAS_NOTECARD) || defined(ARDUINO_ARCH_ESP8266)
25+
2426
#include <Arduino.h>
2527
#include "RTCMillis.h"
2628

@@ -59,4 +61,4 @@ unsigned long RTCMillis::get()
5961
return _last_rtc_update_value;
6062
}
6163

62-
#endif /* ARDUINO_ARCH_ESP8266 */
64+
#endif /* HAS_NOTECARD || ARDUINO_ARCH_ESP8266 */

‎src/utility/time/RTCMillis.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#ifndef ARDUINO_IOT_CLOUD_RTC_MILLIS_H_
1919
#define ARDUINO_IOT_CLOUD_RTC_MILLIS_H_
2020

21-
#ifdef ARDUINO_ARCH_ESP8266
21+
#if defined(HAS_NOTECARD) || defined(ARDUINO_ARCH_ESP8266)
2222

2323
/**************************************************************************************
2424
* INCLUDE
@@ -45,6 +45,6 @@ class RTCMillis
4545

4646
};
4747

48-
#endif /* ARDUINO_ARCH_ESP8266 */
48+
#endif /* HAS_NOTECARD || ARDUINO_ARCH_ESP8266 */
4949

5050
#endif /* ARDUINO_IOT_CLOUD_RTC_MILLIS_H_ */

‎src/utility/time/TimeService.cpp

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,32 @@
1919
* INCLUDE
2020
**************************************************************************************/
2121

22-
#include <AIoTC_Config.h>
2322

2423
#include <time.h>
25-
#include "TimeService.h"
26-
#include "NTPUtils.h"
24+
25+
#include "AIoTC_Config.h"
2726
#include "AIoTC_Const.h"
27+
#include "NTPUtils.h"
28+
#include "TimeService.h"
2829

29-
#ifdef ARDUINO_ARCH_SAMD
30+
#if defined(HAS_NOTECARD) || defined(ARDUINO_ARCH_ESP8266)
31+
#include "RTCMillis.h"
32+
#elif defined(ARDUINO_ARCH_SAMD)
3033
#include <RTCZero.h>
31-
#endif
32-
33-
#ifdef ARDUINO_ARCH_MBED
34+
#elif defined(ARDUINO_ARCH_MBED)
3435
#include <mbed_rtc_time.h>
35-
#endif
36-
37-
#ifdef ARDUINO_ARCH_ESP8266
38-
#include "RTCMillis.h"
39-
#endif
40-
41-
#ifdef ARDUINO_ARCH_RENESAS
36+
#elif defined(ARDUINO_ARCH_RENESAS)
4237
#include "RTC.h"
4338
#endif
4439

4540
/**************************************************************************************
4641
* GLOBAL VARIABLES
4742
**************************************************************************************/
4843

49-
#ifdef ARDUINO_ARCH_SAMD
50-
RTCZero rtc;
51-
#endif
52-
53-
#ifdef ARDUINO_ARCH_ESP8266
44+
#if defined(HAS_NOTECARD) || defined(ARDUINO_ARCH_ESP8266)
5445
RTCMillis rtc;
46+
#elif defined(ARDUINO_ARCH_SAMD)
47+
RTCZero rtc;
5548
#endif
5649

5750
/**************************************************************************************
@@ -60,6 +53,12 @@ RTCMillis rtc;
6053

6154
time_t cvt_time(char const * time);
6255

56+
#if defined(HAS_NOTECARD)
57+
void notecard_initRTC();
58+
void notecard_setRTC(unsigned long time);
59+
unsigned long notecard_getRTC();
60+
#else
61+
6362
#ifdef ARDUINO_ARCH_SAMD
6463
void samd_initRTC();
6564
void samd_setRTC(unsigned long time);
@@ -90,6 +89,8 @@ void renesas_setRTC(unsigned long time);
9089
unsigned long renesas_getRTC();
9190
#endif
9291

92+
#endif /* HAS_NOTECARD */
93+
9394
/**************************************************************************************
9495
* DEFINES
9596
**************************************************************************************/
@@ -161,10 +162,9 @@ bool TimeServiceClass::sync()
161162
if(_sync_func) {
162163
utc = _sync_func();
163164
} else {
164-
#ifdef HAS_TCP
165+
#if defined(HAS_NOTECARD) || defined(HAS_TCP)
165166
utc = getRemoteTime();
166-
#endif
167-
#ifdef HAS_LORA
167+
#elif defined(HAS_LORA)
168168
/* Just keep incrementing stored RTC value*/
169169
utc = getRTC();
170170
#endif
@@ -275,7 +275,7 @@ unsigned long TimeServiceClass::getTimeFromString(const String& input)
275275
* PRIVATE MEMBER FUNCTIONS
276276
**************************************************************************************/
277277

278-
#ifdef HAS_TCP
278+
#if defined(HAS_NOTECARD) || defined(HAS_TCP)
279279
bool TimeServiceClass::connected()
280280
{
281281
if(_con_hdl == nullptr) {
@@ -288,6 +288,7 @@ bool TimeServiceClass::connected()
288288
unsigned long TimeServiceClass::getRemoteTime()
289289
{
290290
if(connected()) {
291+
#ifdef HAS_TCP
291292
/* At first try to obtain a valid time via NTP.
292293
* This is the most reliable time source and it will
293294
* ensure a correct behaviour of the library.
@@ -298,6 +299,7 @@ unsigned long TimeServiceClass::getRemoteTime()
298299
return ntp_time;
299300
}
300301
}
302+
#endif /* HAS_TCP */
301303

302304
/* As fallback if NTP request fails try to obtain the
303305
* network time using the connection handler.
@@ -316,7 +318,7 @@ unsigned long TimeServiceClass::getRemoteTime()
316318
return EPOCH_AT_COMPILE_TIME;
317319
}
318320

319-
#endif /* HAS_TCP */
321+
#endif /* HAS_NOTECARD || HAS_TCP */
320322

321323
bool TimeServiceClass::isTimeValid(unsigned long const time)
322324
{
@@ -331,7 +333,9 @@ bool TimeServiceClass::isTimeZoneOffsetValid(long const offset)
331333

332334
void TimeServiceClass::initRTC()
333335
{
334-
#if defined (ARDUINO_ARCH_SAMD)
336+
#if defined (HAS_NOTECARD)
337+
notecard_initRTC();
338+
#elif defined (ARDUINO_ARCH_SAMD)
335339
samd_initRTC();
336340
#elif defined (ARDUINO_ARCH_MBED)
337341
mbed_initRTC();
@@ -348,7 +352,9 @@ void TimeServiceClass::initRTC()
348352

349353
void TimeServiceClass::setRTC(unsigned long time)
350354
{
351-
#if defined (ARDUINO_ARCH_SAMD)
355+
#if defined (HAS_NOTECARD)
356+
notecard_setRTC(time);
357+
#elif defined (ARDUINO_ARCH_SAMD)
352358
samd_setRTC(time);
353359
#elif defined (ARDUINO_ARCH_MBED)
354360
mbed_setRTC(time);
@@ -365,7 +371,9 @@ void TimeServiceClass::setRTC(unsigned long time)
365371

366372
unsigned long TimeServiceClass::getRTC()
367373
{
368-
#if defined (ARDUINO_ARCH_SAMD)
374+
#if defined (HAS_NOTECARD)
375+
return notecard_getRTC();
376+
#elif defined (ARDUINO_ARCH_SAMD)
369377
return samd_getRTC();
370378
#elif defined (ARDUINO_ARCH_MBED)
371379
return mbed_getRTC();
@@ -420,6 +428,23 @@ time_t cvt_time(char const * time)
420428
return build_time;
421429
}
422430

431+
#ifdef HAS_NOTECARD
432+
void notecard_initRTC()
433+
{
434+
rtc.begin();
435+
}
436+
437+
void notecard_setRTC(unsigned long time)
438+
{
439+
rtc.set(time);
440+
}
441+
442+
unsigned long notecard_getRTC()
443+
{
444+
return rtc.get();
445+
}
446+
#else
447+
423448
#ifdef ARDUINO_ARCH_SAMD
424449
void samd_initRTC()
425450
{
@@ -509,6 +534,8 @@ unsigned long renesas_getRTC()
509534
}
510535
#endif
511536

537+
#endif /* HAS_NOTECARD */
538+
512539
/******************************************************************************
513540
* EXTERN DEFINITION
514541
******************************************************************************/

‎src/utility/time/TimeService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class TimeServiceClass
6969
unsigned long _sync_interval_ms;
7070
syncTimeFunctionPtr _sync_func;
7171

72-
#ifdef HAS_TCP
72+
#if defined(HAS_NOTECARD) || defined(HAS_TCP)
7373
unsigned long getRemoteTime();
7474
bool connected();
7575
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.