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 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ jobs:
- name: ArduinoECCX08
- name: Arduino_Cellular
- name: Blues Wireless Notecard
- name: ArduinoBLE
- name: Arduino_KVStore
- name: Arduino_NetworkConfigurator
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-DeferredOTA
- examples/ArduinoIoTCloud-Notecard
- examples/ArduinoIoTCloud-Schedule
Expand All @@ -207,7 +211,11 @@ jobs:
- name: arduino:mbed_nicla
libraries: |
- name: Blues Wireless Notecard
- name: ArduinoBLE
- name: Arduino_KVStore
- name: Arduino_NetworkConfigurator
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-DeferredOTA
- examples/ArduinoIoTCloud-Notecard
- examples/ArduinoIoTCloud-Schedule
Expand All @@ -222,7 +230,11 @@ jobs:
- name: ArduinoBearSSL
- name: ArduinoECCX08
- name: Blues Wireless Notecard
- name: ArduinoBLE
- name: Arduino_KVStore
- name: Arduino_NetworkConfigurator
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-DeferredOTA
- examples/ArduinoIoTCloud-Notecard
- examples/ArduinoIoTCloud-Schedule
Expand All @@ -237,7 +249,11 @@ jobs:
- name: ArduinoBearSSL
- name: ArduinoECCX08
- name: Blues Wireless Notecard
- name: ArduinoBLE
- name: Arduino_KVStore
- name: Arduino_NetworkConfigurator
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-DeferredOTA
- examples/ArduinoIoTCloud-Notecard
- examples/ArduinoIoTCloud-Schedule
Expand All @@ -251,7 +267,11 @@ jobs:
libraries: |
- name: Arduino_Cellular
- name: Blues Wireless Notecard
- name: ArduinoBLE
- name: Arduino_KVStore
- name: Arduino_NetworkConfigurator
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-Notecard
- examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
Expand All @@ -263,7 +283,11 @@ jobs:
- name: arduino:renesas_uno
libraries: |
- name: Blues Wireless Notecard
- name: ArduinoBLE
- name: Arduino_KVStore
- name: Arduino_NetworkConfigurator
sketch-paths: |
- examples/ArduinoIoTCloud-NetConfig
- examples/ArduinoIoTCloud-Notecard
- examples/ArduinoIoTCloud-Schedule
# Nano ESP32
Expand Down
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/BLEAgent.h"
#include "configuratorAgents/agents/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