Working implementation of the OTA (webbased).
This commit is contained in:
parent
c6f54ebe36
commit
f33a9f098e
5 changed files with 45 additions and 42 deletions
BIN
doc/arduinoIDE_settings.png
Normal file
BIN
doc/arduinoIDE_settings.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
|
@ -16,6 +16,8 @@
|
||||||
#define BME_MOSI 11
|
#define BME_MOSI 11
|
||||||
#define BME_CS 10
|
#define BME_CS 10
|
||||||
|
|
||||||
|
#define INITIAL_WEBSERVER_TIME 20
|
||||||
|
|
||||||
#define SEALEVELPRESSURE_HPA (1013.25)
|
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||||
|
|
||||||
#define BME280_ADDRESS 0x76
|
#define BME280_ADDRESS 0x76
|
||||||
|
@ -28,3 +30,4 @@ const char *INFLUXDB_PASS = "de1873a0d2f8f21f17cf4d8db4f65c59";
|
||||||
|
|
||||||
String DEVICE_NAME = "klaute";
|
String DEVICE_NAME = "klaute";
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
//*************************************************************************//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whishlist:
|
* Whishlist:
|
||||||
* - Webserver for /metrics endpoint (Prometheus)
|
* - Webserver for /metrics endpoint (Prometheus)
|
||||||
|
@ -29,6 +31,8 @@
|
||||||
* - https://github.com/marvinroger/homie-esp8266
|
* - https://github.com/marvinroger/homie-esp8266
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//*************************************************************************//
|
||||||
|
|
||||||
float currentSensorData[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
|
float currentSensorData[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
|
||||||
|
|
||||||
WiFiManager wifiManager;
|
WiFiManager wifiManager;
|
||||||
|
@ -37,16 +41,21 @@ Adafruit_APDS9960 apds;
|
||||||
Adafruit_BME280 bme;
|
Adafruit_BME280 bme;
|
||||||
|
|
||||||
boolean webUpdaterEnabled = false;
|
boolean webUpdaterEnabled = false;
|
||||||
|
uint16_t webserver_timeout = 0;
|
||||||
|
|
||||||
|
//*************************************************************************//
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
|
//WiFi.disconnect(); // erase the wifi credentials
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Pin settings
|
// Pin settings
|
||||||
pinMode(STATUS_LED_PIN, OUTPUT);
|
pinMode(STATUS_LED_PIN, OUTPUT);
|
||||||
//pinMode(ANEMOMETER_PIN, INPUT_PULLUP);
|
pinMode(ANEMOMETER_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
// Establish WiFi connection
|
// Establish WiFi connection
|
||||||
String wifiName = "oko-weather-" + String(ESP.getChipId());
|
String wifiName = "oko-weather-" + String(ESP.getChipId());
|
||||||
|
@ -79,20 +88,32 @@ void setup() {
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//*************************************************************************//
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
if (webUpdaterEnabled == true)
|
//if (INITIAL_WEBSERVER_TIME * 1000 > webserver_timeout) {
|
||||||
{
|
|
||||||
doWebUpdater();
|
if (webserver_timeout == 0) {
|
||||||
return;
|
setupWebUpdater();
|
||||||
}
|
}
|
||||||
|
doWebUpdater();
|
||||||
|
|
||||||
doWebserver();
|
#ifdef DEBUG
|
||||||
|
//Serial.print(".");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
webserver_timeout++;
|
||||||
|
//delay(1);
|
||||||
|
|
||||||
|
//return;
|
||||||
|
//}
|
||||||
|
|
||||||
|
/**/
|
||||||
digitalWrite(STATUS_LED_PIN, LOW);
|
digitalWrite(STATUS_LED_PIN, LOW);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.println("---");
|
//Serial.println("---");
|
||||||
digitalWrite(STATUS_LED_PIN, HIGH);
|
digitalWrite(STATUS_LED_PIN, HIGH);
|
||||||
#endif
|
#endif
|
||||||
currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
|
currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
|
||||||
|
@ -103,7 +124,7 @@ void loop() {
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
Serial.println("Current readings:");
|
//Serial.println("Current readings:");
|
||||||
Serial.println("Temperature: " + String(currentSensorData[SENSOR_TEMPERATURE]) + " °C");
|
Serial.println("Temperature: " + String(currentSensorData[SENSOR_TEMPERATURE]) + " °C");
|
||||||
Serial.println("Humidity: " + String(currentSensorData[SENSOR_HUMIDITY]) + " %");
|
Serial.println("Humidity: " + String(currentSensorData[SENSOR_HUMIDITY]) + " %");
|
||||||
Serial.println("Light: " + String(currentSensorData[SENSOR_LIGHT]) + " Lumen");
|
Serial.println("Light: " + String(currentSensorData[SENSOR_LIGHT]) + " Lumen");
|
||||||
|
@ -114,4 +135,8 @@ void loop() {
|
||||||
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
||||||
|
|
||||||
delay(UPDATE_INTERVAL * 1000);
|
delay(UPDATE_INTERVAL * 1000);
|
||||||
|
/**/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//*************************************************************************//
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
/*
|
/*
|
||||||
To upload through terminal you can use: curl -F "image=@firmware.bin" esp8266-webupdate.local/update
|
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>
|
#include <ESP8266WiFi.h>
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue