Skip to content

Commit 50ade91

Browse files
committed
fix: Await Serial
Previous implementation was waiting while "Serial was NOT ready" AND "time passed is GREATER than 5 seconds". This can NEVER be true. Early logs were being missed and Serial had difficulty connecting during debugging. It should have instead been waiting while "Serial was NOT ready" AND "time passed is LESS THAN OR EQUAL TO 5 seconds".
1 parent da82500 commit 50ade91

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
void setup() {
1616
/* Initialize serial and wait up to 5 seconds for port to open */
1717
Serial.begin(9600);
18-
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
18+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
1919

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

examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static int const LED_BUILTIN = 2;
2323
void setup() {
2424
/* Initialize serial and wait up to 5 seconds for port to open */
2525
Serial.begin(9600);
26-
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
26+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
2727

2828
/* Configure LED pin as an output */
2929
pinMode(LED_BUILTIN, OUTPUT);

examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
You don't need any specific Properties to be created in order to demonstrate these functionalities.
1010
Simply create a new Thing and give it 1 arbitrary Property.
11-
Remember that the Thing ID needs to be configured in thingProperties.h
11+
Remember that the Thing ID needs to be configured in thingProperties.h
1212
These events can be very useful in particular cases, for instance to disable a peripheral
1313
or a connected sensor/actuator when no data connection is available, as well as to perform
1414
specific operations on connection or right after properties values are synchronised.
@@ -31,7 +31,7 @@
3131
void setup() {
3232
/* Initialize serial and wait up to 5 seconds for port to open */
3333
Serial.begin(9600);
34-
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
34+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
3535

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

examples/ArduinoIoTCloud-DeferredOTA/ArduinoIoTCloud-DeferredOTA.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool ask_user_via_serial() {
3939
if (Serial.available()) {
4040
char c = Serial.read();
4141
if (c == 'y' || c == 'Y') {
42-
return true;
42+
return true;
4343
}
4444
}
4545
return false;
@@ -56,7 +56,7 @@ bool onOTARequestCallback()
5656
void setup() {
5757
/* Initialize serial and wait up to 5 seconds for port to open */
5858
Serial.begin(9600);
59-
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
59+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
6060

6161
/* Configure LED pin as an output */
6262
pinMode(LED_BUILTIN, OUTPUT);

examples/ArduinoIoTCloud-Schedule/ArduinoIoTCloud-Schedule.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static int const LED_BUILTIN = 2;
1515
void setup() {
1616
/* Initialize the serial port and wait up to 5 seconds for a connection */
1717
Serial.begin(9600);
18-
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
18+
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
1919

2020
/* Configure LED pin as an output */
2121
pinMode(LED_BUILTIN, OUTPUT);
@@ -206,7 +206,7 @@ void loop() {
206206
if(daily.isActive()) {
207207
Serial.println("Daily schedule is active");
208208
}
209-
209+
210210
/* Activate LED when the weekly schedule is active */
211211
digitalWrite(LED_BUILTIN, weekly.isActive());
212212

examples/utility/ArduinoIoTCloud_Travis_CI/ArduinoIoTCloud_Travis_CI.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void setup() {
1818

1919
Serial.begin(9600);
2020
unsigned long serialBeginTime = millis();
21-
while (!Serial && (millis() - serialBeginTime > 5000));
21+
while (!Serial && (millis() - serialBeginTime <= 5000));
2222

2323
Serial.println("Starting Arduino IoT Cloud Example");
2424

0 commit comments

Comments
 (0)