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 f0379ca

Browse files
committedJul 20, 2024·
feat: Notecard for ArduinoIoTCloud
1 parent 8b6ff40 commit f0379ca

20 files changed

+830
-48
lines changed
 

‎examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This sketch demonstrates how to use more complex cloud data types such as a colour or coordinates.
33
44
IMPORTANT:
5-
This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
5+
This sketch works with Notecard, WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
66
On a LoRa board, if it is configured as a class A device (default and preferred option),
77
values from Cloud dashboard are received only after a value is sent to Cloud.
88

‎examples/ArduinoIoTCloud-Advanced/thingProperties.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <Arduino_ConnectionHandler.h>
33
#include "arduino_secrets.h"
44

5-
#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \
5+
#if !(defined(USE_NOTECARD) || defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \
66
defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT))
77
#error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
88
#endif
@@ -11,6 +11,14 @@
1111
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1212
#endif
1313

14+
#if defined(USE_NOTECARD)
15+
/* The Notecard can provide connectivity to almost any board via ESLOV (I2C)
16+
* or UART. An empty string (or the default value provided below) will not
17+
* override the Notecard's existing configuration.
18+
* Learn more at: https://dev.blues.io */
19+
#define NOTECARD_PRODUCT_UID "com.domain.you:product"
20+
#endif
21+
1422
void onSwitchButtonChange();
1523
void onColorChange();
1624

@@ -23,7 +31,7 @@ void initProperties() {
2331
ArduinoCloud.setBoardId(BOARD_ID);
2432
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
2533
#endif
26-
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)
34+
#if defined(USE_NOTECARD) || defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)
2735
ArduinoCloud.addProperty(switchButton, Permission::Write).onUpdate(onSwitchButtonChange);
2836
ArduinoCloud.addProperty(location, Permission::Read).publishOnChange(0.0f);
2937
ArduinoCloud.addProperty(color, Permission::ReadWrite).onUpdate(onColorChange);
@@ -34,7 +42,9 @@ void initProperties() {
3442
#endif
3543
}
3644

37-
#if defined(BOARD_HAS_WIFI)
45+
#if defined(USE_NOTECARD)
46+
NotecardConnectionHandler ArduinoIoTPreferredConnection(NOTECARD_PRODUCT_UID);
47+
#elif defined(BOARD_HAS_WIFI)
3848
WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
3949
#elif defined(BOARD_HAS_GSM)
4050
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);

‎examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF.
77
88
IMPORTANT:
9-
This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
9+
This sketch works with Notecard, WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
1010
On a LoRa board, if it is configured as a class A device (default and preferred option),
1111
values from Cloud dashboard are received only after a value is sent to Cloud.
1212

‎examples/ArduinoIoTCloud-Basic/thingProperties.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <Arduino_ConnectionHandler.h>
33
#include "arduino_secrets.h"
44

5-
#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \
5+
#if !(defined(USE_NOTECARD) || defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \
66
defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT))
77
#error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
88
#endif
@@ -11,6 +11,14 @@
1111
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1212
#endif
1313

14+
#if defined(USE_NOTECARD)
15+
/* The Notecard can provide connectivity to almost any board via ESLOV (I2C)
16+
* or UART. An empty string (or the default value provided below) will not
17+
* override the Notecard's existing configuration.
18+
* Learn more at: https://dev.blues.io */
19+
#define NOTECARD_PRODUCT_UID "com.domain.you:product"
20+
#endif
21+
1422
void onLedChange();
1523

1624
bool led;
@@ -26,14 +34,16 @@ void initProperties() {
2634
ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
2735
ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
2836
ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);
29-
#elif defined(BOARD_HAS_LORA)
37+
#elif defined(USE_NOTECARD) || defined(BOARD_HAS_LORA)
3038
ArduinoCloud.addProperty(led, 1, Permission::ReadWrite).onUpdate(onLedChange);
3139
ArduinoCloud.addProperty(potentiometer, 2, Permission::Read).publishOnChange(10);
3240
ArduinoCloud.addProperty(seconds, 3, Permission::Read).publishEvery(5 * MINUTES);
3341
#endif
3442
}
3543

36-
#if defined(BOARD_HAS_ETHERNET)
44+
#if defined(USE_NOTECARD)
45+
NotecardConnectionHandler ArduinoIoTPreferredConnection(NOTECARD_PRODUCT_UID);
46+
#elif defined(BOARD_HAS_ETHERNET)
3747
/* DHCP mode */
3848
//EthernetConnectionHandler ArduinoIoTPreferredConnection;
3949
/* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */

‎examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
One function per event can be assigned.
1919
2020
IMPORTANT:
21-
This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
21+
This sketch works with Notecard, WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
2222
On a LoRa board, if it is configured as a class A device (default and preferred option),
2323
values from Cloud dashboard are received only after a value is sent to Cloud.
2424

‎examples/ArduinoIoTCloud-Callbacks/thingProperties.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <Arduino_ConnectionHandler.h>
33
#include "arduino_secrets.h"
44

5-
#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \
5+
#if !(defined(USE_NOTECARD) || defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \
66
defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT))
77
#error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
88
#endif
@@ -11,14 +11,24 @@
1111
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1212
#endif
1313

14+
#if defined(USE_NOTECARD)
15+
/* The Notecard can provide connectivity to almost any board via ESLOV (I2C)
16+
* or UART. An empty string (or the default value provided below) will not
17+
* override the Notecard's existing configuration.
18+
* Learn more at: https://dev.blues.io */
19+
#define NOTECARD_PRODUCT_UID "com.domain.you:product"
20+
#endif
21+
1422
void initProperties() {
1523
#if defined(BOARD_HAS_SECRET_KEY)
1624
ArduinoCloud.setBoardId(BOARD_ID);
1725
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
1826
#endif
1927
}
2028

21-
#if defined(BOARD_HAS_WIFI)
29+
#if defined(USE_NOTECARD)
30+
NotecardConnectionHandler ArduinoIoTPreferredConnection(NOTECARD_PRODUCT_UID);
31+
#elif defined(BOARD_HAS_WIFI)
2232
WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
2333
#elif defined(BOARD_HAS_GSM)
2434
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);

‎examples/ArduinoIoTCloud-Schedule/ArduinoIoTCloud-Schedule.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This sketch demonstrates how to use the cloud schedule variable type.
33
44
IMPORTANT:
5-
This sketch works with WiFi, GSM, NB and Ethernet enabled boards supported by Arduino IoT Cloud.
5+
This sketch works with Notecard, WiFi, GSM, NB and Ethernet enabled boards supported by Arduino IoT Cloud.
66
77
*/
88

‎examples/ArduinoIoTCloud-Schedule/thingProperties.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <Arduino_ConnectionHandler.h>
33
#include "arduino_secrets.h"
44

5-
#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \
5+
#if !(defined(USE_NOTECARD) || defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \
66
defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT))
77
#error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
88
#endif
@@ -11,6 +11,14 @@
1111
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1212
#endif
1313

14+
#if defined(USE_NOTECARD)
15+
/* The Notecard can provide connectivity to almost any board via ESLOV (I2C)
16+
* or UART. An empty string (or the default value provided below) will not
17+
* override the Notecard's existing configuration.
18+
* Learn more at: https://dev.blues.io */
19+
#define NOTECARD_PRODUCT_UID "com.domain.you:product"
20+
#endif
21+
1422
void onSwitchButtonChange();
1523

1624
bool switchButton;
@@ -27,7 +35,7 @@ void initProperties() {
2735
ArduinoCloud.setBoardId(BOARD_ID);
2836
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
2937
#endif
30-
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)
38+
#if defined(USE_NOTECARD) || defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)
3139
ArduinoCloud.addProperty(switchButton, Permission::Write);
3240
ArduinoCloud.addProperty(oneShot, Permission::ReadWrite);
3341
ArduinoCloud.addProperty(minute, Permission::ReadWrite);
@@ -41,7 +49,9 @@ void initProperties() {
4149
#endif
4250
}
4351

44-
#if defined(BOARD_HAS_WIFI)
52+
#if defined(USE_NOTECARD)
53+
NotecardConnectionHandler ArduinoIoTPreferredConnection(NOTECARD_PRODUCT_UID);
54+
#elif defined(BOARD_HAS_WIFI)
4555
WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
4656
#elif defined(BOARD_HAS_GSM)
4757
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);

‎examples/utility/ArduinoIoTCloud_Travis_CI/ArduinoIoTCloud_Travis_CI.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Arduino IoT Cloud API.
55
66
IMPORTANT:
7-
This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
7+
This sketch works with Notecard, WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
88
On a LoRa board, if it is configured as a class A device (default and preferred option),
99
values from Cloud dashboard are received only after a value is sent to Cloud.
1010

‎examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <Arduino_ConnectionHandler.h>
33
#include "arduino_secrets.h"
44

5-
#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \
5+
#if !(defined(USE_NOTECARD) || defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \
66
defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT))
77
#error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
88
#endif
@@ -19,6 +19,14 @@
1919
#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
2020
#endif
2121

22+
#if defined(USE_NOTECARD)
23+
/* The Notecard can provide connectivity to almost any board via ESLOV (I2C)
24+
* or UART. An empty string (or the default value provided below) will not
25+
* override the Notecard's existing configuration.
26+
* Learn more at: https://dev.blues.io */
27+
#define NOTECARD_PRODUCT_UID "com.domain.you:product"
28+
#endif
29+
2230
/******************************************************************************
2331
GLOBAL CONSTANTS
2432
******************************************************************************/
@@ -54,7 +62,9 @@ String str_property_6;
5462
String str_property_7;
5563
String str_property_8;
5664

57-
#if defined(BOARD_HAS_WIFI)
65+
#if defined(USE_NOTECARD)
66+
NotecardConnectionHandler ArduinoIoTPreferredConnection(NOTECARD_PRODUCT_UID);
67+
#elif defined(BOARD_HAS_WIFI)
5868
WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
5969
#elif defined(BOARD_HAS_GSM)
6070
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
@@ -83,7 +93,7 @@ void onStringPropertyChange();
8393
/******************************************************************************
8494
FUNCTIONS
8595
******************************************************************************/
86-
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined (BOARD_HAS_NB) || defined (BOARD_HAS_CATM1_NBIOT)
96+
#if defined(USE_NOTECARD) || defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined (BOARD_HAS_NB) || defined (BOARD_HAS_CATM1_NBIOT)
8797
void initProperties() {
8898
#if defined(BOARD_HAS_SECRET_KEY)
8999
ArduinoCloud.setBoardId(BOARD_ID);

‎src/AIoTC_Config.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
* AUTOMATICALLY CONFIGURED DEFINES
5353
******************************************************************************/
5454

55+
#if !defined(USE_NOTECARD)
56+
5557
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
5658
#define OTA_STORAGE_SNU (1)
5759
#else
@@ -114,11 +116,6 @@
114116
#define HAS_TCP
115117
#endif
116118

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-
122119
#if defined(ARDUINO_NANO_RP2040_CONNECT)
123120
#define BEAR_SSL_CLIENT_IBUF_SIZE (16384 + 325) // Allows download from storage API
124121
#endif
@@ -138,6 +135,13 @@
138135
#define BOARD_HAS_SECURE_ELEMENT
139136
#endif
140137

138+
#endif // USE_NOTECARD
139+
140+
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_OPTA) || defined(ARDUINO_GIGA)
141+
#define BEAR_SSL_CLIENT_IBUF_SIZE (16384 + 325) // Allows download from storage API
142+
#define BOARD_STM32H7
143+
#endif
144+
141145
/******************************************************************************
142146
* CONSTANTS
143147
******************************************************************************/

‎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(USE_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(USE_NOTECARD) || defined(HAS_TCP)
1818

1919
#include "ArduinoIoTCloudDevice.h"
2020
#include "interfaces/CloudProcess.h"
@@ -142,4 +142,4 @@ ArduinoCloudDevice::State ArduinoCloudDevice::handleDisconnected() {
142142
return State::Disconnected;
143143
}
144144

145-
#endif /* HAS_TCP */
145+
#endif /* USE_NOTECARD || HAS_TCP */

‎src/ArduinoIoTCloudNotecard.cpp

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

‎src/ArduinoIoTCloudNotecard.h

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
This file is part of ArduinoIoTCloud.
3+
4+
Copyright 2024 Blues (http://www.blues.com/)
5+
6+
This software is released under the GNU General Public License version 3,
7+
which covers the main part of arduino-cli.
8+
The terms of this license can be found at:
9+
https://www.gnu.org/licenses/gpl-3.0.en.html
10+
11+
You can be released from the requirements of the above licenses by purchasing
12+
a commercial license. Buying such a license is mandatory if you want to
13+
modify or otherwise use the software for commercial activities involving the
14+
Arduino software without disclosing the source code of your own applications.
15+
To purchase a commercial license, send an email to license@arduino.cc.
16+
*/
17+
18+
#ifndef ARDUINO_IOT_CLOUD_NOTECARD_H
19+
#define ARDUINO_IOT_CLOUD_NOTECARD_H
20+
21+
/******************************************************************************
22+
* INCLUDE
23+
******************************************************************************/
24+
25+
#include "ArduinoIoTCloud.h"
26+
#include "ArduinoIoTCloudThing.h"
27+
#include "ArduinoIoTCloudDevice.h"
28+
29+
/******************************************************************************
30+
* DEFINES
31+
******************************************************************************/
32+
33+
#define USE_LIGHT_PAYLOADS (false)
34+
35+
/******************************************************************************
36+
* CONSTANTS
37+
******************************************************************************/
38+
39+
/******************************************************************************
40+
* TYPEDEF
41+
******************************************************************************/
42+
43+
#if OTA_ENABLED
44+
typedef bool (*onOTARequestCallbackFunc)(void);
45+
#endif /* OTA_ENABLED */
46+
47+
/******************************************************************************
48+
* CLASS DECLARATION
49+
******************************************************************************/
50+
51+
class ArduinoIoTCloudNotecard : public ArduinoIoTCloudClass
52+
{
53+
public:
54+
ArduinoIoTCloudNotecard();
55+
virtual ~ArduinoIoTCloudNotecard() { }
56+
57+
virtual void update () override;
58+
virtual int connected () override;
59+
virtual void printDebugInfo() override;
60+
inline virtual PropertyContainer &getThingPropertyContainer() override { return _thing.getPropertyContainer(); }
61+
62+
int begin(ConnectionHandler &connection, int interrupt_pin = -1);
63+
64+
#ifdef BOARD_HAS_SECRET_KEY
65+
inline void setBoardId (String const & device_id) { (_connection && (NetworkConnectionState::INIT != _connection->check())) ? setDeviceId(reinterpret_cast<NotecardConnectionHandler *>(_connection)->syncArduinoDeviceId(device_id)) : setDeviceId(device_id); }
66+
inline void setSecretDeviceKey(String const & secret_device_key) { _secret_device_key = secret_device_key; }
67+
#endif
68+
69+
private:
70+
71+
enum class State
72+
{
73+
ConnectPhy,
74+
SyncTime,
75+
ConfigureNotehub,
76+
Connected,
77+
Disconnect,
78+
};
79+
80+
State _state;
81+
TimedAttempt _connection_attempt;
82+
MessageStream _message_stream;
83+
ArduinoCloudThing _thing;
84+
ArduinoCloudDevice _device;
85+
86+
// Notecard member variables
87+
uint32_t _last_poll_ms;
88+
int _interrupt_pin;
89+
volatile bool _data_available;
90+
91+
#ifdef BOARD_HAS_SECRET_KEY
92+
String _secret_device_key;
93+
#endif
94+
95+
#if OTA_ENABLED
96+
// OTA member variables
97+
bool _ota_cap;
98+
int _ota_error;
99+
String _ota_img_sha256;
100+
String _ota_url;
101+
bool _ota_req;
102+
bool _ask_user_before_executing_ota;
103+
onOTARequestCallbackFunc _get_ota_confirmation;
104+
#endif /* OTA_ENABLED */
105+
106+
State handle_ConnectPhy();
107+
State handle_SyncTime();
108+
State handle_ConfigureNotehub();
109+
State handle_Connected();
110+
State handle_Disconnect();
111+
112+
void attachThing(String thingId);
113+
bool available (void);
114+
#if OTA_ENABLED
115+
void checkOTARequest(void);
116+
#endif /* OTA_ENABLED */
117+
void detachThing();
118+
void fetchIncomingBytes(uint8_t *buf, size_t &len);
119+
void pollNotecard(void);
120+
void processCommand(const uint8_t *buf, size_t len);
121+
void processMessage(const uint8_t *buf, size_t len);
122+
void requestThingIdFromNotehub(void);
123+
void sendMessage(Message * msg);
124+
void sendCommandMsgToCloud(Message * msg_);
125+
void sendThingPropertyContainerToCloud(void);
126+
127+
friend void ISR_dataAvailable (void);
128+
};
129+
130+
/******************************************************************************
131+
* EXTERN DECLARATION
132+
******************************************************************************/
133+
134+
extern ArduinoIoTCloudNotecard ArduinoCloud;
135+
136+
#endif

‎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(USE_NOTECARD) || defined(HAS_TCP)
1919

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

181-
#endif /* HAS_TCP */
181+
#endif /* USE_NOTECARD || HAS_TCP */

‎src/utility/time/RTCMillis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
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+
#if defined(USE_NOTECARD) || defined(ARDUINO_ARCH_ESP8266)
23+
2424
#include <Arduino.h>
2525
#include "RTCMillis.h"
2626

@@ -59,4 +59,4 @@ unsigned long RTCMillis::get()
5959
return _last_rtc_update_value;
6060
}
6161

62-
#endif /* ARDUINO_ARCH_ESP8266 */
62+
#endif /* USE_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(USE_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 /* USE_NOTECARD || ARDUINO_ARCH_ESP8266 */
4949

5050
#endif /* ARDUINO_IOT_CLOUD_RTC_MILLIS_H_ */

‎src/utility/time/TimeService.cpp

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#include "NTPUtils.h"
2727
#include "AIoTC_Const.h"
2828

29+
#ifdef USE_NOTECARD
30+
#include "RTCMillis.h"
31+
#else
32+
2933
#ifdef ARDUINO_ARCH_SAMD
3034
#include <RTCZero.h>
3135
#endif
@@ -42,16 +46,16 @@
4246
#include "RTC.h"
4347
#endif
4448

49+
#endif /* USE_NOTECARD */
50+
4551
/**************************************************************************************
4652
* GLOBAL VARIABLES
4753
**************************************************************************************/
4854

49-
#ifdef ARDUINO_ARCH_SAMD
50-
RTCZero rtc;
51-
#endif
52-
53-
#ifdef ARDUINO_ARCH_ESP8266
55+
#if defined(USE_NOTECARD) || defined(ARDUINO_ARCH_ESP8266)
5456
RTCMillis rtc;
57+
#elif defined(ARDUINO_ARCH_SAMD)
58+
RTCZero rtc;
5559
#endif
5660

5761
/**************************************************************************************
@@ -60,6 +64,12 @@ RTCMillis rtc;
6064

6165
time_t cvt_time(char const * time);
6266

67+
#if defined(USE_NOTECARD)
68+
void notecard_initRTC();
69+
void notecard_setRTC(unsigned long time);
70+
unsigned long notecard_getRTC();
71+
#else
72+
6373
#ifdef ARDUINO_ARCH_SAMD
6474
void samd_initRTC();
6575
void samd_setRTC(unsigned long time);
@@ -90,6 +100,8 @@ void renesas_setRTC(unsigned long time);
90100
unsigned long renesas_getRTC();
91101
#endif
92102

103+
#endif /* USE_NOTECARD */
104+
93105
/**************************************************************************************
94106
* DEFINES
95107
**************************************************************************************/
@@ -161,10 +173,9 @@ bool TimeServiceClass::sync()
161173
if(_sync_func) {
162174
utc = _sync_func();
163175
} else {
164-
#ifdef HAS_TCP
176+
#if defined(USE_NOTECARD) || defined(HAS_TCP)
165177
utc = getRemoteTime();
166-
#endif
167-
#ifdef HAS_LORA
178+
#elif defined(HAS_LORA)
168179
/* Just keep incrementing stored RTC value*/
169180
utc = getRTC();
170181
#endif
@@ -275,7 +286,7 @@ unsigned long TimeServiceClass::getTimeFromString(const String& input)
275286
* PRIVATE MEMBER FUNCTIONS
276287
**************************************************************************************/
277288

278-
#ifdef HAS_TCP
289+
#if defined(USE_NOTECARD) || defined(HAS_TCP)
279290
bool TimeServiceClass::connected()
280291
{
281292
if(_con_hdl == nullptr) {
@@ -288,6 +299,7 @@ bool TimeServiceClass::connected()
288299
unsigned long TimeServiceClass::getRemoteTime()
289300
{
290301
if(connected()) {
302+
#ifdef HAS_TCP
291303
/* At first try to obtain a valid time via NTP.
292304
* This is the most reliable time source and it will
293305
* ensure a correct behaviour of the library.
@@ -298,6 +310,7 @@ unsigned long TimeServiceClass::getRemoteTime()
298310
return ntp_time;
299311
}
300312
}
313+
#endif /* HAS_TCP */
301314

302315
/* As fallback if NTP request fails try to obtain the
303316
* network time using the connection handler.
@@ -316,7 +329,7 @@ unsigned long TimeServiceClass::getRemoteTime()
316329
return EPOCH_AT_COMPILE_TIME;
317330
}
318331

319-
#endif /* HAS_TCP */
332+
#endif /* USE_NOTECARD || HAS_TCP */
320333

321334
bool TimeServiceClass::isTimeValid(unsigned long const time)
322335
{
@@ -331,7 +344,9 @@ bool TimeServiceClass::isTimeZoneOffsetValid(long const offset)
331344

332345
void TimeServiceClass::initRTC()
333346
{
334-
#if defined (ARDUINO_ARCH_SAMD)
347+
#if defined (USE_NOTECARD)
348+
notecard_initRTC();
349+
#elif defined (ARDUINO_ARCH_SAMD)
335350
samd_initRTC();
336351
#elif defined (ARDUINO_ARCH_MBED)
337352
mbed_initRTC();
@@ -348,7 +363,9 @@ void TimeServiceClass::initRTC()
348363

349364
void TimeServiceClass::setRTC(unsigned long time)
350365
{
351-
#if defined (ARDUINO_ARCH_SAMD)
366+
#if defined (USE_NOTECARD)
367+
notecard_setRTC(time);
368+
#elif defined (ARDUINO_ARCH_SAMD)
352369
samd_setRTC(time);
353370
#elif defined (ARDUINO_ARCH_MBED)
354371
mbed_setRTC(time);
@@ -365,7 +382,9 @@ void TimeServiceClass::setRTC(unsigned long time)
365382

366383
unsigned long TimeServiceClass::getRTC()
367384
{
368-
#if defined (ARDUINO_ARCH_SAMD)
385+
#if defined (USE_NOTECARD)
386+
return notecard_getRTC();
387+
#elif defined (ARDUINO_ARCH_SAMD)
369388
return samd_getRTC();
370389
#elif defined (ARDUINO_ARCH_MBED)
371390
return mbed_getRTC();
@@ -420,6 +439,23 @@ time_t cvt_time(char const * time)
420439
return build_time;
421440
}
422441

442+
#ifdef USE_NOTECARD
443+
void notecard_initRTC()
444+
{
445+
rtc.begin();
446+
}
447+
448+
void notecard_setRTC(unsigned long time)
449+
{
450+
rtc.set(time);
451+
}
452+
453+
unsigned long notecard_getRTC()
454+
{
455+
return rtc.get();
456+
}
457+
#else
458+
423459
#ifdef ARDUINO_ARCH_SAMD
424460
void samd_initRTC()
425461
{
@@ -509,6 +545,8 @@ unsigned long renesas_getRTC()
509545
}
510546
#endif
511547

548+
#endif /* USE_NOTECARD */
549+
512550
/******************************************************************************
513551
* EXTERN DEFINITION
514552
******************************************************************************/

‎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(USE_NOTECARD) || defined(HAS_TCP)
7373
unsigned long getRemoteTime();
7474
bool connected();
7575
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.