Refactor webUpdater to remove logic from firmware.ino

This commit is contained in:
Florian Eitel 2019-08-04 12:46:42 +02:00
parent ed913d740e
commit 007d2e4e73
No known key found for this signature in database
GPG key ID: 9987EAFEF6F686BB
2 changed files with 21 additions and 31 deletions

View file

@ -55,9 +55,6 @@ uint16_t update_webserver_cnt = 0;
WiFiManager wifiManager;
#ifdef WEBUPDATER_FEATURE
String localIP = "127.0.0.1";
#endif
//*************************************************************************//
void debug(String x) {
@ -144,8 +141,7 @@ void setup() {
#ifdef WEBUPDATER_FEATURE
#ifndef BATTERY_POWERED
setupWebUpdater();
localIP = WiFi.localIP().toString();
setupWebUpdater(DEVICE_NAME, WiFi.localIP().toString());
#endif
#endif
@ -252,7 +248,7 @@ void _loop() {
#endif
#ifdef WEBUPDATER_FEATURE
setSensorData(DEVICE_NAME, localIP, currentSensorData);
setSensorData(currentSensorData);
#endif
}

View file

@ -15,16 +15,15 @@
ESP8266WebServer httpServer(8080);
ESP8266HTTPUpdateServer httpUpdater;
String ip = "127.0.0.1";
String dev = "unknown";
float sensValues[6];
String _webUpdater_ip = "127.0.0.1";
String _webUpdater_dev = "unknown";
float _webUpdater_sensValues[VALUES];
void setupWebUpdater(void)
void setupWebUpdater(String device, String ip)
{
#ifdef DEBUG
Serial.println();
Serial.println("Starting WebUpdater...");
#endif
debug("Starting WebUpdater... " + ip);
_webUpdater_ip = ip;
_webUpdater_dev = device;
httpUpdater.setup(&httpServer);
@ -32,9 +31,7 @@ void setupWebUpdater(void)
httpServer.begin();
#ifdef DEBUG
Serial.println("HTTPUpdateServer ready!");
#endif
debug("HTTPUpdateServer ready!");
}
void doWebUpdater(void)
@ -43,27 +40,24 @@ void doWebUpdater(void)
httpServer.handleClient();
}
void setSensorData(String device, String localip, float sensorValues[]) {
dev = device;
ip = localip;
for (uint8_t i = 0; i < VALUES; i++)
{
sensValues[i] = sensorValues[i];
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(dev) + "</title>"
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + "</title>"
"<meta http-equiv=\"refresh\" content=\"20\">"
"</head><body>"
"<br><a href=\"http://" + ip + ":8080/update\">firmware update</a><br><br>"
"<br><a href=\"http://" + _webUpdater_ip + ":8080/update\">firmware update</a><br><br>"
"<table>"
"<tr><td>temperature</td><td>" + String(sensValues[SENSOR_TEMPERATURE]) + "</td></tr>"
"<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>"
"<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>";