Skip to content

Commit 4083b9d

Browse files
committed
use network configurator in iotCloud
update test ci update example of sketch that uses the NetworkConfigurator use NetworkConfigurator wrappers for agentsManager
1 parent 67e3c33 commit 4083b9d

File tree

7 files changed

+222
-38
lines changed

7 files changed

+222
-38
lines changed

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

+17-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@ jobs:
2121
UNIVERSAL_LIBRARIES: |
2222
# Install the ArduinoIoTCloud library from the repository
2323
- source-path: ./
24-
- name: Arduino_ConnectionHandler
24+
- source-url: https://github.com/andreagilardoni/Arduino_ConnectionHandler.git
25+
version: 0ca6d61eb538c5a21983e582ee1c8794442f8c75
26+
- source-url: https://github.com/fabik111/ArduinoBLE.git
27+
version: 82e2a28f871e97b313846cee6d9efed8943dca53
2528
- name: ArduinoHttpClient
2629
- name: Arduino_DebugUtils
2730
- name: ArduinoMqttClient
2831
- name: Arduino_SecureElement
2932
- name: Arduino_CloudUtils
33+
- source-url: https://github.com/andreagilardoni/ArduinoStorage.git
34+
version: 39f0bd138103967aaafcaa7f5c0e1e237b4ccb4d
35+
- source-url: https://github.com/bcmi-labs/arduino-network-configurator.git
36+
version: 962ab36dfb00eb9cebe089907223e576f463519f
3037
# sketch paths to compile (recursive) for all boards
3138
UNIVERSAL_SKETCH_PATHS: |
3239
- examples/ArduinoIoTCloud-Advanced
@@ -125,10 +132,12 @@ jobs:
125132
- name: ArduinoECCX08
126133
- name: Blues Wireless Notecard
127134
- name: RTCZero
128-
- name: WiFiNINA
135+
- source-url: https://github.com/andreagilardoni/WiFiNINA.git
136+
version: ca7a9224f86b9aaf00de4f7feccea583a23b3d53
129137
- name: Arduino_JSON
130138
- source-url: https://github.com/adafruit/Adafruit_SleepyDog.git
131139
sketch-paths: |
140+
- examples/ArduinoIoTCloud-NetConfig
132141
- examples/ArduinoIoTCloud-DeferredOTA
133142
- examples/ArduinoIoTCloud-Notecard
134143
- examples/ArduinoIoTCloud-Schedule
@@ -190,6 +199,7 @@ jobs:
190199
- name: Arduino_Cellular
191200
- name: Blues Wireless Notecard
192201
sketch-paths: |
202+
- examples/ArduinoIoTCloud-NetConfig
193203
- examples/ArduinoIoTCloud-DeferredOTA
194204
- examples/ArduinoIoTCloud-Notecard
195205
- examples/ArduinoIoTCloud-Schedule
@@ -203,6 +213,7 @@ jobs:
203213
libraries: |
204214
- name: Blues Wireless Notecard
205215
sketch-paths: |
216+
- examples/ArduinoIoTCloud-NetConfig
206217
- examples/ArduinoIoTCloud-DeferredOTA
207218
- examples/ArduinoIoTCloud-Notecard
208219
- examples/ArduinoIoTCloud-Schedule
@@ -217,6 +228,7 @@ jobs:
217228
- name: ArduinoECCX08
218229
- name: Blues Wireless Notecard
219230
sketch-paths: |
231+
- examples/ArduinoIoTCloud-NetConfig
220232
- examples/ArduinoIoTCloud-DeferredOTA
221233
- examples/ArduinoIoTCloud-Notecard
222234
- examples/ArduinoIoTCloud-Schedule
@@ -231,6 +243,7 @@ jobs:
231243
- name: ArduinoECCX08
232244
- name: Blues Wireless Notecard
233245
sketch-paths: |
246+
- examples/ArduinoIoTCloud-NetConfig
234247
- examples/ArduinoIoTCloud-DeferredOTA
235248
- examples/ArduinoIoTCloud-Notecard
236249
- examples/ArduinoIoTCloud-Schedule
@@ -245,6 +258,7 @@ jobs:
245258
- name: Arduino_Cellular
246259
- name: Blues Wireless Notecard
247260
sketch-paths: |
261+
- examples/ArduinoIoTCloud-NetConfig
248262
- examples/ArduinoIoTCloud-Notecard
249263
- examples/ArduinoIoTCloud-Schedule
250264
- examples/utility/Provisioning
@@ -257,6 +271,7 @@ jobs:
257271
libraries: |
258272
- name: Blues Wireless Notecard
259273
sketch-paths: |
274+
- examples/ArduinoIoTCloud-NetConfig
260275
- examples/ArduinoIoTCloud-Notecard
261276
- examples/ArduinoIoTCloud-Schedule
262277
# 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+
}

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

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#if defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \
2+
|| (defined(BOARD_HAS_SECRET_KEY) && !defined(ARDUINO_UNOR4_WIFI)) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
3+
#error "This example is not compatible with this board."
4+
#endif
5+
#include <ArduinoIoTCloud.h>
6+
#include <Arduino_ConnectionHandler.h>
7+
#include "ConfiguratorAgents/agents/BLE/BLEAgent.h"
8+
#include "ConfiguratorAgents/agents/Serial/SerialAgent.h"
9+
10+
#if !(defined(HAS_TCP) || defined(HAS_LORA))
11+
#error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
12+
#endif
13+
14+
void onLedChange();
15+
16+
bool led;
17+
int potentiometer;
18+
int seconds;
19+
20+
GenericConnectionHandler ArduinoIoTPreferredConnection;
21+
KVStore kvStore;
22+
NetworkConfiguratorClass NetworkConfigurator(ArduinoIoTPreferredConnection);
23+
BLEAgentClass BLEAgent;
24+
SerialAgentClass SerialAgent;
25+
26+
void initProperties() {
27+
NetworkConfigurator.addAgent(BLEAgent);
28+
NetworkConfigurator.addAgent(SerialAgent);
29+
NetworkConfigurator.setStorage(kvStore);
30+
ArduinoCloud.setConfigurator(NetworkConfigurator);
31+
#if defined(ARDUINO_OPTA)
32+
ArduinoCloud.setReconfigurePin(BTN_USER, INPUT);
33+
#endif
34+
35+
ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
36+
ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
37+
ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);
38+
39+
}

Diff for: src/ArduinoIoTCloud.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
ArduinoIoTCloudClass::ArduinoIoTCloudClass()
2929
: _connection{nullptr}
30+
, _configurator{nullptr}
3031
, _time_service(TimeService)
3132
, _thing_id{"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}
3233
, _lib_version{AIOT_CONFIG_LIB_VERSION}

Diff for: src/ArduinoIoTCloud.h

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

2727
#include <Arduino_ConnectionHandler.h>
28+
#include <NetworkConfigurator.h>
2829

2930
#if defined(DEBUG_ERROR) || defined(DEBUG_WARNING) || defined(DEBUG_INFO) || defined(DEBUG_DEBUG) || defined(DEBUG_VERBOSE)
3031
# include <Arduino_DebugUtils.h>
@@ -101,6 +102,8 @@ class ArduinoIoTCloudClass
101102
inline unsigned long getInternalTime() { return _time_service.getTime(); }
102103
inline unsigned long getLocalTime() { return _time_service.getLocalTime(); }
103104

105+
inline void setConfigurator(NetworkConfiguratorClass & configurator) { _configurator = &configurator; }
106+
104107
void addCallback(ArduinoIoTCloudEvent const event, OnCloudEventCallback callback);
105108

106109
#define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__)
@@ -146,6 +149,7 @@ class ArduinoIoTCloudClass
146149
protected:
147150

148151
ConnectionHandler * _connection;
152+
NetworkConfiguratorClass * _configurator = nullptr;
149153
TimeServiceClass & _time_service;
150154
String _thing_id;
151155
String _lib_version;

0 commit comments

Comments
 (0)