Skip to content

fix: Await Serial #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
void setup() {
/* Initialize serial and wait up to 5 seconds for port to open */
Serial.begin(9600);
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }

/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
initProperties();
Expand Down
2 changes: 1 addition & 1 deletion examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static int const LED_BUILTIN = 2;
void setup() {
/* Initialize serial and wait up to 5 seconds for port to open */
Serial.begin(9600);
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }

/* Configure LED pin as an output */
pinMode(LED_BUILTIN, OUTPUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
initProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool ask_user_via_serial() {
if (Serial.available()) {
char c = Serial.read();
if (c == 'y' || c == 'Y') {
return true;
return true;
}
}
return false;
Expand All @@ -56,7 +56,7 @@ bool onOTARequestCallback()
void setup() {
/* Initialize serial and wait up to 5 seconds for port to open */
Serial.begin(9600);
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }

/* Configure LED pin as an output */
pinMode(LED_BUILTIN, OUTPUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static int const LED_BUILTIN = 2;
void setup() {
/* Initialize the serial port and wait up to 5 seconds for a connection */
Serial.begin(9600);
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }

/* Configure LED pin as an output */
pinMode(LED_BUILTIN, OUTPUT);
Expand Down Expand Up @@ -206,7 +206,7 @@ void loop() {
if(daily.isActive()) {
Serial.println("Daily schedule is active");
}

/* Activate LED when the weekly schedule is active */
digitalWrite(LED_BUILTIN, weekly.isActive());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void setup() {

Serial.begin(9600);
unsigned long serialBeginTime = millis();
while (!Serial && (millis() - serialBeginTime > 5000));
while (!Serial && (millis() - serialBeginTime <= 5000));

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

Expand Down
Loading