Skip to content

Commit 30d9365

Browse files
authored
Merge pull request #110 from arduino-libraries/cleanup-examples
Cleaning up examples
2 parents 2d60fea + 9015940 commit 30d9365

25 files changed

+235
-251
lines changed

Diff for: .travis.yml

+26-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ matrix:
55
- BOARD="arduino:samd:mkr1000"
66
- env:
77
- BOARD="arduino:samd:mkrwifi1010"
8+
- env:
9+
- BOARD="arduino:samd:nano_33_iot"
810
- env:
911
- BOARD="arduino:samd:mkrgsm1400"
1012
- env:
@@ -77,32 +79,43 @@ install:
7779
- mkdir -p $HOME/Arduino/libraries
7880
- ln -s $PWD $HOME/Arduino/libraries/.
7981
script:
82+
# Sketches to build for all boards
8083
- |
81-
if [ "$BOARD" == "arduino:samd:mkr1000" ] || [ "$BOARD" == "arduino:samd:mkrwifi1010" ] || [ "$BOARD" == "arduino:samd:mkrgsm1400" ] || [ "$BOARD" == "arduino:samd:mkrnb1500" ]; then
84+
if [ "$BOARD" == "arduino:samd:mkr1000" ] || \
85+
[ "$BOARD" == "arduino:samd:mkrwifi1010" ] || \
86+
[ "$BOARD" == "esp8266:esp8266:huzzah" ] || \
87+
[ "$BOARD" == "arduino:samd:nano_33_iot"] || \
88+
[ "$BOARD" == "arduino:samd:mkrgsm1400" ] || \
89+
[ "$BOARD" == "arduino:samd:mkrnb1500" ] || \
90+
[ "$BOARD" == "arduino:samd:mkrwan1300" ]; then
8291
buildSketch \
83-
"ArduinoIoTCloud_LED_switch" \
84-
"ArduinoIoTCloud_Travis_CI" \
85-
"utility/Provisioning"
92+
"ArduinoIoTCloud-Advanced" \
93+
"ArduinoIoTCloud-Basic" \
94+
"utility/ArduinoIoTCloud_Travis_CI"
8695
fi
96+
# Sketches to build for selected boards
8797
- |
88-
if [ "$BOARD" == "arduino:samd:mkrwan1300" ]; then
98+
if [ "$BOARD" == "arduino:samd:mkr1000" ] || [ "$BOARD" == "arduino:samd:mkrwifi1010" ] || [ "$BOARD" == "arduino:samd:nano_33_iot"]; then
8999
buildSketch \
90-
"ArduinoIoTCloud_LED_switch" \
91-
"ArduinoIoTCloud_Travis_CI"
100+
"utility/Provisioning" \
101+
"utility/WiFi_Cloud_Blink"
92102
fi
93103
- |
94-
if [ "$BOARD" == "arduino:samd:mkr1000" ] || [ "$BOARD" == "arduino:samd:mkrwifi1010" ]; then
104+
if [ "$BOARD" == "arduino:samd:mkrgsm1400" ]; then
95105
buildSketch \
96-
"WiFi_Cloud_Blink" \
97-
"MultiValue_example"
106+
"utility/Provisioning" \
107+
"utility/GSM_Cloud_Blink"
98108
fi
99109
- |
100-
if [ "$BOARD" == "arduino:samd:mkrgsm1400" ]; then
101-
buildSketch "GSM_Cloud_Blink"
110+
if [ "$BOARD" == "arduino:samd:mkrnb1500" ]; then
111+
buildSketch \
112+
"utility/Provisioning" \
113+
"utility/NB_Cloud_Blink"
102114
fi
103115
- |
104116
if [ "$BOARD" == "esp8266:esp8266:huzzah" ]; then
105-
buildSketch "ArduinoIoTCloud_ESP8266"
117+
buildSketch \
118+
"utility/WiFi_Cloud_Blink_with_security_credentials"
106119
fi
107120
notifications:
108121
webhooks:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
This sketch demonstrates how to use more complex cloud data types such as a colour or coordinates.
3+
4+
This sketch is compatible with:
5+
- MKR 1000
6+
- MKR WIFI 1010
7+
- MKR GSM 1400
8+
- MKR NB 1500
9+
- MKR WAN 1300/1310
10+
- ESP 8266
11+
*/
12+
13+
#include "arduino_secrets.h"
14+
#include "thingProperties.h"
15+
16+
void setup() {
17+
/* Initialize serial and wait up to 5 seconds for port to open */
18+
Serial.begin(9600);
19+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
20+
21+
/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
22+
initProperties();
23+
24+
/* Initialize Arduino IoT Cloud library */
25+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
26+
27+
setDebugMessageLevel(DBG_INFO);
28+
ArduinoCloud.printDebugInfo();
29+
}
30+
31+
float latMov = 45.5058224, lonMov = 9.1628673;
32+
float latArd = 45.0502078, lonArd = 7.6674765;
33+
34+
float hueRed = 0.0, satRed = 100.0, briRed = 100.0;
35+
float hueGreen = 80.0, satGreen = 100.0, briGreen = 100.0;
36+
37+
void loop() {
38+
ArduinoCloud.update();
39+
}
40+
41+
void onSwitchButtonChange() {
42+
if (switchButton)
43+
{
44+
location = Location(latMov, lonMov);
45+
color = Color(hueRed, satRed, briRed);
46+
}
47+
else
48+
{
49+
location = Location(latArd, lonArd);
50+
color = Color(hueGreen, satGreen, briGreen);
51+
}
52+
}
53+
54+
void onColorChange() {
55+
Serial.print("Hue = ");
56+
Serial.println(color.getValue().hue);
57+
Serial.print("Sat = ");
58+
Serial.println(color.getValue().sat);
59+
Serial.print("Bri = ");
60+
Serial.println(color.getValue().bri);
61+
}

Diff for: examples/ArduinoIoTCloud_Travis_CI/arduino_secrets.h renamed to examples/ArduinoIoTCloud-Advanced/arduino_secrets.h

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
#define SECRET_PASS "YOUR_WIFI_PASSWORD"
77
#endif
88

9+
/* ESP8266 */
10+
#if defined(BOARD_ESP8266)
11+
#define SECRET_DEVICE_KEY "my-device-password"
12+
#endif
13+
914
/* MKR GSM 1400 */
1015
#if defined(BOARD_HAS_GSM)
1116
#define SECRET_PIN ""

Diff for: examples/ArduinoIoTCloud-Advanced/thingProperties.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <ArduinoIoTCloud.h>
2+
#include <Arduino_ConnectionHandler.h>
3+
4+
#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
5+
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
6+
7+
void onSwitchButtonChange();
8+
void onColorChange();
9+
10+
bool switchButton;
11+
CloudLocation location;
12+
CloudColor color;
13+
14+
void initProperties() {
15+
#if defined(BOARD_ESP8266)
16+
ArduinoCloud.setBoardId(BOARD_ID);
17+
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
18+
#endif
19+
ArduinoCloud.setThingId(THING_ID);
20+
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB)
21+
ArduinoCloud.addProperty(switchButton, WRITE, ON_CHANGE, onSwitchButtonChange);
22+
ArduinoCloud.addProperty(location, READ, ON_CHANGE);
23+
ArduinoCloud.addProperty(color, READWRITE, ON_CHANGE, onColorChange);
24+
#elif defined(BOARD_HAS_LORA)
25+
ArduinoCloud.addProperty(switchButton, 1, WRITE, ON_CHANGE, onSwitchButtonChange);
26+
ArduinoCloud.addProperty(location, 2, READ, ON_CHANGE);
27+
ArduinoCloud.addProperty(color, 3, READWRITE, ON_CHANGE, onColorChange);
28+
#endif
29+
}
30+
31+
#if defined(BOARD_HAS_WIFI)
32+
WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);
33+
#elif defined(BOARD_HAS_GSM)
34+
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
35+
#elif defined(BOARD_HAS_LORA)
36+
LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, _lora_class::CLASS_A);
37+
#elif defined(BOARD_HAS_NB)
38+
NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
39+
#endif
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 and Lora enabled boards supported by Arduino IoT Cloud.
10+
On a LoRa board, if it is configuered as a class A device (default and preferred option), values from Cloud dashboard are received
11+
only after a value is sent to Cloud.
12+
13+
This sketch is compatible with:
14+
- MKR 1000
15+
- MKR WIFI 1010
16+
- MKR GSM 1400
17+
- MKR NB 1500
18+
- MKR WAN 1300/1310
19+
- ESP 8266
20+
*/
21+
22+
#include "arduino_secrets.h"
23+
#include "thingProperties.h"
24+
25+
void setup() {
26+
/* Initialize serial and wait up to 5 seconds for port to open */
27+
Serial.begin(9600);
28+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
29+
30+
/* Configure LED pin as an output */
31+
pinMode(LED_BUILTIN, OUTPUT);
32+
33+
/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
34+
initProperties();
35+
36+
/* Initialize Arduino IoT Cloud library */
37+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
38+
39+
setDebugMessageLevel(DBG_INFO);
40+
ArduinoCloud.printDebugInfo();
41+
}
42+
43+
void loop() {
44+
ArduinoCloud.update();
45+
potentiometer = analogRead(A0);
46+
seconds = millis() / 1000;
47+
}
48+
49+
/*
50+
* 'onLedChange' is called when the "led" property of your Thing changes
51+
*/
52+
void onLedChange() {
53+
Serial.print("LED set to ");
54+
Serial.println(led);
55+
digitalWrite(LED_BUILTIN, led);
56+
}

Diff for: examples/ArduinoIoTCloud-Basic/arduino_secrets.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <Arduino_ConnectionHandler.h>
2+
3+
/* MKR1000, MKR WiFi 1010 */
4+
#if defined(BOARD_HAS_WIFI)
5+
#define SECRET_SSID "YOUR_WIFI_NETWORK_NAME"
6+
#define SECRET_PASS "YOUR_WIFI_PASSWORD"
7+
#endif
8+
9+
/* ESP8266 */
10+
#if defined(BOARD_ESP8266)
11+
#define SECRET_DEVICE_KEY "my-device-password"
12+
#endif
13+
14+
/* MKR GSM 1400 */
15+
#if defined(BOARD_HAS_GSM)
16+
#define SECRET_PIN ""
17+
#define SECRET_APN ""
18+
#define SECRET_LOGIN ""
19+
#define SECRET_PASS ""
20+
#endif
21+
22+
/* MKR WAN 1300/1310 */
23+
#if defined(BOARD_HAS_LORA)
24+
#define SECRET_APP_EUI ""
25+
#define SECRET_APP_KEY ""
26+
#endif
27+
28+
/* MKR NB 1500 */
29+
#if defined(BOARD_HAS_NB)
30+
#define SECRET_PIN ""
31+
#define SECRET_APN ""
32+
#define SECRET_LOGIN ""
33+
#define SECRET_PASS ""
34+
#endif

Diff for: examples/ArduinoIoTCloud_LED_switch/thingProperties.h renamed to examples/ArduinoIoTCloud-Basic/thingProperties.h

+14-9
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,30 @@
99
#error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010, MKR WAN 1300/1310, MKR NB 1500 and MKR GSM 1400"
1010
#endif
1111

12-
13-
// Your THING_ID
14-
#define THING_ID "ARDUINO_IOT_CLOUD_THING_ID"
12+
#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
13+
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1514

1615
void onLedChange();
1716

1817
bool led;
1918
int potentiometer;
19+
int seconds;
2020

2121
void initProperties() {
22+
#if defined(BOARD_ESP8266)
23+
ArduinoCloud.setBoardId(BOARD_ID);
24+
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
25+
#endif
2226
ArduinoCloud.setThingId(THING_ID);
23-
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM)
24-
ArduinoCloud.addProperty(led, READWRITE, ON_CHANGE, onLedChange);
25-
ArduinoCloud.addProperty(potentiometer, READ, ON_CHANGE);
26-
#elif defined(BOARD_HAS_LORA)
27+
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB)
28+
ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
29+
ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
30+
ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);
31+
#elif defined(BOARD_HAS_LORA)
2732
ArduinoCloud.addProperty(led, 1, READWRITE, ON_CHANGE, onLedChange);
2833
ArduinoCloud.addProperty(potentiometer, 2, READ, ON_CHANGE);
29-
#endif
30-
34+
ArduinoCloud.addProperty(seconds, 3, READ, 5 * MINUTES);
35+
#endif
3136
}
3237

3338
#if defined(BOARD_HAS_WIFI)

Diff for: examples/ArduinoIoTCloud_ESP8266/ArduinoIoTCloud_ESP8266.ino

-35
This file was deleted.

Diff for: examples/ArduinoIoTCloud_ESP8266/arduino_secrets.h

-5
This file was deleted.

Diff for: examples/ArduinoIoTCloud_ESP8266/thingProperties.h

-18
This file was deleted.

0 commit comments

Comments
 (0)