Big wheaterstation update #2
1 changed files with 69 additions and 103 deletions
|
@ -11,7 +11,7 @@
|
|||
#include <ESP8266HTTPUpdateServer.h>
|
||||
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiManager.h> // WiFiManager from bib manager by tzapu
|
||||
#include <WiFiManager.h> // WiFiManager from bib manager by tzapu
|
||||
|
||||
#include "config.h"
|
||||
#include "config_user.h"
|
||||
|
@ -27,8 +27,8 @@ String _webUpdater_dev = "unknown";
|
|||
float _webUpdater_sensValues[VALUES];
|
||||
|
||||
#define TR_TD_START_STR "<tr><td>"
|
||||
#define TR_TD_END_STR "</td></tr>"
|
||||
#define TD_TD_MID_STR "</td><td>"
|
||||
#define TR_TD_END_STR "</td></tr>"
|
||||
#define TD_TD_MID_STR "</td><td>"
|
||||
|
||||
boolean wuValidData = false;
|
||||
|
||||
|
@ -36,8 +36,7 @@ uint32_t _wifi_reconnect_cnt = 0;
|
|||
|
||||
//*************************************************************************//
|
||||
|
||||
void setupWebUpdater(String device, String ip)
|
||||
{
|
||||
void setupWebUpdater(String device, String ip) {
|
||||
debug("Starting WebUpdater... " + ip);
|
||||
_webUpdater_ip = ip;
|
||||
_webUpdater_dev = device;
|
||||
|
@ -67,41 +66,33 @@ void setupWebUpdater(String device, String ip)
|
|||
|
||||
//*************************************************************************//
|
||||
|
||||
void doWebUpdater(void)
|
||||
{
|
||||
void doWebUpdater(void) {
|
||||
digitalWrite(D0, HIGH);
|
||||
httpServer.handleClient();
|
||||
}
|
||||
|
||||
//*************************************************************************//
|
||||
#ifdef SHOW_SENSOR_DATA_ON_WEBUPDATER_MAIN_PAGE
|
||||
void sentWindspeed(float ws)
|
||||
{
|
||||
void sentWindspeed(float ws) {
|
||||
_webUpdater_sensValues[SENSOR_WINDSPEED] = ws;
|
||||
}
|
||||
#endif
|
||||
|
||||
void setWifiReconnectCnt(uint32_t wrc)
|
||||
{
|
||||
void setWifiReconnectCnt(uint32_t wrc) {
|
||||
_wifi_reconnect_cnt = wrc;
|
||||
}
|
||||
|
||||
#ifdef SHOW_SENSOR_DATA_ON_WEBUPDATER_MAIN_PAGE
|
||||
void setSensorData(float sensorValues[])
|
||||
{
|
||||
void setSensorData(float sensorValues[]) {
|
||||
|
||||
for (uint8_t i = 0; i < 5 and wuValidData == false; i++)
|
||||
{
|
||||
if (sensorValues[i] != 0 and sensorValues[i] != nanf("no value") and (not isnan(sensorValues[i])))
|
||||
{
|
||||
wuValidData = true; // at least one value is not zero, the data
|
||||
for (uint8_t i = 0; i < 5 and wuValidData == false; i++) {
|
||||
if (sensorValues[i] != 0 and sensorValues[i] != nanf("no value") and (not isnan(sensorValues[i]))) {
|
||||
wuValidData = true; // at least one value is not zero, the data
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < VALUES; i++)
|
||||
{
|
||||
if (sensorValues[i] != nanf("no value") and (not isnan(sensorValues[i])))
|
||||
{
|
||||
for (uint8_t i = 0; i < VALUES; i++) {
|
||||
if (sensorValues[i] != nanf("no value") and (not isnan(sensorValues[i]))) {
|
||||
// only copy real float values
|
||||
//debug(String(i) + "=" + String(sensorValues[i]));
|
||||
_webUpdater_sensValues[i] = sensorValues[i];
|
||||
|
@ -112,43 +103,38 @@ void setSensorData(float sensorValues[])
|
|||
|
||||
//*************************************************************************//
|
||||
|
||||
void showHTMLMain(void)
|
||||
{
|
||||
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>"
|
||||
"<meta http-equiv=\"refresh\" content=\"20\">"
|
||||
"</head><body>"
|
||||
"<br><a href=\"http://"
|
||||
+ _webUpdater_ip + ":8080/update\">firmware update</a><br><br>"
|
||||
#ifdef USE_LOGGER
|
||||
"<br><a href=\"http://" + _webUpdater_ip + ":8080/showlog\">logfile</a><br>"
|
||||
"<br><a href=\"http://"
|
||||
+ _webUpdater_ip + ":8080/showlog\">logfile</a><br>"
|
||||
#endif
|
||||
#ifdef DEBUG_WINDSPEED_MEASUREMENT
|
||||
"<br><a href=\"http://" + _webUpdater_ip + ":8080/measWind\">manual wind measurement</a><br>"
|
||||
"<br><a href=\"http://"
|
||||
+ _webUpdater_ip + ":8080/measWind\">manual wind measurement</a><br>"
|
||||
#endif
|
||||
#ifdef HOMEBRIDGE_WEBSTAT
|
||||
"<br><a href=\"http://" + _webUpdater_ip + ":8080/hbWebstat\">homebridge websatt</a><br>"
|
||||
"<br><a href=\"http://"
|
||||
+ _webUpdater_ip + ":8080/hbWebstat\">homebridge websatt</a><br>"
|
||||
#endif
|
||||
#ifdef WEB_RESET
|
||||
"<br><a href=\"http://" + _webUpdater_ip + ":8080/resetESP\">reset ESP</a><br>"
|
||||
"<br><a href=\"http://"
|
||||
+ _webUpdater_ip + ":8080/resetESP\">reset ESP</a><br>"
|
||||
#endif
|
||||
#ifdef SHOW_SENSOR_DATA_ON_WEBUPDATER_MAIN_PAGE
|
||||
"<br><br><table>"
|
||||
TR_TD_START_STR + "temperature" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_TEMPERATURE]) + TR_TD_END_STR
|
||||
TR_TD_START_STR + "humidity" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_HUMIDITY]) + TR_TD_END_STR
|
||||
TR_TD_START_STR + "light" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_LIGHT]) + TR_TD_END_STR
|
||||
TR_TD_START_STR + "windspeed" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_WINDSPEED]) + TR_TD_END_STR
|
||||
TR_TD_START_STR + "pressure" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_PRESSURE]) + TR_TD_END_STR
|
||||
TR_TD_START_STR + "batvoltage" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_BAT_VOLTAGE]) + TR_TD_END_STR
|
||||
TR_TD_START_STR + "millis" + TD_TD_MID_STR + String(millis()) + TR_TD_END_STR
|
||||
TR_TD_START_STR + "valid" + TD_TD_MID_STR + String(wuValidData) + TR_TD_END_STR
|
||||
TR_TD_START_STR + "wifi rssi" + TD_TD_MID_STR + WiFi.RSSI() + TR_TD_END_STR
|
||||
TR_TD_START_STR + "wifi rec cnt" + TD_TD_MID_STR + String(_wifi_reconnect_cnt) + TR_TD_END_STR
|
||||
"</table>"
|
||||
"<br><br><table>" TR_TD_START_STR
|
||||
+ "temperature" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_TEMPERATURE]) + TR_TD_END_STR TR_TD_START_STR + "humidity" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_HUMIDITY]) + TR_TD_END_STR TR_TD_START_STR + "light" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_LIGHT]) + TR_TD_END_STR TR_TD_START_STR + "windspeed" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_WINDSPEED]) + TR_TD_END_STR TR_TD_START_STR + "pressure" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_PRESSURE]) + TR_TD_END_STR TR_TD_START_STR + "batvoltage" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_BAT_VOLTAGE]) + TR_TD_END_STR TR_TD_START_STR + "millis" + TD_TD_MID_STR + String(millis()) + TR_TD_END_STR TR_TD_START_STR + "valid" + TD_TD_MID_STR + String(wuValidData) + TR_TD_END_STR TR_TD_START_STR + "wifi rssi" + TD_TD_MID_STR + WiFi.RSSI() + TR_TD_END_STR TR_TD_START_STR + "wifi rec cnt" + TD_TD_MID_STR + String(_wifi_reconnect_cnt) + TR_TD_END_STR "</table>"
|
||||
#endif
|
||||
#ifndef DISABLE_WIFIMANAGER
|
||||
"<br><br><br><br><br><a href=\"http://" + _webUpdater_ip + ":8080/resetWifiManager\">reset WiFi Manager</a><br>"
|
||||
"<br><br><br><br><br><a href=\"http://"
|
||||
+ _webUpdater_ip + ":8080/resetWifiManager\">reset WiFi Manager</a><br>"
|
||||
#endif
|
||||
"</body></html>";
|
||||
"</body></html>";
|
||||
|
||||
httpServer.send(200, "text/html", message);
|
||||
}
|
||||
|
@ -156,31 +142,10 @@ void showHTMLMain(void)
|
|||
//*************************************************************************//
|
||||
|
||||
#ifdef HOMEBRIDGE_WEBSTAT
|
||||
void hb_webstat_send(void)
|
||||
{
|
||||
void hb_webstat_send(void) {
|
||||
|
||||
String msg = hb_ws_msg_start +
|
||||
hb_ws_msg_temp +
|
||||
String(_webUpdater_sensValues[SENSOR_TEMPERATURE], 2) +
|
||||
", " +
|
||||
hb_ws_msg_humi +
|
||||
String(_webUpdater_sensValues[SENSOR_HUMIDITY], 2) +
|
||||
", " +
|
||||
hb_ws_msg_light +
|
||||
String(_webUpdater_sensValues[SENSOR_LIGHT], 0) + // The light level for the homebridge-http-lux2 plugin is only able to parse integer values
|
||||
", " +
|
||||
hb_ws_msg_windspeed +
|
||||
String(_webUpdater_sensValues[SENSOR_WINDSPEED], 2) +
|
||||
", " +
|
||||
hb_ws_msg_pressure +
|
||||
String(_webUpdater_sensValues[SENSOR_PRESSURE], 2) +
|
||||
", " +
|
||||
hb_ws_msg_timestamp +
|
||||
String(millis()) +
|
||||
", " +
|
||||
hb_ws_msg_valid +
|
||||
String(wuValidData) +
|
||||
hb_ws_msg_end;
|
||||
String msg = hb_ws_msg_start + hb_ws_msg_temp + String(_webUpdater_sensValues[SENSOR_TEMPERATURE], 2) + ", " + hb_ws_msg_humi + String(_webUpdater_sensValues[SENSOR_HUMIDITY], 2) + ", " + hb_ws_msg_light + String(_webUpdater_sensValues[SENSOR_LIGHT], 0) + // The light level for the homebridge-http-lux2 plugin is only able to parse integer values
|
||||
", " + hb_ws_msg_windspeed + String(_webUpdater_sensValues[SENSOR_WINDSPEED], 2) + ", " + hb_ws_msg_pressure + String(_webUpdater_sensValues[SENSOR_PRESSURE], 2) + ", " + hb_ws_msg_timestamp + String(millis()) + ", " + hb_ws_msg_valid + String(wuValidData) + hb_ws_msg_end;
|
||||
|
||||
httpServer.send(200, "text/html", msg);
|
||||
}
|
||||
|
@ -190,19 +155,23 @@ void hb_webstat_send(void)
|
|||
|
||||
#ifdef WEB_RESET
|
||||
|
||||
void resetESP()
|
||||
{
|
||||
void resetESP() {
|
||||
|
||||
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + " - reset WiFi manager</title>"
|
||||
"<meta http-equiv=\"refresh\" content=\"20\">"
|
||||
"</head><body>"
|
||||
"Rebooting...<br>"
|
||||
"</body></html>";
|
||||
"<meta http-equiv=\"refresh\" content=\"20\">"
|
||||
"</head><body>"
|
||||
"Rebooting...<br>"
|
||||
"</body></html>";
|
||||
|
||||
httpServer.send(200, "text/html", message);
|
||||
|
||||
delay(5000);
|
||||
|
||||
#ifdef ENABLE_WATCHDOG
|
||||
// loop endless, watchdog will reset the device
|
||||
while (1 == 1) {}
|
||||
#endif
|
||||
|
||||
// manual reset after restart is required
|
||||
ESP.restart();
|
||||
}
|
||||
|
@ -211,15 +180,14 @@ void resetESP()
|
|||
|
||||
#ifndef DISABLE_WIFIMANAGER
|
||||
|
||||
void resetWifiManager()
|
||||
{
|
||||
void resetWifiManager() {
|
||||
|
||||
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + " - reset WiFi manager</title>"
|
||||
"<meta http-equiv=\"refresh\" content=\"20\">"
|
||||
"</head><body>"
|
||||
"Reset WifiManager config.<br>"
|
||||
"Rebooting...<br>"
|
||||
"</body></html>";
|
||||
"<meta http-equiv=\"refresh\" content=\"20\">"
|
||||
"</head><body>"
|
||||
"Reset WifiManager config.<br>"
|
||||
"Rebooting...<br>"
|
||||
"</body></html>";
|
||||
|
||||
httpServer.send(200, "text/html", message);
|
||||
|
||||
|
@ -229,6 +197,10 @@ void resetWifiManager()
|
|||
|
||||
delay(5000);
|
||||
|
||||
#ifdef ENABLE_WATCHDOG
|
||||
// loop endless, watchdog will reset the device
|
||||
while (1 == 1) {}
|
||||
#endif
|
||||
// manual reset after restart is required
|
||||
ESP.restart();
|
||||
}
|
||||
|
@ -239,8 +211,7 @@ void resetWifiManager()
|
|||
|
||||
#ifdef DEBUG_WINDSPEED_MEASUREMENT
|
||||
#ifdef SENSOR_WIND
|
||||
void measureWindspeed()
|
||||
{
|
||||
void measureWindspeed() {
|
||||
|
||||
// read from windspeed sensorSTATUS_LED_PIN
|
||||
digitalWrite(STATUS_LED_PIN, HIGH);
|
||||
|
@ -249,12 +220,12 @@ void measureWindspeed()
|
|||
digitalWrite(STATUS_LED_PIN, LOW);
|
||||
|
||||
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + " - manual wind measurement</title>"
|
||||
"</head><body>"
|
||||
"Windsensor measurement result: " + String(tmp_windspeed) + "<br>"
|
||||
"</body></html>";
|
||||
"</head><body>"
|
||||
"Windsensor measurement result: "
|
||||
+ String(tmp_windspeed) + "<br>"
|
||||
"</body></html>";
|
||||
|
||||
httpServer.send(200, "text/html", message);
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
@ -269,30 +240,25 @@ String logfile[LOGFILE_SIZE];
|
|||
|
||||
uint16_t logger_pos = 0;
|
||||
|
||||
void logdata(String s)
|
||||
{
|
||||
void logdata(String s) {
|
||||
logfile[logger_pos] = s;
|
||||
logger_pos++;
|
||||
|
||||
if (logger_pos > LOGFILE_SIZE -1)
|
||||
{
|
||||
for (uint16_t i = 1; i < LOGFILE_SIZE; i++)
|
||||
{
|
||||
logfile[i-1] = logfile[i]; // overwrite previous element with current element
|
||||
if (logger_pos > LOGFILE_SIZE - 1) {
|
||||
for (uint16_t i = 1; i < LOGFILE_SIZE; i++) {
|
||||
logfile[i - 1] = logfile[i]; // overwrite previous element with current element
|
||||
}
|
||||
logger_pos--; // reduce the position in the log
|
||||
logger_pos--; // reduce the position in the log
|
||||
}
|
||||
}
|
||||
|
||||
void showLog()
|
||||
{
|
||||
void showLog() {
|
||||
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + " - logfile</title>"
|
||||
"<meta http-equiv=\"refresh\" content=\"5\">"
|
||||
"</head><body>"
|
||||
"Logfile data:<br>";
|
||||
"<meta http-equiv=\"refresh\" content=\"5\">"
|
||||
"</head><body>"
|
||||
"Logfile data:<br>";
|
||||
|
||||
for (uint16_t lp = 0; lp < logger_pos; lp++)
|
||||
{
|
||||
for (uint16_t lp = 0; lp < logger_pos; lp++) {
|
||||
message = message + logfile[lp] + "<br>";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue