OTA does not need a reboot anymore

This commit is contained in:
Mathieu Maret 2016-12-14 22:57:01 +01:00
parent 0396ccfb45
commit f4541a6fd6
5 changed files with 20 additions and 22 deletions

4
Updater.py Normal file → Executable file
View File

@ -26,11 +26,9 @@ class Updater(Thread):
try: try:
print("Put device in OTA mode") print("Put device in OTA mode")
urllib.request.urlopen("http://" + self.ip + "/otamode").read() urllib.request.urlopen("http://" + self.ip + "/otamode").read()
urllib.request.urlopen("http://" + self.ip + "/reboot").read()
self.gui.pb["value"] = 2 self.gui.pb["value"] = 2
print("Waiting for device to reboot") print("Uploading new firmware")
time.sleep(10)
self.gui.pb["value"] = 3 self.gui.pb["value"] = 3
subprocess.call(["python", "espota.py", "-i", subprocess.call(["python", "espota.py", "-i",

View File

@ -64,8 +64,10 @@ void EepromReadConfig(productConfig &config) {
char *tmpString; char *tmpString;
if (boot == '1') { if (boot == '1') {
config.bootMode = BOOTMODE_NORMAL; config.bootMode = BOOTMODE_SETUP;
} else if (boot == '2') { } else if (boot == '2') {
config.bootMode = BOOTMODE_NORMAL;
} else if (boot == '3') {
config.bootMode = BOOTMODE_OTA; config.bootMode = BOOTMODE_OTA;
} else { } else {
//Do not need to parse EEPROM when not configured //Do not need to parse EEPROM when not configured

View File

@ -176,7 +176,8 @@ void WebHandleSave() {
//In STA mode, we can test the AP connection //In STA mode, we can test the AP connection
WiFi.begin(server.arg("ssid").c_str(), server.arg("password").c_str()); WiFi.begin(server.arg("ssid").c_str(), server.arg("password").c_str());
server.send(200, "text/html", "<h1>Configuration Saved</h1><br/>" server.send(200, "text/html", "<h1>Configuration Saved</h1><br/>"
"<a href=\"/wifiStatus\">Check Wifi Configuration</a><br/>"); "<a href=\"/wifiStatus\">Check Wifi Configuration</a><br/>"
"<a href=\"/reboot\">Reboot</a><br/>");
}else{ }else{
server.send(200, "text/html", "<h1>Configuration Saved</h1><br/>" server.send(200, "text/html", "<h1>Configuration Saved</h1><br/>"
"<a href=\"/reboot\">Reboot</a><br/>"); "<a href=\"/reboot\">Reboot</a><br/>");
@ -184,11 +185,11 @@ void WebHandleSave() {
} }
void WebHandleOTA() { void WebHandleOTA() {
SKETCH_DEBUG_PRINTLN("Boot mode Set to OTA"); SKETCH_DEBUG_PRINTLN("Activating OTA mode");
EepromSaveBootMode(BOOTMODE_OTA); server.send(200, "text/html", "<h1>Setting OTA mode</h1><br/>"
server.send(200, "text/html", "<h1>OTA Mode set</h1><br/>" "Web ui will be disabled<br/>");
"You can reboot now<br/>" mode = BOOTMODE_OTA;
"<a href=\"/reboot\">Reboot</a><br/>"); OTASetup();
} }
void WebHandleNotFound() { void WebHandleNotFound() {

View File

@ -55,15 +55,15 @@ extern "C" {
} }
#define BOOTMODE_SETUP 0 #define BOOTMODE_SETUP 1
#define BOOTMODE_NORMAL 1 #define BOOTMODE_NORMAL 2
#define BOOTMODE_OTA 2 #define BOOTMODE_OTA 3
double temp, pressure; double temp, pressure;
float dhtTemp, dhtHumidity; float dhtTemp, dhtHumidity;
int dryness; int dryness;
uint8_t mode; 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 // Should have less that MAXSUBSCRIPTIONS elements
// MAXSUBSCRIPTIONS is defined is Adafruit_mqtt.h // MAXSUBSCRIPTIONS is defined is Adafruit_mqtt.h
const int gpioControlled[] = CONFIG_CONTROLLED_GPIO; const int gpioControlled[] = CONFIG_CONTROLLED_GPIO;
@ -99,10 +99,9 @@ void onLongButtonPressed(uint8_t pin){
void WifiSetup(productConfig conf) { void WifiSetup(productConfig conf) {
IPAddress myIP; IPAddress myIP;
if (conf.bootMode == BOOTMODE_SETUP) { if (conf.bootMode == BOOTMODE_SETUP) {
SKETCH_DEBUG_PRINT("Configuring access point..."); SKETCH_DEBUG_PRINTLN("Configuring access point: "CONFIG_SSID_NAME);
SKETCH_DEBUG_PRINTLN(conf.ssid);
/* You can set a password to the AP here */ /* You can set a password to the AP here */
WiFi.softAP(conf.ssid); WiFi.softAP(CONFIG_SSID_NAME);
myIP = WiFi.softAPIP(); myIP = WiFi.softAPIP();
} else { } else {
//Disable previous AP mode //Disable previous AP mode
@ -144,15 +143,13 @@ void OTASetup() {
// No authentication by default // No authentication by default
// ArduinoOTA.setPassword((const char *)"123"); // 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([]() { ArduinoOTA.onStart([]() {
SKETCH_DEBUG_PRINTLN("Start"); SKETCH_DEBUG_PRINTLN("Start");
}); });
ArduinoOTA.onEnd([]() { ArduinoOTA.onEnd([]() {
SKETCH_DEBUG_PRINTLN("\nEnd"); SKETCH_DEBUG_PRINTLN("\nEnd");
//Force BOOTMODE_SETUP in case eeprom layout have changed
EepromSaveBootMode(BOOTMODE_SETUP);
}); });
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
SKETCH_DEBUG_PRINTF("Progress: %u%%\n", (progress / (total / 100))); SKETCH_DEBUG_PRINTF("Progress: %u%%\n", (progress / (total / 100)));

View File

@ -54,7 +54,7 @@
// GPIO that can be get by mqtt and http // GPIO that can be get by mqtt and http
// Pin 6 to 11 and 16 can not be used for mqtt // 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 // GPIO used in PWM
//#define CONFIG_CONTROLLED_PWM {} //#define CONFIG_CONTROLLED_PWM {}