Added the webbased OTA update mechanism.
This commit is contained in:
parent
107d9544c0
commit
b03df134c5
4 changed files with 76 additions and 50 deletions
|
@ -9,7 +9,7 @@
|
||||||
#define UPDATE_INTERVAL 4
|
#define UPDATE_INTERVAL 4
|
||||||
|
|
||||||
#define STATUS_LED_PIN BUILTIN_LED
|
#define STATUS_LED_PIN BUILTIN_LED
|
||||||
#define ANEMOMETER_PIN D6
|
#define ANEMOMETER_PIN D7
|
||||||
|
|
||||||
#define BME_SCK 13
|
#define BME_SCK 13
|
||||||
#define BME_MISO 12
|
#define BME_MISO 12
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
|
||||||
|
#include <WiFiClient.h>
|
||||||
|
#include <ESP8266mDNS.h>
|
||||||
|
#include <ESP8266HTTPUpdateServer.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
@ -11,22 +14,6 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
<<<<<<< HEAD
|
|
||||||
Whishlist:
|
|
||||||
- Webserver for /metrics endpoint (Prometheus)
|
|
||||||
- Show current sensor values over simple webpage
|
|
||||||
- Push sensor values to various 3rd party services (https://openweathermap.org/)
|
|
||||||
- MQTT?
|
|
||||||
|
|
||||||
- Buffer sensor values if there is no WIFI connection
|
|
||||||
- Configure weather station over http webinterface
|
|
||||||
- OTA firmware update
|
|
||||||
|
|
||||||
TODO:
|
|
||||||
- https://sminghub.github.io/Sming/about/
|
|
||||||
- https://github.com/marvinroger/homie-esp8266
|
|
||||||
*/
|
|
||||||
=======
|
|
||||||
* Whishlist:
|
* Whishlist:
|
||||||
* - Webserver for /metrics endpoint (Prometheus)
|
* - Webserver for /metrics endpoint (Prometheus)
|
||||||
* - Show current sensor values over simple webpage
|
* - Show current sensor values over simple webpage
|
||||||
|
@ -41,24 +28,22 @@
|
||||||
* - https://sminghub.github.io/Sming/about/
|
* - https://sminghub.github.io/Sming/about/
|
||||||
* - https://github.com/marvinroger/homie-esp8266
|
* - https://github.com/marvinroger/homie-esp8266
|
||||||
*/
|
*/
|
||||||
>>>>>>> d5aee1ca54127dd46df8934c2512bcf1b9cc1bfa
|
|
||||||
|
|
||||||
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;
|
||||||
Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
|
Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
|
||||||
Adafruit_APDS9960 apds;
|
Adafruit_APDS9960 apds;
|
||||||
Adafruit_BME280 bme;
|
Adafruit_BME280 bme;
|
||||||
|
|
||||||
|
boolean webUpdaterEnabled = false;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//WiFi.disconnect(); // enable to remove the wifi credentials
|
|
||||||
|
|
||||||
// Pin settings
|
// Pin settings
|
||||||
pinMode(STATUS_LED_PIN, OUTPUT);
|
pinMode(STATUS_LED_PIN, OUTPUT);
|
||||||
//pinMode(ANEMOMETER_PIN, INPUT_PULLUP);
|
//pinMode(ANEMOMETER_PIN, INPUT_PULLUP);
|
||||||
|
@ -96,6 +81,14 @@ void setup() {
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
|
if (webUpdaterEnabled == true)
|
||||||
|
{
|
||||||
|
doWebUpdater();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
doWebserver();
|
||||||
|
|
||||||
digitalWrite(STATUS_LED_PIN, LOW);
|
digitalWrite(STATUS_LED_PIN, LOW);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -103,7 +96,6 @@ void loop() {
|
||||||
digitalWrite(STATUS_LED_PIN, HIGH);
|
digitalWrite(STATUS_LED_PIN, HIGH);
|
||||||
#endif
|
#endif
|
||||||
currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
|
currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
|
||||||
<<<<<<< HEAD
|
|
||||||
currentSensorData[SENSOR_HUMIDITY] = fetchHumidity();
|
currentSensorData[SENSOR_HUMIDITY] = fetchHumidity();
|
||||||
currentSensorData[SENSOR_LIGHT] = fetchLight();
|
currentSensorData[SENSOR_LIGHT] = fetchLight();
|
||||||
currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed();
|
currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed();
|
||||||
|
@ -122,31 +114,4 @@ void loop() {
|
||||||
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
||||||
|
|
||||||
delay(UPDATE_INTERVAL * 1000);
|
delay(UPDATE_INTERVAL * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
=======
|
|
||||||
Serial.print("*");
|
|
||||||
currentSensorData[SENSOR_HUMIDITY] = fetchHumidity();
|
|
||||||
Serial.print("*");
|
|
||||||
currentSensorData[SENSOR_LIGHT] = fetchLight();
|
|
||||||
Serial.print("*");
|
|
||||||
currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed();
|
|
||||||
Serial.print("*");
|
|
||||||
currentSensorData[SENSOR_PRESSURE] = fetchPressure();
|
|
||||||
Serial.println("*");
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.println("");
|
|
||||||
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");
|
|
||||||
Serial.println("Windspeed: " + String(currentSensorData[SENSOR_WINDSPEED]) + " Km/h");
|
|
||||||
Serial.println("Pressure: " + String(currentSensorData[SENSOR_PRESSURE]) + " hPa");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
|
||||||
|
|
||||||
delay(UPDATE_INTERVAL*1000);
|
|
||||||
}
|
|
||||||
>>>>>>> d5aee1ca54127dd46df8934c2512bcf1b9cc1bfa
|
|
||||||
|
|
34
firmware/webUpdater.ino
Normal file
34
firmware/webUpdater.ino
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
To upload through terminal you can use: curl -F "image=@firmware.bin" esp8266-webupdate.local/update
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <WiFiClient.h>
|
||||||
|
#include <ESP8266WebServer.h>
|
||||||
|
#include <ESP8266mDNS.h>
|
||||||
|
#include <ESP8266HTTPUpdateServer.h>
|
||||||
|
|
||||||
|
ESP8266WebServer httpServer(8080);
|
||||||
|
ESP8266HTTPUpdateServer httpUpdater;
|
||||||
|
|
||||||
|
void setupWebUpdater(void)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
Serial.println();
|
||||||
|
Serial.println("Starting WebUpdater...");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
httpUpdater.setup(&httpServer);
|
||||||
|
httpServer.begin();
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
Serial.println("HTTPUpdateServer ready!");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void doWebUpdater(void)
|
||||||
|
{
|
||||||
|
digitalWrite(D0, HIGH);
|
||||||
|
httpServer.handleClient();
|
||||||
|
}
|
||||||
|
|
27
firmware/webserver.ino
Normal file
27
firmware/webserver.ino
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
//*************************************************************************//
|
||||||
|
|
||||||
|
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