From 91c428eda233a1045d4263699f8d848026ae6304 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Fri, 26 Jul 2019 12:18:15 +0200 Subject: [PATCH] wifi --- src/main.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2926c1f..076558d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -122,6 +122,7 @@ void printValues() { void setup() { Serial.begin(115200); + delay(10); ESP_LOGD(TAG, "setup hardware and sensors"); @@ -156,12 +157,18 @@ void setup() helloWorld(); display.powerOff(); - ESP_LOGD(TAG, "starting WiFi"); + ESP_LOGD(TAG, "connecting to WiFi"); + WiFi.setHostname("esp32-weatherstation"); + wifiMulti.addAP(WIFI_SSID, WIFI_PASSWD); wifiMulti.addAP(WIFI_SSID2, WIFI_PASSWD2); - Serial.println("Connecting Wifi..."); + for (int tries=0; wifiMulti.run() != WL_CONNECTED && tries < 10; tries++) { + Serial.print("."); + delay(500); + } + if(wifiMulti.run() == WL_CONNECTED) { Serial.println(""); Serial.println("WiFi connected"); @@ -171,7 +178,9 @@ void setup() } ESP_LOGD(TAG, "trying to fetch over-the-air update"); - ota.update(); + if (WiFi.status() == WL_CONNECTED) { + ota.update(); + } ESP_LOGD(TAG, "connecting to MQTT"); mqtt.begin();