Skip to content

Commit 37df5db

Browse files
committed
use network configurator in iotCloud
update example of sketch that uses the NetworkConfigurator use NetworkConfigurator wrappers for agentsManager update ci test for networkConfigurator add Arduino_NetworkConfigurator dep to library.properties
1 parent cc01f43 commit 37df5db

9 files changed

+239
-31
lines changed

.github/workflows/compile-examples.yml

+24
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ jobs:
194194
- name: ArduinoECCX08
195195
- name: Arduino_Cellular
196196
- name: Blues Wireless Notecard
197+
- name: ArduinoBLE
198+
- name: Arduino_KVStore
199+
- name: Arduino_NetworkConfigurator
197200
sketch-paths: |
201+
- examples/ArduinoIoTCloud-NetConfig
198202
- examples/ArduinoIoTCloud-DeferredOTA
199203
- examples/ArduinoIoTCloud-Notecard
200204
- examples/ArduinoIoTCloud-Schedule
@@ -207,7 +211,11 @@ jobs:
207211
- name: arduino:mbed_nicla
208212
libraries: |
209213
- name: Blues Wireless Notecard
214+
- name: ArduinoBLE
215+
- name: Arduino_KVStore
216+
- name: Arduino_NetworkConfigurator
210217
sketch-paths: |
218+
- examples/ArduinoIoTCloud-NetConfig
211219
- examples/ArduinoIoTCloud-DeferredOTA
212220
- examples/ArduinoIoTCloud-Notecard
213221
- examples/ArduinoIoTCloud-Schedule
@@ -222,7 +230,11 @@ jobs:
222230
- name: ArduinoBearSSL
223231
- name: ArduinoECCX08
224232
- name: Blues Wireless Notecard
233+
- name: ArduinoBLE
234+
- name: Arduino_KVStore
235+
- name: Arduino_NetworkConfigurator
225236
sketch-paths: |
237+
- examples/ArduinoIoTCloud-NetConfig
226238
- examples/ArduinoIoTCloud-DeferredOTA
227239
- examples/ArduinoIoTCloud-Notecard
228240
- examples/ArduinoIoTCloud-Schedule
@@ -237,7 +249,11 @@ jobs:
237249
- name: ArduinoBearSSL
238250
- name: ArduinoECCX08
239251
- name: Blues Wireless Notecard
252+
- name: ArduinoBLE
253+
- name: Arduino_KVStore
254+
- name: Arduino_NetworkConfigurator
240255
sketch-paths: |
256+
- examples/ArduinoIoTCloud-NetConfig
241257
- examples/ArduinoIoTCloud-DeferredOTA
242258
- examples/ArduinoIoTCloud-Notecard
243259
- examples/ArduinoIoTCloud-Schedule
@@ -251,7 +267,11 @@ jobs:
251267
libraries: |
252268
- name: Arduino_Cellular
253269
- name: Blues Wireless Notecard
270+
- name: ArduinoBLE
271+
- name: Arduino_KVStore
272+
- name: Arduino_NetworkConfigurator
254273
sketch-paths: |
274+
- examples/ArduinoIoTCloud-NetConfig
255275
- examples/ArduinoIoTCloud-Notecard
256276
- examples/ArduinoIoTCloud-Schedule
257277
- examples/utility/Provisioning
@@ -263,7 +283,11 @@ jobs:
263283
- name: arduino:renesas_uno
264284
libraries: |
265285
- name: Blues Wireless Notecard
286+
- name: ArduinoBLE
287+
- name: Arduino_KVStore
288+
- name: Arduino_NetworkConfigurator
266289
sketch-paths: |
290+
- examples/ArduinoIoTCloud-NetConfig
267291
- examples/ArduinoIoTCloud-Notecard
268292
- examples/ArduinoIoTCloud-Schedule
269293
# Nano ESP32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
This sketch demonstrates how to exchange data between your board and the Arduino IoT Cloud.
3+
4+
* Connect a potentiometer (or other analog sensor) to A0.
5+
* When the potentiometer (or sensor) value changes the data is sent to the Cloud.
6+
* When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF.
7+
8+
IMPORTANT:
9+
This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
10+
On a LoRa board, if it is configured as a class A device (default and preferred option),
11+
values from Cloud dashboard are received only after a value is sent to Cloud.
12+
13+
The full list of compatible boards can be found here:
14+
- https://github.com/arduino-libraries/ArduinoIoTCloud#what
15+
*/
16+
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+
void setup() {
24+
/* Initialize serial and wait up to 5 seconds for port to open */
25+
Serial.begin(9600);
26+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
27+
28+
/* Set the debug message level:
29+
* - DBG_ERROR: Only show error messages
30+
* - DBG_WARNING: Show warning and error messages
31+
* - DBG_INFO: Show info, warning, and error messages
32+
* - DBG_DEBUG: Show debug, info, warning, and error messages
33+
* - DBG_VERBOSE: Show all messages
34+
*/
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+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
45+
46+
ArduinoCloud.printDebugInfo();
47+
}
48+
49+
void loop() {
50+
ArduinoCloud.update();
51+
potentiometer = analogRead(A0);
52+
seconds = millis() / 1000;
53+
}
54+
55+
/*
56+
* 'onLedChange' is called when the "led" property of your Thing changes
57+
*/
58+
void onLedChange() {
59+
Serial.print("LED set to ");
60+
Serial.println(led);
61+
digitalWrite(LED_BUILTIN, led);
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#if !defined(ARDUINO_SAMD_MKRWIFI1010) && !defined(ARDUINO_SAMD_NANO_33_IOT) && !defined(ARDUINO_NANO_RP2040_CONNECT) \
2+
&& !defined(ARDUINO_PORTENTA_H7_M7) && !defined(ARDUINO_NICLA_VISION) && !defined(ARDUINO_OPTA) && !defined(ARDUINO_GIGA) \
3+
&& !defined(ARDUINO_UNOR4_WIFI) && !defined(ARDUINO_PORTENTA_C33)
4+
#error "This example is not compatible with this board."
5+
#endif
6+
#include <ArduinoIoTCloud.h>
7+
#include <Arduino_ConnectionHandler.h>
8+
#include "ConfiguratorAgents/agents/BLE/BLEAgent.h"
9+
#include "ConfiguratorAgents/agents/Serial/SerialAgent.h"
10+
11+
void onLedChange();
12+
13+
bool led;
14+
int potentiometer;
15+
int seconds;
16+
17+
GenericConnectionHandler ArduinoIoTPreferredConnection;
18+
KVStore kvStore;
19+
NetworkConfiguratorClass NetworkConfigurator(ArduinoIoTPreferredConnection);
20+
BLEAgentClass BLEAgent;
21+
SerialAgentClass SerialAgent;
22+
23+
void initProperties() {
24+
NetworkConfigurator.addAgent(BLEAgent);
25+
NetworkConfigurator.addAgent(SerialAgent);
26+
NetworkConfigurator.setStorage(kvStore);
27+
28+
/* For changing the default reset pin uncomment and set your preferred pin.
29+
* Use DISABLE_PIN for disabling the reset procedure.
30+
* The pin must be in the list of digital pins usable for interrupts.
31+
* Please refer to the Arduino documentation for more details:
32+
* https://docs.arduino.cc/language-reference/en/functions/external-interrupts/attachInterrupt/
33+
*/
34+
//NetworkConfigurator.setReconfigurePin(your_pin);
35+
36+
/* Otherwise if you need to monitor the pin status changes
37+
* you can set a custom callback function that is fired on every change
38+
*/
39+
//NetworkConfigurator.setPinChangedCallback(your_callback);
40+
41+
ArduinoCloud.setConfigurator(NetworkConfigurator);
42+
43+
ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
44+
ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
45+
ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);
46+
47+
}

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ category=Communication
88
url=https://github.com/arduino-libraries/ArduinoIoTCloud
99
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
11-
depends=Arduino_ConnectionHandler,Arduino_DebugUtils,Arduino_SecureElement,ArduinoMqttClient,ArduinoECCX08,RTCZero,Adafruit SleepyDog Library,ArduinoHttpClient,Arduino_CloudUtils,ArduinoBearSSL
11+
depends=Arduino_ConnectionHandler,Arduino_DebugUtils,Arduino_SecureElement,ArduinoMqttClient,ArduinoECCX08,RTCZero,Adafruit SleepyDog Library,ArduinoHttpClient,Arduino_CloudUtils,ArduinoBearSSL,Arduino_NetworkConfigurator

src/AIoTC_Config.h

+7
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@
148148
#define BOARD_STM32H7
149149
#endif
150150

151+
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_OPTA) || defined(ARDUINO_GIGA) \
152+
|| defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_PORTENTA_C33)
153+
#define NETWORK_CONFIGURATOR_ENABLED (1)
154+
#else
155+
#define NETWORK_CONFIGURATOR_ENABLED (0)
156+
#endif
157+
151158
/******************************************************************************
152159
* CONSTANTS
153160
******************************************************************************/

src/ArduinoIoTCloud.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
ArduinoIoTCloudClass::ArduinoIoTCloudClass()
2929
: _connection{nullptr}
30+
#if NETWORK_CONFIGURATOR_ENABLED
31+
, _configurator{nullptr}
32+
#endif
3033
, _time_service(TimeService)
3134
, _thing_id{"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}
3235
, _lib_version{AIOT_CONFIG_LIB_VERSION}

src/ArduinoIoTCloud.h

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include <AIoTC_Config.h>
2626

2727
#include <Arduino_ConnectionHandler.h>
28+
#if NETWORK_CONFIGURATOR_ENABLED
29+
#include <NetworkConfigurator.h>
30+
#endif
2831

2932
#if defined(DEBUG_ERROR) || defined(DEBUG_WARNING) || defined(DEBUG_INFO) || defined(DEBUG_DEBUG) || defined(DEBUG_VERBOSE)
3033
# include <Arduino_DebugUtils.h>
@@ -101,6 +104,9 @@ class ArduinoIoTCloudClass
101104
inline unsigned long getInternalTime() { return _time_service.getTime(); }
102105
inline unsigned long getLocalTime() { return _time_service.getLocalTime(); }
103106

107+
#if NETWORK_CONFIGURATOR_ENABLED
108+
inline void setConfigurator(NetworkConfiguratorClass & configurator) { _configurator = &configurator; }
109+
#endif
104110
void addCallback(ArduinoIoTCloudEvent const event, OnCloudEventCallback callback);
105111

106112
#define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__)
@@ -146,6 +152,9 @@ class ArduinoIoTCloudClass
146152
protected:
147153

148154
ConnectionHandler * _connection;
155+
#if NETWORK_CONFIGURATOR_ENABLED
156+
NetworkConfiguratorClass * _configurator;
157+
#endif
149158
TimeServiceClass & _time_service;
150159
String _thing_id;
151160
String _lib_version;

0 commit comments

Comments
 (0)