Skip to content

Cleaning up examples #110

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

Merged
merged 15 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
39 changes: 26 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ matrix:
- BOARD="arduino:samd:mkr1000"
- env:
- BOARD="arduino:samd:mkrwifi1010"
- env:
- BOARD="arduino:samd:nano_33_iot"
- env:
- BOARD="arduino:samd:mkrgsm1400"
- env:
Expand Down Expand Up @@ -77,32 +79,43 @@ install:
- mkdir -p $HOME/Arduino/libraries
- ln -s $PWD $HOME/Arduino/libraries/.
script:
# Sketches to build for all boards
- |
if [ "$BOARD" == "arduino:samd:mkr1000" ] || [ "$BOARD" == "arduino:samd:mkrwifi1010" ] || [ "$BOARD" == "arduino:samd:mkrgsm1400" ] || [ "$BOARD" == "arduino:samd:mkrnb1500" ]; then
if [ "$BOARD" == "arduino:samd:mkr1000" ] || \
[ "$BOARD" == "arduino:samd:mkrwifi1010" ] || \
[ "$BOARD" == "esp8266:esp8266:huzzah" ] || \
[ "$BOARD" == "arduino:samd:nano_33_iot"] || \
[ "$BOARD" == "arduino:samd:mkrgsm1400" ] || \
[ "$BOARD" == "arduino:samd:mkrnb1500" ] || \
[ "$BOARD" == "arduino:samd:mkrwan1300" ]; then
buildSketch \
"ArduinoIoTCloud_LED_switch" \
"ArduinoIoTCloud_Travis_CI" \
"utility/Provisioning"
"ArduinoIoTCloud-Advanced" \
"ArduinoIoTCloud-Basic" \
"utility/ArduinoIoTCloud_Travis_CI"
fi
# Sketches to build for selected boards
- |
if [ "$BOARD" == "arduino:samd:mkrwan1300" ]; then
if [ "$BOARD" == "arduino:samd:mkr1000" ] || [ "$BOARD" == "arduino:samd:mkrwifi1010" ] || [ "$BOARD" == "arduino:samd:nano_33_iot"]; then
buildSketch \
"ArduinoIoTCloud_LED_switch" \
"ArduinoIoTCloud_Travis_CI"
"utility/Provisioning" \
"utility/WiFi_Cloud_Blink"
fi
- |
if [ "$BOARD" == "arduino:samd:mkr1000" ] || [ "$BOARD" == "arduino:samd:mkrwifi1010" ]; then
if [ "$BOARD" == "arduino:samd:mkrgsm1400" ]; then
buildSketch \
"WiFi_Cloud_Blink" \
"MultiValue_example"
"utility/Provisioning" \
"utility/GSM_Cloud_Blink"
fi
- |
if [ "$BOARD" == "arduino:samd:mkrgsm1400" ]; then
buildSketch "GSM_Cloud_Blink"
if [ "$BOARD" == "arduino:samd:mkrnb1500" ]; then
buildSketch \
"utility/Provisioning" \
"utility/NB_Cloud_Blink"
fi
- |
if [ "$BOARD" == "esp8266:esp8266:huzzah" ]; then
buildSketch "ArduinoIoTCloud_ESP8266"
buildSketch \
"utility/WiFi_Cloud_Blink_with_security_credentials"
fi
notifications:
webhooks:
Expand Down
61 changes: 61 additions & 0 deletions examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
This sketch demonstrates how to use more complex cloud data types such as a colour or coordinates.

This sketch is compatible with:
- MKR 1000
- MKR WIFI 1010
- MKR GSM 1400
- MKR NB 1500
- MKR WAN 1300/1310
- ESP 8266
*/

#include "arduino_secrets.h"
#include "thingProperties.h"

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); ) { }

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

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

setDebugMessageLevel(DBG_INFO);
ArduinoCloud.printDebugInfo();
}

float latMov = 45.5058224, lonMov = 9.1628673;
float latArd = 45.0502078, lonArd = 7.6674765;

float hueRed = 0.0, satRed = 100.0, briRed = 100.0;
float hueGreen = 80.0, satGreen = 100.0, briGreen = 100.0;

void loop() {
ArduinoCloud.update();
}

void onSwitchButtonChange() {
if (switchButton)
{
location = Location(latMov, lonMov);
color = Color(hueRed, satRed, briRed);
}
else
{
location = Location(latArd, lonArd);
color = Color(hueGreen, satGreen, briGreen);
}
}

void onColorChange() {
Serial.print("Hue = ");
Serial.println(color.getValue().hue);
Serial.print("Sat = ");
Serial.println(color.getValue().sat);
Serial.print("Bri = ");
Serial.println(color.getValue().bri);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#define SECRET_PASS "YOUR_WIFI_PASSWORD"
#endif

/* ESP8266 */
#if defined(BOARD_ESP8266)
#define SECRET_DEVICE_KEY "my-device-password"
#endif

/* MKR GSM 1400 */
#if defined(BOARD_HAS_GSM)
#define SECRET_PIN ""
Expand Down
39 changes: 39 additions & 0 deletions examples/ArduinoIoTCloud-Advanced/thingProperties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

void onSwitchButtonChange();
void onColorChange();

bool switchButton;
CloudLocation location;
CloudColor color;

void initProperties() {
#if defined(BOARD_ESP8266)
ArduinoCloud.setBoardId(BOARD_ID);
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
#endif
ArduinoCloud.setThingId(THING_ID);
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB)
ArduinoCloud.addProperty(switchButton, WRITE, ON_CHANGE, onSwitchButtonChange);
ArduinoCloud.addProperty(location, READ, ON_CHANGE);
ArduinoCloud.addProperty(color, READWRITE, ON_CHANGE, onColorChange);
#elif defined(BOARD_HAS_LORA)
ArduinoCloud.addProperty(switchButton, 1, WRITE, ON_CHANGE, onSwitchButtonChange);
ArduinoCloud.addProperty(location, 2, READ, ON_CHANGE);
ArduinoCloud.addProperty(color, 3, READWRITE, ON_CHANGE, onColorChange);
#endif
}

#if defined(BOARD_HAS_WIFI)
WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);
#elif defined(BOARD_HAS_GSM)
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#elif defined(BOARD_HAS_LORA)
LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, _lora_class::CLASS_A);
#elif defined(BOARD_HAS_NB)
NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#endif
56 changes: 56 additions & 0 deletions examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
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 and Lora enabled boards supported by Arduino IoT Cloud.
On a LoRa board, if it is configuered as a class A device (default and preferred option), values from Cloud dashboard are received
only after a value is sent to Cloud.

This sketch is compatible with:
- MKR 1000
- MKR WIFI 1010
- MKR GSM 1400
- MKR NB 1500
- MKR WAN 1300/1310
- ESP 8266
*/

#include "arduino_secrets.h"
#include "thingProperties.h"

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); ) { }

/* 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);

setDebugMessageLevel(DBG_INFO);
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);
}
34 changes: 34 additions & 0 deletions examples/ArduinoIoTCloud-Basic/arduino_secrets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <Arduino_ConnectionHandler.h>

/* MKR1000, MKR WiFi 1010 */
#if defined(BOARD_HAS_WIFI)
#define SECRET_SSID "YOUR_WIFI_NETWORK_NAME"
#define SECRET_PASS "YOUR_WIFI_PASSWORD"
#endif

/* ESP8266 */
#if defined(BOARD_ESP8266)
#define SECRET_DEVICE_KEY "my-device-password"
#endif

/* MKR GSM 1400 */
#if defined(BOARD_HAS_GSM)
#define SECRET_PIN ""
#define SECRET_APN ""
#define SECRET_LOGIN ""
#define SECRET_PASS ""
#endif

/* MKR WAN 1300/1310 */
#if defined(BOARD_HAS_LORA)
#define SECRET_APP_EUI ""
#define SECRET_APP_KEY ""
#endif

/* MKR NB 1500 */
#if defined(BOARD_HAS_NB)
#define SECRET_PIN ""
#define SECRET_APN ""
#define SECRET_LOGIN ""
#define SECRET_PASS ""
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,30 @@
#error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010, MKR WAN 1300/1310, MKR NB 1500 and MKR GSM 1400"
#endif


// Your THING_ID
#define THING_ID "ARDUINO_IOT_CLOUD_THING_ID"
#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

void onLedChange();

bool led;
int potentiometer;
int seconds;

void initProperties() {
#if defined(BOARD_ESP8266)
ArduinoCloud.setBoardId(BOARD_ID);
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
#endif
ArduinoCloud.setThingId(THING_ID);
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM)
ArduinoCloud.addProperty(led, READWRITE, ON_CHANGE, onLedChange);
ArduinoCloud.addProperty(potentiometer, READ, ON_CHANGE);
#elif defined(BOARD_HAS_LORA)
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB)
ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);
#elif defined(BOARD_HAS_LORA)
ArduinoCloud.addProperty(led, 1, READWRITE, ON_CHANGE, onLedChange);
ArduinoCloud.addProperty(potentiometer, 2, READ, ON_CHANGE);
#endif

ArduinoCloud.addProperty(seconds, 3, READ, 5 * MINUTES);
#endif
}

#if defined(BOARD_HAS_WIFI)
Expand Down
35 changes: 0 additions & 35 deletions examples/ArduinoIoTCloud_ESP8266/ArduinoIoTCloud_ESP8266.ino

This file was deleted.

5 changes: 0 additions & 5 deletions examples/ArduinoIoTCloud_ESP8266/arduino_secrets.h

This file was deleted.

18 changes: 0 additions & 18 deletions examples/ArduinoIoTCloud_ESP8266/thingProperties.h

This file was deleted.

Loading