Skip to content

Commit 7604899

Browse files
fabik111pennam
authored andcommitted
use network configurator in iotCloud
update test ci update example of sketch that uses the NetworkConfigurator use NetworkConfigurator wrappers for agentsManager
1 parent da9c776 commit 7604899

File tree

8 files changed

+256
-38
lines changed

8 files changed

+256
-38
lines changed

.github/workflows/compile-examples.yml

Lines changed: 17 additions & 2 deletions
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
@@ -127,10 +134,12 @@ jobs:
127134
- name: ArduinoECCX08
128135
- name: Blues Wireless Notecard
129136
- name: RTCZero
130-
- name: WiFiNINA
137+
- source-url: https://github.com/andreagilardoni/WiFiNINA.git
138+
version: ca7a9224f86b9aaf00de4f7feccea583a23b3d53
131139
- name: Arduino_JSON
132140
- source-url: https://github.com/adafruit/Adafruit_SleepyDog.git
133141
sketch-paths: |
142+
- examples/ArduinoIoTCloud-NetConfig
134143
- examples/ArduinoIoTCloud-DeferredOTA
135144
- examples/ArduinoIoTCloud-Notecard
136145
- examples/ArduinoIoTCloud-Schedule
@@ -195,6 +204,7 @@ jobs:
195204
- name: Arduino_Cellular
196205
- name: Blues Wireless Notecard
197206
sketch-paths: |
207+
- examples/ArduinoIoTCloud-NetConfig
198208
- examples/ArduinoIoTCloud-DeferredOTA
199209
- examples/ArduinoIoTCloud-Notecard
200210
- examples/ArduinoIoTCloud-Schedule
@@ -208,6 +218,7 @@ jobs:
208218
libraries: |
209219
- name: Blues Wireless Notecard
210220
sketch-paths: |
221+
- examples/ArduinoIoTCloud-NetConfig
211222
- examples/ArduinoIoTCloud-DeferredOTA
212223
- examples/ArduinoIoTCloud-Notecard
213224
- examples/ArduinoIoTCloud-Schedule
@@ -223,6 +234,7 @@ jobs:
223234
- name: ArduinoECCX08
224235
- name: Blues Wireless Notecard
225236
sketch-paths: |
237+
- examples/ArduinoIoTCloud-NetConfig
226238
- examples/ArduinoIoTCloud-DeferredOTA
227239
- examples/ArduinoIoTCloud-Notecard
228240
- examples/ArduinoIoTCloud-Schedule
@@ -238,6 +250,7 @@ jobs:
238250
- name: ArduinoECCX08
239251
- name: Blues Wireless Notecard
240252
sketch-paths: |
253+
- examples/ArduinoIoTCloud-NetConfig
241254
- examples/ArduinoIoTCloud-DeferredOTA
242255
- examples/ArduinoIoTCloud-Notecard
243256
- examples/ArduinoIoTCloud-Schedule
@@ -252,6 +265,7 @@ jobs:
252265
- name: Arduino_Cellular
253266
- name: Blues Wireless Notecard
254267
sketch-paths: |
268+
- examples/ArduinoIoTCloud-NetConfig
255269
- examples/ArduinoIoTCloud-Notecard
256270
- examples/ArduinoIoTCloud-Schedule
257271
- examples/utility/Provisioning
@@ -264,6 +278,7 @@ jobs:
264278
libraries: |
265279
- name: Blues Wireless Notecard
266280
sketch-paths: |
281+
- examples/ArduinoIoTCloud-NetConfig
267282
- examples/ArduinoIoTCloud-Notecard
268283
- examples/ArduinoIoTCloud-Schedule
269284
# 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+
}

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 = nullptr;
157+
#endif
149158
TimeServiceClass & _time_service;
150159
String _thing_id;
151160
String _lib_version;

0 commit comments

Comments
 (0)