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:
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",

View File

@ -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

View File

@ -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", "<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{
server.send(200, "text/html", "<h1>Configuration Saved</h1><br/>"
"<a href=\"/reboot\">Reboot</a><br/>");
@ -184,11 +185,11 @@ void WebHandleSave() {
}
void WebHandleOTA() {
SKETCH_DEBUG_PRINTLN("Boot mode Set to OTA");
EepromSaveBootMode(BOOTMODE_OTA);
server.send(200, "text/html", "<h1>OTA Mode set</h1><br/>"
"You can reboot now<br/>"
"<a href=\"/reboot\">Reboot</a><br/>");
SKETCH_DEBUG_PRINTLN("Activating OTA mode");
server.send(200, "text/html", "<h1>Setting OTA mode</h1><br/>"
"Web ui will be disabled<br/>");
mode = BOOTMODE_OTA;
OTASetup();
}
void WebHandleNotFound() {

View File

@ -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)));

View File

@ -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 {}