Skip to content

Commit 957be75

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 957be75

File tree

9 files changed

+231
-37
lines changed

9 files changed

+231
-37
lines changed

.github/workflows/compile-examples.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ jobs:
2222
# Install the ArduinoIoTCloud library from the repository
2323
- source-path: ./
2424
- name: Arduino_ConnectionHandler
25+
- name: ArduinoBLE
2526
- name: ArduinoHttpClient
2627
- name: Arduino_DebugUtils
2728
- name: ArduinoMqttClient
2829
- name: Arduino_SecureElement
2930
- name: Arduino_CloudUtils
31+
- name: Arduino_KVStore
32+
- name: Arduino_NetworkConfigurator
3033
# sketch paths to compile (recursive) for all boards
3134
UNIVERSAL_SKETCH_PATHS: |
3235
- examples/ArduinoIoTCloud-Advanced
@@ -195,6 +198,7 @@ jobs:
195198
- name: Arduino_Cellular
196199
- name: Blues Wireless Notecard
197200
sketch-paths: |
201+
- examples/ArduinoIoTCloud-NetConfig
198202
- examples/ArduinoIoTCloud-DeferredOTA
199203
- examples/ArduinoIoTCloud-Notecard
200204
- examples/ArduinoIoTCloud-Schedule
@@ -208,6 +212,7 @@ jobs:
208212
libraries: |
209213
- name: Blues Wireless Notecard
210214
sketch-paths: |
215+
- examples/ArduinoIoTCloud-NetConfig
211216
- examples/ArduinoIoTCloud-DeferredOTA
212217
- examples/ArduinoIoTCloud-Notecard
213218
- examples/ArduinoIoTCloud-Schedule
@@ -223,6 +228,7 @@ jobs:
223228
- name: ArduinoECCX08
224229
- name: Blues Wireless Notecard
225230
sketch-paths: |
231+
- examples/ArduinoIoTCloud-NetConfig
226232
- examples/ArduinoIoTCloud-DeferredOTA
227233
- examples/ArduinoIoTCloud-Notecard
228234
- examples/ArduinoIoTCloud-Schedule
@@ -238,6 +244,7 @@ jobs:
238244
- name: ArduinoECCX08
239245
- name: Blues Wireless Notecard
240246
sketch-paths: |
247+
- examples/ArduinoIoTCloud-NetConfig
241248
- examples/ArduinoIoTCloud-DeferredOTA
242249
- examples/ArduinoIoTCloud-Notecard
243250
- examples/ArduinoIoTCloud-Schedule
@@ -252,6 +259,7 @@ jobs:
252259
- name: Arduino_Cellular
253260
- name: Blues Wireless Notecard
254261
sketch-paths: |
262+
- examples/ArduinoIoTCloud-NetConfig
255263
- examples/ArduinoIoTCloud-Notecard
256264
- examples/ArduinoIoTCloud-Schedule
257265
- examples/utility/Provisioning
@@ -264,6 +272,7 @@ jobs:
264272
libraries: |
265273
- name: Blues Wireless Notecard
266274
sketch-paths: |
275+
- examples/ArduinoIoTCloud-NetConfig
267276
- examples/ArduinoIoTCloud-Notecard
268277
- examples/ArduinoIoTCloud-Schedule
269278
# Nano ESP32
Lines changed: 62 additions & 0 deletions
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+
}
Lines changed: 47 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@
148148
#define BOARD_STM32H7
149149
#endif
150150

151+
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_NANO_RP2040_CONNECT) \
152+
|| defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_OPTA) || defined(ARDUINO_GIGA) \
153+
|| defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_PORTENTA_C33)
154+
#define NETWORK_CONFIGURATOR_ENABLED (1)
155+
#else
156+
#define NETWORK_CONFIGURATOR_ENABLED (0)
157+
#endif
158+
151159
/******************************************************************************
152160
* CONSTANTS
153161
******************************************************************************/

src/ArduinoIoTCloud.cpp

Lines changed: 3 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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)