87 lines
2.5 KiB
C++
87 lines
2.5 KiB
C++
/*
|
|
* To upload through terminal you can use: curl -F "image=@firmware.bin" http://<ip>:8080/update
|
|
*
|
|
*
|
|
* bin file location on windows: C:\Users\<your username>\AppData\Local\Temp\arduino_build_<id>
|
|
*/
|
|
|
|
#include <ESP8266WiFi.h>
|
|
#include <ESP8266WebServer.h>
|
|
#include <ESP8266mDNS.h>
|
|
#include <ESP8266HTTPUpdateServer.h>
|
|
|
|
#include <WiFiClient.h>
|
|
#include <WiFiManager.h> // WiFiManager from bib manager
|
|
|
|
ESP8266WebServer httpServer(8080);
|
|
ESP8266HTTPUpdateServer httpUpdater;
|
|
|
|
String _webUpdater_ip = "127.0.0.1";
|
|
String _webUpdater_dev = "unknown";
|
|
float _webUpdater_sensValues[VALUES];
|
|
|
|
void setupWebUpdater(String device, String ip)
|
|
{
|
|
debug("Starting WebUpdater... " + ip);
|
|
_webUpdater_ip = ip;
|
|
_webUpdater_dev = device;
|
|
|
|
httpUpdater.setup(&httpServer);
|
|
|
|
httpServer.on("/", showHTMLMain);
|
|
httpServer.on("/resetWifiManager", resetWifiManager);
|
|
|
|
httpServer.begin();
|
|
|
|
debug("HTTPUpdateServer ready!");
|
|
}
|
|
|
|
void doWebUpdater(void)
|
|
{
|
|
digitalWrite(D0, HIGH);
|
|
httpServer.handleClient();
|
|
}
|
|
|
|
void setSensorData(float sensorValues[]) {
|
|
for (uint8_t i = 0; i < VALUES; i++) {
|
|
_webUpdater_sensValues[i] = sensorValues[i];
|
|
}
|
|
}
|
|
|
|
void showHTMLMain(void) {
|
|
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + "</title>"
|
|
"<meta http-equiv=\"refresh\" content=\"20\">"
|
|
"</head><body>"
|
|
"<br><a href=\"http://" + _webUpdater_ip + ":8080/update\">firmware update</a><br><br>"
|
|
"<table>"
|
|
"<tr><td>temperature</td><td>" + String(_webUpdater_sensValues[SENSOR_TEMPERATURE]) + "</td></tr>"
|
|
"<tr><td>humidity</td><td>" + String(_webUpdater_sensValues[SENSOR_HUMIDITY]) + "</td></tr>"
|
|
"<tr><td>light</td><td>" + String(_webUpdater_sensValues[SENSOR_LIGHT]) + "</td></tr>"
|
|
"<tr><td>windspeed</td><td>" + String(_webUpdater_sensValues[SENSOR_WINDSPEED]) + "</td></tr>"
|
|
"<tr><td>pressure</td><td>" + String(_webUpdater_sensValues[SENSOR_PRESSURE]) + "</td></tr>"
|
|
"<tr><td>batvoltage</td><td>" + String(_webUpdater_sensValues[SENSOR_BAT_VOLTAGE]) + "</td></tr>"
|
|
"</table>"
|
|
"</body></html>";
|
|
|
|
httpServer.send(200, "text/html", message);
|
|
}
|
|
|
|
void resetWifiManager()
|
|
{
|
|
|
|
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + "</title>"
|
|
"<meta http-equiv=\"refresh\" content=\"20\">"
|
|
"</head><body>"
|
|
"Reset WifiManager config.<br>"
|
|
"Rebooting...<br>"
|
|
"</body></html>";
|
|
|
|
httpServer.send(200, "text/html", message);
|
|
|
|
// Erase WiFi Credentials, enable, compile, flash, disable and reflash.
|
|
WiFiManager.resetSettings();
|
|
|
|
delay(5000);
|
|
|
|
ESP.restart();
|
|
}
|