Skip to content

Commit a3b2b67

Browse files
committed
Add example sketch for cloud schedule property
1 parent ad9b106 commit a3b2b67

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
This sketch demonstrates how to use cloud schedule data type.
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+
- Nano 33 IoT
11+
- ESP 8266
12+
*/
13+
14+
#include "arduino_secrets.h"
15+
#include "thingProperties.h"
16+
17+
#if defined(ESP32)
18+
static int const LED_BUILTIN = 2;
19+
#endif
20+
21+
void setup() {
22+
/* Initialize serial and wait up to 5 seconds for port to open */
23+
Serial.begin(9600);
24+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
25+
26+
/* Configure LED pin as an output */
27+
pinMode(LED_BUILTIN, OUTPUT);
28+
29+
/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
30+
initProperties();
31+
32+
/* Initialize Arduino IoT Cloud library */
33+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
34+
35+
setDebugMessageLevel(DBG_INFO);
36+
ArduinoCloud.printDebugInfo();
37+
38+
/* Configure a schedule for LED. This should be done with Arduino create Scheduler widget */
39+
unsigned int startingFrom = 1635786000; /* From 01/11/2021 17:00 */
40+
unsigned int untilTo = startingFrom + ( DAYS * 28 ); /* To 29/11/2021 17:00 */
41+
unsigned int executionPeriod = MINUTES * 6; /* For 6 minutes */
42+
unsigned int scheduleConfiguration = 134217770; /* On monday wednesday and friday */
43+
44+
led = Schedule(startingFrom, untilTo, executionPeriod, scheduleConfiguration);
45+
}
46+
47+
void loop() {
48+
ArduinoCloud.update();
49+
50+
/* Activate LED when schedule is active */
51+
digitalWrite(LED_BUILTIN, led.isActive());
52+
53+
}
54+
Lines changed: 34 additions & 0 deletions
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
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
9+
bool switchButton;
10+
CloudSchedule led;
11+
12+
void initProperties() {
13+
#if defined(BOARD_ESP8266)
14+
ArduinoCloud.setBoardId(BOARD_ID);
15+
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
16+
#endif
17+
ArduinoCloud.setThingId(THING_ID);
18+
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB)
19+
ArduinoCloud.addProperty(switchButton, WRITE, ON_CHANGE);
20+
ArduinoCloud.addProperty(led, READWRITE, ON_CHANGE);
21+
#elif defined(BOARD_HAS_LORA)
22+
ArduinoCloud.addProperty(switchButton, 1, WRITE, ON_CHANGE;
23+
ArduinoCloud.addProperty(led, 2, READWRITE, ON_CHANGE);
24+
#endif
25+
}
26+
27+
#if defined(BOARD_HAS_WIFI)
28+
WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);
29+
#elif defined(BOARD_HAS_GSM)
30+
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
31+
#elif defined(BOARD_HAS_LORA)
32+
LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A);
33+
#elif defined(BOARD_HAS_NB)
34+
NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
35+
#endif

0 commit comments

Comments
 (0)