Browse Source

tidy wifi code

lightsleep
Hendrik Langer 7 years ago
parent
commit
b9dedbd055
  1. 45
      src/main.cpp

45
src/main.cpp

@ -72,27 +72,6 @@ volatile unsigned long geiger_counts = 0;
unsigned long geiger_previousMillis; unsigned long geiger_previousMillis;
void ICACHE_FLASH_ATTR sendValues() { 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 temperature = dht.readTemperature();
float humidity = dht.readHumidity(); float humidity = dht.readHumidity();
@ -176,6 +155,29 @@ void ICACHE_FLASH_ATTR sendValues() {
char buffer[500]; char buffer[500];
array.printTo(buffer, sizeof(buffer)); 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; int httpCode = 0;
for (int tries=0; tries<3 && httpCode != HTTP_CODE_CREATED; tries++) { for (int tries=0; tries<3 && httpCode != HTTP_CODE_CREATED; tries++) {
@ -204,6 +206,7 @@ void ICACHE_FLASH_ATTR sendValues() {
WiFi.disconnect(); WiFi.disconnect();
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);
WiFi.forceSleepBegin(); WiFi.forceSleepBegin();
delay(1); // yield();
} }

Loading…
Cancel
Save