diff --git a/doc/arduinoIDE_settings.png b/doc/arduinoIDE_settings.png new file mode 100644 index 0000000..92c319d Binary files /dev/null and b/doc/arduinoIDE_settings.png differ diff --git a/firmware/config.h b/firmware/config.h index 57f67ca..3c2ae5f 100755 --- a/firmware/config.h +++ b/firmware/config.h @@ -16,15 +16,18 @@ #define BME_MOSI 11 #define BME_CS 10 +#define INITIAL_WEBSERVER_TIME 20 + #define SEALEVELPRESSURE_HPA (1013.25) #define BME280_ADDRESS 0x76 -const char *INFLUXDB_HOST = "influxdb.okoyono.de"; -const uint16_t INFLUXDB_PORT = 80; -const char *INFLUXDB_DB = "weatherstation"; -const char *INFLUXDB_USER = "oko"; -const char *INFLUXDB_PASS = "de1873a0d2f8f21f17cf4d8db4f65c59"; +const char *INFLUXDB_HOST = "influxdb.okoyono.de"; +const uint16_t INFLUXDB_PORT = 80; +const char *INFLUXDB_DB = "weatherstation"; +const char *INFLUXDB_USER = "oko"; +const char *INFLUXDB_PASS = "de1873a0d2f8f21f17cf4d8db4f65c59"; -String DEVICE_NAME = "klaute"; +String DEVICE_NAME = "klaute"; + diff --git a/firmware/firmware.ino b/firmware/firmware.ino index aa8db14..71ebd5a 100755 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -13,6 +13,8 @@ #include "config.h" +//*************************************************************************// + /** * Whishlist: * - Webserver for /metrics endpoint (Prometheus) @@ -29,6 +31,8 @@ * - https://github.com/marvinroger/homie-esp8266 */ +//*************************************************************************// + float currentSensorData[5] = {0.0, 0.0, 0.0, 0.0, 0.0}; WiFiManager wifiManager; @@ -37,16 +41,21 @@ Adafruit_APDS9960 apds; Adafruit_BME280 bme; boolean webUpdaterEnabled = false; +uint16_t webserver_timeout = 0; + +//*************************************************************************// void setup() { + //WiFi.disconnect(); // erase the wifi credentials + #ifdef DEBUG Serial.begin(115200); #endif // Pin settings pinMode(STATUS_LED_PIN, OUTPUT); - //pinMode(ANEMOMETER_PIN, INPUT_PULLUP); + pinMode(ANEMOMETER_PIN, INPUT_PULLUP); // Establish WiFi connection String wifiName = "oko-weather-" + String(ESP.getChipId()); @@ -79,20 +88,32 @@ void setup() { delay(100); } +//*************************************************************************// + void loop() { - if (webUpdaterEnabled == true) - { + //if (INITIAL_WEBSERVER_TIME * 1000 > webserver_timeout) { + + if (webserver_timeout == 0) { + setupWebUpdater(); + } doWebUpdater(); - return; - } - doWebserver(); +#ifdef DEBUG + //Serial.print("."); +#endif + webserver_timeout++; + //delay(1); + + //return; + //} + + /**/ digitalWrite(STATUS_LED_PIN, LOW); #ifdef DEBUG - Serial.println("---"); + //Serial.println("---"); digitalWrite(STATUS_LED_PIN, HIGH); #endif currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature(); @@ -103,7 +124,7 @@ void loop() { #ifdef DEBUG Serial.println(""); - Serial.println("Current readings:"); + //Serial.println("Current readings:"); Serial.println("Temperature: " + String(currentSensorData[SENSOR_TEMPERATURE]) + " °C"); Serial.println("Humidity: " + String(currentSensorData[SENSOR_HUMIDITY]) + " %"); Serial.println("Light: " + String(currentSensorData[SENSOR_LIGHT]) + " Lumen"); @@ -114,4 +135,8 @@ void loop() { pushToInfluxDB(DEVICE_NAME, currentSensorData); delay(UPDATE_INTERVAL * 1000); -} + /**/ +} + +//*************************************************************************// + diff --git a/firmware/webUpdater.ino b/firmware/webUpdater.ino index 9d02762..d4d8561 100644 --- a/firmware/webUpdater.ino +++ b/firmware/webUpdater.ino @@ -1,5 +1,7 @@ /* To upload through terminal you can use: curl -F "image=@firmware.bin" esp8266-webupdate.local/update + + Windows: C:\Users\\AppData\Local\Temp\arduino_build_ */ #include diff --git a/firmware/webserver.ino b/firmware/webserver.ino deleted file mode 100644 index 98aaab2..0000000 --- a/firmware/webserver.ino +++ /dev/null @@ -1,27 +0,0 @@ - -//*************************************************************************// - -WiFiServer server(80); - -void doWebserver(void) -{ - WiFiClient client = server.available(); - if (client) - { - String request = client.readStringUntil('\r'); - - if (request.indexOf("/WU") != -1) - { - setupWebUpdater(); - webUpdaterEnabled = true; // enable the web update mechanism - - } else if (request.indexOf("/RW") != -1) - { - WiFi.disconnect(); // erase the wifi credentials - while(1); // trigger the watchdog - } - - } -} - -