diff --git a/Updater.py b/Updater.py old mode 100644 new mode 100755 index 7e39dac..385d335 --- a/Updater.py +++ b/Updater.py @@ -26,11 +26,9 @@ class Updater(Thread): try: print("Put device in OTA mode") urllib.request.urlopen("http://" + self.ip + "/otamode").read() - urllib.request.urlopen("http://" + self.ip + "/reboot").read() self.gui.pb["value"] = 2 - print("Waiting for device to reboot") - time.sleep(10) + print("Uploading new firmware") self.gui.pb["value"] = 3 subprocess.call(["python", "espota.py", "-i", diff --git a/WifiControlSensor/EEPROM.ino b/WifiControlSensor/EEPROM.ino index 7ef05be..0ae00a4 100644 --- a/WifiControlSensor/EEPROM.ino +++ b/WifiControlSensor/EEPROM.ino @@ -64,8 +64,10 @@ void EepromReadConfig(productConfig &config) { char *tmpString; if (boot == '1') { - config.bootMode = BOOTMODE_NORMAL; + config.bootMode = BOOTMODE_SETUP; } else if (boot == '2') { + config.bootMode = BOOTMODE_NORMAL; + } else if (boot == '3') { config.bootMode = BOOTMODE_OTA; } else { //Do not need to parse EEPROM when not configured diff --git a/WifiControlSensor/WebServer.ino b/WifiControlSensor/WebServer.ino index 4130b19..2c857d8 100644 --- a/WifiControlSensor/WebServer.ino +++ b/WifiControlSensor/WebServer.ino @@ -176,7 +176,8 @@ void WebHandleSave() { //In STA mode, we can test the AP connection WiFi.begin(server.arg("ssid").c_str(), server.arg("password").c_str()); server.send(200, "text/html", "

Configuration Saved


" - "Check Wifi Configuration
"); + "Check Wifi Configuration
" + "Reboot
"); }else{ server.send(200, "text/html", "

Configuration Saved


" "Reboot
"); @@ -184,11 +185,11 @@ void WebHandleSave() { } void WebHandleOTA() { - SKETCH_DEBUG_PRINTLN("Boot mode Set to OTA"); - EepromSaveBootMode(BOOTMODE_OTA); - server.send(200, "text/html", "

OTA Mode set


" - "You can reboot now
" - "Reboot
"); + SKETCH_DEBUG_PRINTLN("Activating OTA mode"); + server.send(200, "text/html", "

Setting OTA mode


" + "Web ui will be disabled
"); + mode = BOOTMODE_OTA; + OTASetup(); } void WebHandleNotFound() { diff --git a/WifiControlSensor/WifiControlSensor.ino b/WifiControlSensor/WifiControlSensor.ino index c94c156..a9064de 100644 --- a/WifiControlSensor/WifiControlSensor.ino +++ b/WifiControlSensor/WifiControlSensor.ino @@ -55,15 +55,15 @@ extern "C" { } -#define BOOTMODE_SETUP 0 -#define BOOTMODE_NORMAL 1 -#define BOOTMODE_OTA 2 +#define BOOTMODE_SETUP 1 +#define BOOTMODE_NORMAL 2 +#define BOOTMODE_OTA 3 double temp, pressure; float dhtTemp, dhtHumidity; int dryness; uint8_t mode; -productConfig conf = {BOOTMODE_SETUP, "", "", "", "", "", "", 0, 0, 0, 0, 0, 0, 0}; +productConfig conf = {BOOTMODE_SETUP, "", "", "", "", "", "", 1883, 0, 0, 0, 0, 0, 0}; // Should have less that MAXSUBSCRIPTIONS elements // MAXSUBSCRIPTIONS is defined is Adafruit_mqtt.h const int gpioControlled[] = CONFIG_CONTROLLED_GPIO; @@ -99,10 +99,9 @@ void onLongButtonPressed(uint8_t pin){ void WifiSetup(productConfig conf) { IPAddress myIP; if (conf.bootMode == BOOTMODE_SETUP) { - SKETCH_DEBUG_PRINT("Configuring access point..."); - SKETCH_DEBUG_PRINTLN(conf.ssid); + SKETCH_DEBUG_PRINTLN("Configuring access point: "CONFIG_SSID_NAME); /* You can set a password to the AP here */ - WiFi.softAP(conf.ssid); + WiFi.softAP(CONFIG_SSID_NAME); myIP = WiFi.softAPIP(); } else { //Disable previous AP mode @@ -144,15 +143,13 @@ void OTASetup() { // No authentication by default // ArduinoOTA.setPassword((const char *)"123"); - //Disable OTA mode to avoid forever loop - //Force BOOTMODE_SETUP in case eeprom layout have changed - EepromSaveBootMode(BOOTMODE_SETUP); - ArduinoOTA.onStart([]() { SKETCH_DEBUG_PRINTLN("Start"); }); ArduinoOTA.onEnd([]() { SKETCH_DEBUG_PRINTLN("\nEnd"); + //Force BOOTMODE_SETUP in case eeprom layout have changed + EepromSaveBootMode(BOOTMODE_SETUP); }); ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { SKETCH_DEBUG_PRINTF("Progress: %u%%\n", (progress / (total / 100))); diff --git a/WifiControlSensor/config_device.h b/WifiControlSensor/config_device.h index 7ac6750..f7bdb37 100644 --- a/WifiControlSensor/config_device.h +++ b/WifiControlSensor/config_device.h @@ -54,7 +54,7 @@ // GPIO that can be get by mqtt and http // Pin 6 to 11 and 16 can not be used for mqtt -#define CONFIG_OBSERVED_GPIO {} +#define CONFIG_OBSERVED_GPIO {5} // GPIO used in PWM //#define CONFIG_CONTROLLED_PWM {}