From d5a8232e43fe3b4a9afaa7b5de5ee8b3dcb81d21 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Sat, 28 Jan 2017 14:29:28 +0100 Subject: [PATCH] Fix reconfiguration when wifi unreachable --- WifiControlSensor/WifiControlSensor.ino | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/WifiControlSensor/WifiControlSensor.ino b/WifiControlSensor/WifiControlSensor.ino index 78cad20..40fe6a1 100644 --- a/WifiControlSensor/WifiControlSensor.ino +++ b/WifiControlSensor/WifiControlSensor.ino @@ -63,6 +63,7 @@ double temp, pressure; float dhtTemp, dhtHumidity; int dryness; uint8_t mode; +int reconfig = 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 @@ -87,7 +88,8 @@ void WebSetupServer(int bootmode); #ifdef CONFIG_SETUP_BUTTON void onLongButtonPressed(uint8_t pin){ - if(pin == CONFIG_SETUP_BUTTON && mode == BOOTMODE_NORMAL){ + if(pin == CONFIG_SETUP_BUTTON){ + reconfig = 1; SKETCH_DEBUG_PRINTLN("Putting device in setup mode"); mode = BOOTMODE_SETUP; WiFi.disconnect(); @@ -98,7 +100,7 @@ void onLongButtonPressed(uint8_t pin){ void WifiSetup(productConfig conf) { IPAddress myIP; - if (conf.bootMode == BOOTMODE_SETUP) { + if (mode == BOOTMODE_SETUP) { SKETCH_DEBUG_PRINTLN("Configuring access point: " CONFIG_SSID_NAME); /* You can set a password to the AP here */ WiFi.softAP(CONFIG_SSID_NAME); @@ -115,6 +117,10 @@ void WifiSetup(productConfig conf) { while (WiFi.status() != WL_CONNECTED) { delay(500); SKETCH_DEBUG_PRINT("."); + if (reconfig == 1){ + reconfig = 0; + return; + } } SKETCH_DEBUG_PRINTF("\nWiFi connected\n"); @@ -181,6 +187,9 @@ void OTASetup() { } void setup() { +#ifdef CONFIG_SETUP_BUTTON + new HIB(CONFIG_SETUP_BUTTON, HIGH, NULL, NULL, onLongButtonPressed); +#endif pinMode(3, OUTPUT); delay(1000); @@ -241,9 +250,6 @@ void setup() { #ifdef CONFIG_ENABLE_POWER_SAVE wifi_set_sleep_type(LIGHT_SLEEP_T); #endif -#ifdef CONFIG_SETUP_BUTTON - new HIB(CONFIG_SETUP_BUTTON, HIGH, NULL, NULL, onLongButtonPressed); -#endif } uint nbCycle = CONFIG_SAMPLING_PERIODE_MS / CONFIG_WEB_DELAY_MS;