Skip to content

Commit 491f19d

Browse files
authored
Test WiFi status before waiting
Check the return status of `WiFi.begin` before waiting for the delay.
1 parent dc31407 commit 491f19d

File tree

1 file changed

+11
-10
lines changed
  • content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-wifi

1 file changed

+11
-10
lines changed

content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-wifi/giga-wifi.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,12 @@ This code is in the public domain.
375375
#include <WiFiUdp.h>
376376
#include <mbed_mktime.h>
377377
378-
int timezone = -1; //this is GMT -1.
378+
int timezone = -1; //this is GMT -1.
379379
380-
int status = WL_IDLE_STATUS;
381-
382-
char ssid[] = "Flen"; // your network SSID (name)
383-
char pass[] = ""; // your network password (use for WPA, or use as key for WEP)
380+
#include "arduino_secrets.h"
381+
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
382+
char ssid[] = SECRET_SSID; // your network SSID (name)
383+
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
384384
385385
int keyIndex = 0; // your network key index number (needed only for WEP)
386386
@@ -416,11 +416,12 @@ void setup() {
416416
}
417417
418418
// attempt to connect to WiFi network:
419-
while (status != WL_CONNECTED) {
419+
while (true) {
420420
Serial.print("Attempting to connect to SSID: ");
421421
Serial.println(ssid);
422422
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
423-
status = WiFi.begin(ssid, pass);
423+
if (WiFi.begin(ssid, pass) == WL_CONNECTED)
424+
break;
424425
425426
// wait 10 seconds for connection:
426427
delay(10000);
@@ -475,8 +476,8 @@ unsigned long parseNtpPacket() {
475476
const unsigned long secsSince1900 = highWord << 16 | lowWord;
476477
constexpr unsigned long seventyYears = 2208988800UL;
477478
const unsigned long epoch = secsSince1900 - seventyYears;
478-
479-
const unsigned long new_epoch = epoch + (3600 * timezone); //multiply the timezone with 3600 (1 hour)
479+
480+
const unsigned long new_epoch = epoch + (3600 * timezone); //multiply the timezone with 3600 (1 hour)
480481
481482
set_time(new_epoch);
482483
@@ -1660,4 +1661,4 @@ void onMqttMessage(int messageSize) {
16601661
Serial.println();
16611662
Serial.println();
16621663
}
1663-
```
1664+
```

0 commit comments

Comments
 (0)