Skip to content

Use NetworkConfigurator #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
42 changes: 38 additions & 4 deletions .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ jobs:
UNIVERSAL_LIBRARIES: |
# Install the ArduinoIoTCloud library from the repository
- source-path: ./
- name: Arduino_ConnectionHandler
- source-url: https://github.com/fabik111/Arduino_ConnectionHandler.git
version: 0314cf54593029aea05bb8c179e40a26128f7d67
- name: ArduinoBLE
- name: ArduinoHttpClient
- name: Arduino_DebugUtils
- name: ArduinoMqttClient
- name: Arduino_SecureElement
- name: Arduino_CloudUtils
- source-url: https://github.com/pennam/Arduino_SecureElement.git
version: 4900febf84435c1a06bb13451bced3bac6f16e76
- source-url: https://github.com/arduino-libraries/Arduino_CloudUtils.git
- name: Arduino_KVStore
- source-url: https://github.com/arduino-libraries/Arduino_UniqueHWId.git
- source-url: https://github.com/arduino-libraries/Arduino_NetworkConfigurator.git
# sketch paths to compile (recursive) for all boards
UNIVERSAL_SKETCH_PATHS: |
- examples/ArduinoIoTCloud-Advanced
Expand Down Expand Up @@ -125,15 +131,18 @@ jobs:
- name: ArduinoECCX08
- name: Blues Wireless Notecard
- name: RTCZero
- name: WiFiNINA
- source-url: https://github.com/andreagilardoni/WiFiNINA.git
version: 31616ac5a30f6281c68f982bc39800771b2fbaeb
- name: Arduino_JSON
- source-url: https://github.com/adafruit/Adafruit_SleepyDog.git
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-DeferredOTA
- examples/ArduinoIoTCloud-Notecard
- examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
- examples/utility/SelfProvisioning
- examples/utility/Provisioning_2.0
- board:
type: wan
platforms: |
Expand Down Expand Up @@ -190,10 +199,12 @@ jobs:
- name: Arduino_Cellular
- name: Blues Wireless Notecard
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-DeferredOTA
- examples/ArduinoIoTCloud-Notecard
- examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
- examples/utility/Provisioning_2.0
# Nicla Vision
- board:
type: mbed_nicla
Expand All @@ -202,11 +213,14 @@ jobs:
- name: arduino:mbed_nicla
libraries: |
- name: Blues Wireless Notecard
- name: ArduinoECCX08
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-DeferredOTA
- examples/ArduinoIoTCloud-Notecard
- examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
- examples/utility/Provisioning_2.0
# Opta
- board:
type: mbed_opta
Expand All @@ -217,10 +231,12 @@ jobs:
- name: ArduinoECCX08
- name: Blues Wireless Notecard
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-DeferredOTA
- examples/ArduinoIoTCloud-Notecard
- examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
- examples/utility/Provisioning_2.0
# GIGA
- board:
type: mbed_giga
Expand All @@ -231,10 +247,12 @@ jobs:
- name: ArduinoECCX08
- name: Blues Wireless Notecard
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-DeferredOTA
- examples/ArduinoIoTCloud-Notecard
- examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
- examples/utility/Provisioning_2.0
# Portenta C33
- board:
type: renesas_portenta
Expand All @@ -244,10 +262,13 @@ jobs:
libraries: |
- name: Arduino_Cellular
- name: Blues Wireless Notecard
- name: ArduinoECCX08
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-Notecard
- examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
- examples/utility/Provisioning_2.0
# UNO R4 WiFi
- board:
type: renesas_uno
Expand All @@ -256,9 +277,12 @@ jobs:
- name: arduino:renesas_uno
libraries: |
- name: Blues Wireless Notecard
- name: ArduinoECCX08
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-Notecard
- examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning_2.0
# Nano ESP32
- board:
type: arduino_esp32
Expand Down Expand Up @@ -337,6 +361,9 @@ jobs:
${{ matrix.sketch-paths }}
enable-deltas-report: "true"
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
cli-compile-flags: |
- --output-dir
- ${{ runner.temp }}/arduino-cli-output

- name: Write data to size trends report spreadsheet
# Update report on every push to the master branch
Expand All @@ -353,3 +380,10 @@ jobs:
with:
name: sketches-report-${{ matrix.board.artifact-name-suffix }}
path: ${{ env.SKETCHES_REPORTS_PATH }}

- name: Save build artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: provisioning-${{ matrix.board.artifact-name-suffix }}
path: ${{ runner.temp }}/arduino-cli-output/Provisioning_2.0*
62 changes: 62 additions & 0 deletions examples/ArduinoIoTCloud-NetConfig/ArduinoIoTCloud-NetConfig.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
This sketch demonstrates how to exchange data between your board and the Arduino IoT Cloud.

* Connect a potentiometer (or other analog sensor) to A0.
* When the potentiometer (or sensor) value changes the data is sent to the Cloud.
* When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF.

IMPORTANT:
This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
On a LoRa board, if it is configured as a class A device (default and preferred option),
values from Cloud dashboard are received only after a value is sent to Cloud.

The full list of compatible boards can be found here:
- https://github.com/arduino-libraries/ArduinoIoTCloud#what
*/

#include "thingProperties.h"

#if !defined(LED_BUILTIN) && !defined(ARDUINO_NANO_ESP32)
static int const LED_BUILTIN = 2;
#endif

void setup() {
/* Initialize serial and wait up to 5 seconds for port to open */
Serial.begin(9600);
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }

/* Set the debug message level:
* - DBG_ERROR: Only show error messages
* - DBG_WARNING: Show warning and error messages
* - DBG_INFO: Show info, warning, and error messages
* - DBG_DEBUG: Show debug, info, warning, and error messages
* - DBG_VERBOSE: Show all messages
*/
setDebugMessageLevel(DBG_INFO);

/* Configure LED pin as an output */
pinMode(LED_BUILTIN, OUTPUT);

/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
initProperties();

/* Initialize Arduino IoT Cloud library */
ArduinoCloud.begin(ArduinoIoTPreferredConnection);

ArduinoCloud.printDebugInfo();
}

void loop() {
ArduinoCloud.update();
potentiometer = analogRead(A0);
seconds = millis() / 1000;
}

/*
* 'onLedChange' is called when the "led" property of your Thing changes
*/
void onLedChange() {
Serial.print("LED set to ");
Serial.println(led);
digitalWrite(LED_BUILTIN, led);
}
48 changes: 48 additions & 0 deletions examples/ArduinoIoTCloud-NetConfig/thingProperties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#if !defined(ARDUINO_SAMD_MKRWIFI1010) && !defined(ARDUINO_SAMD_NANO_33_IOT) && !defined(ARDUINO_NANO_RP2040_CONNECT) \
&& !defined(ARDUINO_PORTENTA_H7_M7) && !defined(ARDUINO_NICLA_VISION) && !defined(ARDUINO_OPTA) && !defined(ARDUINO_GIGA) \
&& !defined(ARDUINO_UNOR4_WIFI) && !defined(ARDUINO_PORTENTA_C33)
#error "This example is not compatible with this board."
#endif
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
#include <GenericConnectionHandler.h>
#include "ConfiguratorAgents/agents/BLE/BLEAgent.h"
#include "ConfiguratorAgents/agents/Serial/SerialAgent.h"

void onLedChange();

bool led;
int potentiometer;
int seconds;

GenericConnectionHandler ArduinoIoTPreferredConnection;
KVStore kvStore;
NetworkConfiguratorClass NetworkConfigurator(ArduinoIoTPreferredConnection);
BLEAgentClass BLEAgent;
SerialAgentClass SerialAgent;

void initProperties() {
NetworkConfigurator.addAgent(BLEAgent);
NetworkConfigurator.addAgent(SerialAgent);
NetworkConfigurator.setStorage(kvStore);

/* For changing the default reset pin uncomment and set your preferred pin.
* Use DISABLE_PIN for disabling the reset procedure.
* The pin must be in the list of digital pins usable for interrupts.
* Please refer to the Arduino documentation for more details:
* https://docs.arduino.cc/language-reference/en/functions/external-interrupts/attachInterrupt/
*/
//NetworkConfigurator.setReconfigurePin(your_pin);

/* Otherwise if you need to monitor the pin status changes
* you can set a custom callback function that is fired on every change
*/
//NetworkConfigurator.setPinChangedCallback(your_callback);

ArduinoCloud.setConfigurator(NetworkConfigurator);

ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);

}
Loading
Loading