From b9dedbd055898e276a372f6319d846081865f1b6 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Thu, 8 Mar 2018 15:11:49 +0100 Subject: [PATCH] tidy wifi code --- src/main.cpp | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7e40fd5..3377f59 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,27 +72,6 @@ volatile unsigned long geiger_counts = 0; unsigned long geiger_previousMillis; void ICACHE_FLASH_ATTR sendValues() { - WiFi.forceSleepWake(); - WiFi.mode(WIFI_STA); - wifiMulti.addAP("nether.net", "password1"); - wifiMulti.addAP("LNet", "password2"); - wifiMulti.addAP("Freifunk", ""); - int tries = 0; - while (wifiMulti.run() != WL_CONNECTED) { - tries++; - Serial.print("."); - if (tries > 20) { - Serial.println(" [ERROR]"); - Serial.println("Retrying in 1 minute.."); - delay(postingInterval); - ESP.restart(); - } - delay(500); - } - Serial.println(" [CONNECTED]"); - Serial.print("IP address: "); - Serial.println(WiFi.localIP()); - float temperature = dht.readTemperature(); float humidity = dht.readHumidity(); @@ -176,6 +155,29 @@ void ICACHE_FLASH_ATTR sendValues() { char buffer[500]; array.printTo(buffer, sizeof(buffer)); + WiFi.forceSleepWake(); + delay(1); // yield(); + WiFi.persistent(false); // don't load and save credentials to flash + WiFi.mode(WIFI_STA); + wifiMulti.addAP("nether.net", "password1"); + wifiMulti.addAP("LNet", "password2"); + wifiMulti.addAP("Freifunk", ""); + int tries = 0; + while (wifiMulti.run() != WL_CONNECTED) { + tries++; + Serial.print("."); + if (tries > 20) { + Serial.println(" [ERROR]"); + Serial.println("Retrying in 1 minute.."); + delay(postingInterval); + ESP.restart(); + } + delay(500); + } + Serial.println(" [CONNECTED]"); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); + int httpCode = 0; for (int tries=0; tries<3 && httpCode != HTTP_CODE_CREATED; tries++) { @@ -204,6 +206,7 @@ void ICACHE_FLASH_ATTR sendValues() { WiFi.disconnect(); WiFi.mode(WIFI_OFF); WiFi.forceSleepBegin(); + delay(1); // yield(); }