Skip to content

Commit a6d65e4

Browse files
committed
Adding example used in conjunction with Travis CI to verify that no user facing API changes have been made
1 parent 18ce9bb commit a6d65e4

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ install:
2929
- ln -s $PWD $HOME/Arduino/libraries/.
3030
script:
3131
- buildExampleSketch ArduinoIoTCloud_LED_switch
32+
- buildExampleSketch ArduinoIoTCloud_Travis_CI
3233
- buildExampleUtilitySketch Provisioning
3334

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This sketch is used in combination with Travis CI to check if
3+
* unintentional breaking changes are made to the used facing
4+
* Arduino IoT Cloud API.
5+
*/
6+
7+
#include "arduino_secrets.h"
8+
#include "thingProperties.h"
9+
10+
void setup() {
11+
12+
Serial.begin(9600);
13+
unsigned long serialBeginTime = millis();
14+
while (!Serial && (millis() - serialBeginTime > 5000));
15+
16+
Serial.println("Starting Arduino IoT Cloud Example");
17+
18+
initProperties();
19+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
20+
21+
ArduinoCloud.printDebugInfo();
22+
}
23+
24+
void loop() {
25+
ArduinoCloud.update();
26+
27+
}
28+
29+
void onBoolPropertyChange() {
30+
Serial.println("'onBoolPropertyChange'");
31+
}
32+
33+
void onIntPropertyChange() {
34+
Serial.println("'onIntPropertyChange'");
35+
}
36+
37+
void onFloatPropertyChange() {
38+
Serial.println("'onFloatPropertyChange'");
39+
}
40+
41+
void onStringPropertyChange() {
42+
Serial.println("'onStringPropertyChange'");
43+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* (MKR1000, MKR WiFi 1010) */
2+
#define SECRET_SSID "YOUR_WIFI_NETWORK_NAME"
3+
#define SECRET_PASS "YOUR_WIFI_PASSWORD"
4+
5+
/* MKR GSM 1400 comment the lines above and uncommet the following. */
6+
#define SECRET_PIN ""
7+
#define SECRET_APN ""
8+
#define SECRET_LOGIN ""
9+
#define SECRET_PASS ""
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/******************************************************************************
2+
* INCLUDE
3+
******************************************************************************/
4+
5+
#include <ArduinoIoTCloud.h>
6+
#include <ConnectionManager.h>
7+
8+
#if defined(BOARD_HAS_WIFI)
9+
#include <WiFiConnectionManager.h>
10+
#elif defined(BOARD_HAS_GSM)
11+
#include <GSMConnectionManager.h>
12+
#else
13+
#error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010 and MKR GSM 1400"
14+
#endif
15+
16+
/******************************************************************************
17+
* DEFINES
18+
******************************************************************************/
19+
20+
#define THING_ID "ARDUINO_IOT_CLOUD_THING_ID"
21+
22+
/******************************************************************************
23+
* GLOBAL CONSTANTS
24+
******************************************************************************/
25+
26+
int const MIN_DELTA_INT_PROPERTY = 5;
27+
float const MIN_DELTA_FLOAT_PROPERTY = 10.0f;
28+
29+
/******************************************************************************
30+
* GLOBAL VARIABLES
31+
******************************************************************************/
32+
33+
bool bool_property_1;
34+
bool bool_property_2;
35+
36+
int int_property_1;
37+
int int_property_2;
38+
int int_property_3;
39+
int int_property_4;
40+
int int_property_5;
41+
int int_property_6;
42+
43+
float float_property_1;
44+
float float_property_2;
45+
float float_property_3;
46+
float float_property_4;
47+
48+
String str_property_1;
49+
String str_property_2;
50+
String str_property_3;
51+
String str_property_4;
52+
String str_property_5;
53+
String str_property_6;
54+
String str_property_7;
55+
String str_property_8;
56+
57+
#if defined(BOARD_HAS_WIFI)
58+
ConnectionManager * ArduinoIoTPreferredConnection = new WiFiConnectionManager(SECRET_SSID, SECRET_PASS);
59+
#elif defined(BOARD_HAS_GSM)
60+
ConnectionManager * ArduinoIoTPreferredConnection = new GSMConnectionManager (SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
61+
#endif
62+
63+
/******************************************************************************
64+
* PROTOTYPES
65+
******************************************************************************/
66+
67+
void onBoolPropertyChange ();
68+
void onIntPropertyChange ();
69+
void onFloatPropertyChange ();
70+
void onStringPropertyChange();
71+
72+
/******************************************************************************
73+
* FUNCTIONS
74+
******************************************************************************/
75+
76+
void initProperties() {
77+
ArduinoCloud.setThingId(THING_ID);
78+
79+
ArduinoCloud.addProperty(bool_property_1, READWRITE, 1*SECONDS);
80+
ArduinoCloud.addProperty(int_property_1, READ, 2*MINUTES);
81+
ArduinoCloud.addProperty(float_property_1, WRITE, 3*HOURS );
82+
ArduinoCloud.addProperty(str_property_1, READWRITE, 4*DAYS );
83+
84+
ArduinoCloud.addProperty(bool_property_2, Permission::ReadWrite).publishEvery(1*SECONDS);
85+
ArduinoCloud.addProperty(int_property_2, Permission::Read ).publishEvery(1*MINUTES);
86+
ArduinoCloud.addProperty(float_property_2, Permission::Write ).publishEvery(3*HOURS );
87+
ArduinoCloud.addProperty(str_property_2, Permission::ReadWrite).publishEvery(4*DAYS );
88+
89+
ArduinoCloud.addProperty(int_property_3, READWRITE, ON_CHANGE); /* Default 'minDelta' = 0 */
90+
ArduinoCloud.addProperty(int_property_4, READWRITE, ON_CHANGE, onIntPropertyChange); /* Default 'minDelta' = 0 */
91+
ArduinoCloud.addProperty(int_property_5, READWRITE, ON_CHANGE, 0 /* onIntPropertyChange */, MIN_DELTA_INT_PROPERTY);
92+
ArduinoCloud.addProperty(int_property_6, READWRITE, ON_CHANGE, onIntPropertyChange, MIN_DELTA_INT_PROPERTY);
93+
94+
ArduinoCloud.addProperty(float_property_3, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY);
95+
ArduinoCloud.addProperty(float_property_4, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY).onUpdate(onFloatPropertyChange);
96+
97+
ArduinoCloud.addProperty(str_property_3, READWRITE, 1*SECONDS, 0 /* onStringPropertyChange */, "" /* 'minDelta' */, MOST_RECENT_WINS);
98+
ArduinoCloud.addProperty(str_property_4, READWRITE, 1*SECONDS, 0 /* onStringPropertyChange */, "" /* 'minDelta' */, CLOUD_WINS);
99+
ArduinoCloud.addProperty(str_property_5, READWRITE, 1*SECONDS, 0 /* onStringPropertyChange */, "" /* 'minDelta' */, DEVICE_WINS);
100+
101+
ArduinoCloud.addProperty(str_property_6, Permission::ReadWrite).publishEvery(1*SECONDS).onSync(MOST_RECENT_WINS);
102+
ArduinoCloud.addProperty(str_property_7, Permission::ReadWrite).publishEvery(1*SECONDS).onSync(CLOUD_WINS);
103+
ArduinoCloud.addProperty(str_property_8, Permission::ReadWrite).publishEvery(1*SECONDS).onSync(DEVICE_WINS);
104+
}

0 commit comments

Comments
 (0)