Skip to content

Commit 41ab915

Browse files
authored
Merge pull request #535 from fabik111/use-networkconfigurator
Use NetworkConfigurator
2 parents e4e1ac3 + 2b11b7e commit 41ab915

16 files changed

+1303
-42
lines changed

.github/workflows/compile-examples.yml

Lines changed: 24 additions & 0 deletions
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
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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 <GenericConnectionHandler.h>
9+
#include <Arduino_NetworkConfigurator.h>
10+
#include <configuratorAgents/agents/BLEAgent.h>
11+
#include <configuratorAgents/agents/SerialAgent.h>
12+
13+
void onLedChange();
14+
15+
bool led;
16+
int potentiometer;
17+
int seconds;
18+
19+
GenericConnectionHandler ArduinoIoTPreferredConnection;
20+
KVStore kvStore;
21+
NetworkConfiguratorClass NetworkConfigurator(ArduinoIoTPreferredConnection);
22+
BLEAgentClass BLEAgent;
23+
SerialAgentClass SerialAgent;
24+
25+
void initProperties() {
26+
NetworkConfigurator.addAgent(BLEAgent);
27+
NetworkConfigurator.addAgent(SerialAgent);
28+
NetworkConfigurator.setStorage(kvStore);
29+
30+
/* For changing the default reset pin uncomment and set your preferred pin.
31+
* Use DISABLE_PIN for disabling the reset procedure.
32+
* The pin must be in the list of digital pins usable for interrupts.
33+
* Please refer to the Arduino documentation for more details:
34+
* https://docs.arduino.cc/language-reference/en/functions/external-interrupts/attachInterrupt/
35+
*/
36+
//NetworkConfigurator.setReconfigurePin(your_pin);
37+
38+
/* Otherwise if you need to monitor the pin status changes
39+
* you can set a custom callback function that is fired on every change
40+
*/
41+
//NetworkConfigurator.setPinChangedCallback(your_callback);
42+
43+
ArduinoCloud.setConfigurator(NetworkConfigurator);
44+
45+
ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
46+
ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
47+
ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);
48+
49+
}

0 commit comments

Comments
 (0)