2018-06-23 21:49:11 +02:00
|
|
|
/*
|
2018-06-24 12:13:46 +02:00
|
|
|
* To upload through terminal you can use: curl -F "image=@firmware.bin" http://<ip>:8080/update
|
2018-06-24 12:01:58 +02:00
|
|
|
*
|
|
|
|
*
|
2018-06-24 12:03:05 +02:00
|
|
|
* bin file location on windows: C:\Users\<your username>\AppData\Local\Temp\arduino_build_<id>
|
2018-06-24 12:01:58 +02:00
|
|
|
*/
|
2018-06-23 21:49:11 +02:00
|
|
|
|
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
#include <WiFiClient.h>
|
|
|
|
#include <ESP8266WebServer.h>
|
|
|
|
#include <ESP8266mDNS.h>
|
|
|
|
#include <ESP8266HTTPUpdateServer.h>
|
|
|
|
|
|
|
|
ESP8266WebServer httpServer(8080);
|
|
|
|
ESP8266HTTPUpdateServer httpUpdater;
|
|
|
|
|
2018-07-11 11:49:58 +02:00
|
|
|
String ip = "127.0.0.1";
|
|
|
|
String dev = "unknown";
|
|
|
|
float sensValues[6];
|
|
|
|
|
2018-06-23 21:49:11 +02:00
|
|
|
void setupWebUpdater(void)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
Serial.println();
|
|
|
|
Serial.println("Starting WebUpdater...");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
httpUpdater.setup(&httpServer);
|
2018-07-11 11:49:58 +02:00
|
|
|
|
|
|
|
httpServer.on("/", showHTMLMain); // oko specific site
|
|
|
|
|
2018-06-23 21:49:11 +02:00
|
|
|
httpServer.begin();
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
Serial.println("HTTPUpdateServer ready!");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void doWebUpdater(void)
|
|
|
|
{
|
|
|
|
digitalWrite(D0, HIGH);
|
|
|
|
httpServer.handleClient();
|
|
|
|
}
|
2018-07-11 11:49:58 +02:00
|
|
|
|
|
|
|
void setSensorData(String device, String localip, float sensorValues[]) {
|
|
|
|
dev = device;
|
|
|
|
ip = localip;
|
|
|
|
for (uint8_t i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
sensValues[i] = sensorValues[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void showHTMLMain(void) {
|
2018-07-11 12:09:29 +02:00
|
|
|
String message = "<html><head><title>OKO Weatherstation - " + String(dev) + "</title>"
|
|
|
|
"<meta http-equiv=\"refresh\" content=\"20\">"
|
|
|
|
"</head><body>"
|
2018-07-11 11:49:58 +02:00
|
|
|
"<br><a href=\"http://" + ip + ":8080/update\">firmware update</a><br><br>"
|
|
|
|
"<table>"
|
|
|
|
"<tr><td>temperature</td><td>" + String(sensValues[SENSOR_TEMPERATURE]) + "</td></tr>"
|
2018-07-11 11:55:58 +02:00
|
|
|
"<tr><td>humidity</td><td>" + String(sensValues[SENSOR_HUMIDITY]) + "</td></tr>"
|
|
|
|
"<tr><td>light</td><td>" + String(sensValues[SENSOR_LIGHT]) + "</td></tr>"
|
|
|
|
"<tr><td>windspeed</td><td>" + String(sensValues[SENSOR_WINDSPEED]) + "</td></tr>"
|
|
|
|
"<tr><td>pressure</td><td>" + String(sensValues[SENSOR_PRESSURE]) + "</td></tr>"
|
|
|
|
"<tr><td>batvoltage</td><td>" + String(sensValues[SENSOR_BAT_VOLTAGE]) + "</td></tr>";
|
2018-07-11 11:49:58 +02:00
|
|
|
"</table>"
|
|
|
|
"</body></html>";
|
|
|
|
|
|
|
|
httpServer.send(200, "text/html", message);
|
|
|
|
}
|
2018-06-23 21:49:11 +02:00
|
|
|
|