Fix reconfiguration when wifi unreachable

This commit is contained in:
Mathieu Maret 2017-01-28 14:29:28 +01:00
parent e9a7cb8745
commit d5a8232e43

View File

@ -63,6 +63,7 @@ double temp, pressure;
float dhtTemp, dhtHumidity; float dhtTemp, dhtHumidity;
int dryness; int dryness;
uint8_t mode; uint8_t mode;
int reconfig = 0;
productConfig conf = {BOOTMODE_SETUP, "", "", "", "", "", "", 1883, 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
@ -87,7 +88,8 @@ void WebSetupServer(int bootmode);
#ifdef CONFIG_SETUP_BUTTON #ifdef CONFIG_SETUP_BUTTON
void onLongButtonPressed(uint8_t pin){ 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"); SKETCH_DEBUG_PRINTLN("Putting device in setup mode");
mode = BOOTMODE_SETUP; mode = BOOTMODE_SETUP;
WiFi.disconnect(); WiFi.disconnect();
@ -98,7 +100,7 @@ void onLongButtonPressed(uint8_t pin){
void WifiSetup(productConfig conf) { void WifiSetup(productConfig conf) {
IPAddress myIP; IPAddress myIP;
if (conf.bootMode == BOOTMODE_SETUP) { if (mode == BOOTMODE_SETUP) {
SKETCH_DEBUG_PRINTLN("Configuring access point: " CONFIG_SSID_NAME); SKETCH_DEBUG_PRINTLN("Configuring access point: " CONFIG_SSID_NAME);
/* You can set a password to the AP here */ /* You can set a password to the AP here */
WiFi.softAP(CONFIG_SSID_NAME); WiFi.softAP(CONFIG_SSID_NAME);
@ -115,6 +117,10 @@ void WifiSetup(productConfig conf) {
while (WiFi.status() != WL_CONNECTED) { while (WiFi.status() != WL_CONNECTED) {
delay(500); delay(500);
SKETCH_DEBUG_PRINT("."); SKETCH_DEBUG_PRINT(".");
if (reconfig == 1){
reconfig = 0;
return;
}
} }
SKETCH_DEBUG_PRINTF("\nWiFi connected\n"); SKETCH_DEBUG_PRINTF("\nWiFi connected\n");
@ -181,6 +187,9 @@ void OTASetup() {
} }
void setup() { void setup() {
#ifdef CONFIG_SETUP_BUTTON
new HIB(CONFIG_SETUP_BUTTON, HIGH, NULL, NULL, onLongButtonPressed);
#endif
pinMode(3, OUTPUT); pinMode(3, OUTPUT);
delay(1000); delay(1000);
@ -241,9 +250,6 @@ void setup() {
#ifdef CONFIG_ENABLE_POWER_SAVE #ifdef CONFIG_ENABLE_POWER_SAVE
wifi_set_sleep_type(LIGHT_SLEEP_T); wifi_set_sleep_type(LIGHT_SLEEP_T);
#endif #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; uint nbCycle = CONFIG_SAMPLING_PERIODE_MS / CONFIG_WEB_DELAY_MS;