Some code optimizations

This commit is contained in:
Blue Fox 2022-08-21 21:12:34 +02:00
parent 45df5179b8
commit 03dec075d1
2 changed files with 13 additions and 5 deletions

View File

@ -14,7 +14,7 @@ String getHTML(String url) {
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET: %d\n", httpCode);
Serial.printf("[HTTP] GET %d: %s\n", httpCode, url.c_str());
// file found at server
if(httpCode == HTTP_CODE_OK) {

View File

@ -4,12 +4,20 @@
void connectWiFi() { // connect to the wifi with the above defined credentials
if(WiFi.status() == WL_CONNECTED) { return; } // return if not connected
Serial.println("[WiFi] Connecting to WiFi...");
Serial.print("[WiFi] Connecting to WiFi...");
WiFi.begin(wiFiSSID, wiFiPSK);
delay(10000); // pause the program 5 secs to give time for connection
if(WiFi.status() != WL_CONNECTED) { Serial.printf("[WiFi] Failed connecting to WiFi \"%s\".", wiFiSSID); return; }
Serial.printf("[WiFi] Connected to WiFi \"%s\", got IP-Adress ", wiFiSSID);
while(WiFi.status() != WL_CONNECTED) {
delay(2000); Serial.printf(".");
if(WiFi.status() == WL_NO_SSID_AVAIL) {
Serial.println("[WiFi] Failed to connect to WiFi. Reason: WL_NO_SSID_AVAIL");
return;
} else if(WiFi.status() == WL_CONNECT_FAILED) {
Serial.println("[WiFi] Failed to connect to WiFi. Reason: WL_CONNECT_FAILED");
return;
}
}
Serial.printf("\n[WiFi] Connected to WiFi \"%s\", got IP-Adress ", wiFiSSID);
Serial.println(WiFi.localIP());
Serial.println("[NTP] Getting time...");