Browse Source

Fix reconfiguration when wifi unreachable

sonoff
Mathieu Maret 5 years ago
parent
commit
d5a8232e43
  1. 16
      WifiControlSensor/WifiControlSensor.ino

16
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;

Loading…
Cancel
Save