Skip to content

Commit 5f11cb8

Browse files
Sid23Alberto Iannaccone
authored and
Alberto Iannaccone
committed
Updated example sketch cloud_blink
1 parent 54133c0 commit 5f11cb8

File tree

1 file changed

+56
-10
lines changed

1 file changed

+56
-10
lines changed

examples/MKR1000_Cloud_Blink/MKR1000_Cloud_Blink.ino

+56-10
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,35 @@ unsigned long getTime() {
1313
return WiFi.getTime();
1414
}
1515

16+
// Thing properties
1617
int position;
18+
bool valid = true;
19+
float ratio = 2.47;
20+
String welcome = "ciao";
21+
22+
// Last time when the WiFi connection was checked
23+
unsigned long lastMillis = 0;
1724

1825
void onPositionUpdate() {
1926
Serial.print("New position value: ");
2027
Serial.println(position);
2128
}
2229

30+
void onWelcomeUpdate() {
31+
Serial.print("New state value: ");
32+
Serial.println(welcome);
33+
}
34+
35+
void onValidUpdate() {
36+
Serial.print("New valid value: ");
37+
Serial.println(valid);
38+
}
39+
40+
void onRatioUpdate() {
41+
Serial.print("New ratio value: ");
42+
Serial.println(ratio);
43+
}
44+
2345
void setup() {
2446
//Initialize serial and wait for port to open:
2547
Serial.begin(9600);
@@ -47,7 +69,7 @@ void setup() {
4769
status = WiFi.begin(ssid, pass);
4870

4971
// wait 10 seconds for connection:
50-
delay(10000);
72+
delay(5000);
5173
}
5274

5375
// you're connected now, so print out the data:
@@ -63,21 +85,45 @@ void setup() {
6385
}
6486

6587
Serial.println("Successfully connected to Arduino Cloud :)");
66-
67-
ArduinoCloud.addProperty(position, READ, 10*SECONDS, onPositionUpdate);
88+
ArduinoCloud.addProperty(welcome, READWRITE, ON_CHANGE, onWelcomeUpdate);
89+
ArduinoCloud.addProperty(position, READWRITE, ON_CHANGE, onPositionUpdate);
90+
ArduinoCloud.addProperty(valid, READWRITE, ON_CHANGE, onValidUpdate);
91+
ArduinoCloud.addProperty(ratio, READWRITE, ON_CHANGE, onRatioUpdate);
6892

6993
CloudSerial.begin(9600);
94+
lastMillis = millis();
7095
}
7196

7297
void loop() {
7398
ArduinoCloud.poll();
74-
75-
if (CloudSerial.available()) {
76-
Serial.write(CloudSerial.read());
99+
Serial.println("loop updated");
100+
/*
101+
Serial.println(".");
102+
welcome += "!";
103+
ratio += 0.4355;
104+
valid = !valid;
105+
position += 1;
106+
*/
107+
if (millis() - lastMillis > 20000) {
108+
Serial.println("..Check WiFi status..");
109+
bool error = false;
110+
// Check Wifi status
111+
while (WiFi.status() != WL_CONNECTED) {
112+
error = true;
113+
Serial.print("..Reconnection to connect to WPA SSID: ");
114+
Serial.println(ssid);
115+
status = WiFi.begin(ssid, pass);
116+
// wait 10 seconds for connection:
117+
delay(2000);
118+
}
119+
if(error) {
120+
Serial.println("..Reconnected to the Nework!");
121+
// Call the reconnect method to clean up the ArduinoCloud connection
122+
ArduinoCloud.reconnect(wifiClient);
123+
}
124+
delay(500);
125+
lastMillis = millis();
77126
}
78127

79-
if (Serial.available()) {
80-
CloudSerial.write(Serial.read());
81-
}
128+
delay(2000);
82129
}
83-

0 commit comments

Comments
 (0)