Add reliable wifi connection #2 #3

This commit is contained in:
Aaron Fischer 2017-11-12 22:34:08 +01:00
parent 458f69ce5a
commit c9fd2ad2ac

View file

@ -1,5 +1,9 @@
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include "config.h"
/**
@ -10,10 +14,8 @@
* - Push sensor values to various 3rd party services
* - MQTT?
*
* - Auto-Reconnect for WIFI
* - Buffer sensor values if there is no WIFI connection
* - Configure weather station over http webinterface
* - If there are now WiFi credentials, open up an access point to configure it
* - OTA firmware update
*
* TODO:
@ -23,30 +25,35 @@
float currentSensorData[4] = {0.0, 0.0, 0.0, 0.0};
void connectToWiFi() {
}
bool checkWiFiConnection() {
return true;
}
WiFiManager wifiManager;
void setup() {
#ifdef DEBUG
Serial.begin(115200);
#endif
// Pin settings
pinMode(STATUS_LED_PIN, OUTPUT);
pinMode(ANEMOMETER_PIN, INPUT_PULLUP);
connectToWiFi();
// Establish wifi connection
String wifiName = "oko-weather-" + String(ESP.getChipId());
wifiManager.setMinimumSignalQuality(15);
if (!wifiManager.autoConnect(wifiName.c_str(), "DEADBEEF")) {
#ifdef DEBUG
Serial.println("WiFi connection failed, we reboot ...");
#endif
ESP.reset();
delay(1000);
}
#ifdef DEBUG
Serial.println("Connected!");
#endif
}
void loop() {
digitalWrite(STATUS_LED_PIN, LOW);
while (!checkWiFiConnection()) {
connectToWiFi();
delay(5000);
}
currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
currentSensorData[SENSOR_HUMIDITY] = fetchHumidity();
@ -64,6 +71,5 @@ void loop() {
pushToInfluxDB(currentSensorData);
delay(UPDATE_INTERVAL*1000);
}