Working implementation of the OTA (webbased).

This commit is contained in:
klaute 2018-06-24 12:00:51 +02:00
parent c6f54ebe36
commit f33a9f098e
5 changed files with 45 additions and 42 deletions

BIN
doc/arduinoIDE_settings.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View file

@ -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";

View file

@ -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);
}
/**/
}
//*************************************************************************//

View file

@ -1,5 +1,7 @@
/*
To upload through terminal you can use: curl -F "image=@firmware.bin" esp8266-webupdate.local/update
Windows: C:\Users\<your username>\AppData\Local\Temp\arduino_build_<id>
*/
#include <ESP8266WiFi.h>

View file

@ -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
}
}
}