/* * To upload through terminal you can use: curl -F "image=@firmware.bin" http://:8080/update * * * bin file location on windows: C:\Users\\AppData\Local\Temp\arduino_build_ */ #include #include #include #include #include #include "config.h" #include "config_user.h" #ifdef USE_WIFIMANAGER #include // WiFiManager from bib manager #endif ESP8266WebServer httpServer(WEB_UPDATER_HTTP_PORT); ESP8266HTTPUpdateServer httpUpdater; String _webUpdater_ip = "127.0.0.1"; String _webUpdater_dev = "unknown"; float _webUpdater_sensValues[VALUES]; String hb_ws_msg_start = "{"; String hb_ws_msg_temp = "\"temperature\": "; String hb_ws_msg_humi = "\"humidity\": "; String hb_ws_msg_light = "\"lightlevel\": "; String hb_ws_msg_windspeed = "\"windspeed\": "; String hb_ws_msg_pressure = "\"pressure\": "; String hb_ws_msg_timestamp = "\"timestamp\": "; String hb_ws_msg_valid = "\"valid\": "; String hb_ws_msg_end = "}"; boolean wuValidData = false; void setupWebUpdater(String device, String ip) { debug("Starting WebUpdater... " + ip); _webUpdater_ip = ip; _webUpdater_dev = device; httpUpdater.setup(&httpServer); httpServer.on("/", showHTMLMain); #ifdef USE_WIFIMANAGER httpServer.on("/resetWifiManager", resetWifiManager); #endif #ifdef HOMEBRIDGE_WEBSTAT httpServer.on("/hbWebstat", hb_webstat_send); #endif #ifdef DEBUG_WINDSPEED_MEASUREMENT httpServer.on("/measWind", measureWindspeed); #endif httpServer.begin(); debug("HTTPUpdateServer ready!"); } void doWebUpdater(void) { digitalWrite(D0, HIGH); httpServer.handleClient(); } void setSensorData(float sensorValues[]) { for (uint8_t i = 0; i < 5 and wuValidData == false; i++) { if (sensorValues[i] != 0) { wuValidData = true; // at least one value is not zero, the data is valid } } for (uint8_t i = 0; i < VALUES; i++) { _webUpdater_sensValues[i] = sensorValues[i]; } } void showHTMLMain(void) { String message = "OKO Weatherstation - " + String(_webUpdater_dev) + "" "" "" "
firmware update

" "" "" "" "" "" "" "" "" "" "
temperature" + String(_webUpdater_sensValues[SENSOR_TEMPERATURE]) + "
humidity" + String(_webUpdater_sensValues[SENSOR_HUMIDITY]) + "
light" + String(_webUpdater_sensValues[SENSOR_LIGHT]) + "
windspeed" + String(_webUpdater_sensValues[SENSOR_WINDSPEED]) + "
pressure" + String(_webUpdater_sensValues[SENSOR_PRESSURE]) + "
batvoltage" + String(_webUpdater_sensValues[SENSOR_BAT_VOLTAGE]) + "
millis" + String(millis()) + "
valid" + String(wuValidData) + "
" ""; httpServer.send(200, "text/html", message); } 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; httpServer.send(200, "text/html", msg); } #ifdef USE_WIFIMANAGER void resetWifiManager() { String message = "OKO Weatherstation - " + String(_webUpdater_dev) + "" "" "" "Reset WifiManager config.
" "Rebooting...
" ""; httpServer.send(200, "text/html", message); // Erase WiFi Credentials, enable, compile, flash, disable and reflash. WiFiManager wifiManager; wifiManager.resetSettings(); delay(5000); // manual reset after restart is required ESP.restart(); } #endif void measureWindspeed() { // read from windspeed sensorSTATUS_LED_PIN digitalWrite(STATUS_LED_PIN, HIGH); debug("Starting windspeed measurement"); float tmp_windspeed = wind_speed(); digitalWrite(STATUS_LED_PIN, LOW); String message = "OKO Weatherstation - " + String(_webUpdater_dev) + "" "" "Windsensor measurement result: " + String(tmp_windspeed) + "
" ""; httpServer.send(200, "text/html", message); }