diff --git a/WifiControlSensor/WifiControlSensor.ino b/WifiControlSensor/WifiControlSensor.ino index dd97dcb..425c055 100644 --- a/WifiControlSensor/WifiControlSensor.ino +++ b/WifiControlSensor/WifiControlSensor.ino @@ -94,15 +94,17 @@ void MqttCheckSubscription(); void MqttChangeGpioValue(int gpio, int value); bool MqttIsConfigured(); -void WifiSetup(int bootmode, int forceSetup, char *confSsid, char *confPassword, char *confHost, int ip_config, uint32_t ip, uint32_t gw, uint32_t mask, uint32_t dns, uint32_t dns2) { +void WifiSetup(int bootmode, char *confSsid, char *confPassword, char *confHost, int ip_config, uint32_t ip, uint32_t gw, uint32_t mask, uint32_t dns, uint32_t dns2) { IPAddress myIP; - if (bootmode == BOOTMODE_SETUP || forceSetup) { + if (bootmode == BOOTMODE_SETUP) { SKETCH_DEBUG_PRINT("Configuring access point..."); SKETCH_DEBUG_PRINTLN(ssid); /* You can set a password to the AP here */ WiFi.softAP(ssid); myIP = WiFi.softAPIP(); } else { + SKETCH_DEBUG_PRINTLN("Disable previous AP mode "); + WiFi.softAPdisconnect(true); SKETCH_DEBUG_PRINTLN("Connecting to Wifi..."); if(ip_config == 1){ SKETCH_DEBUG_PRINTLN("Use static ip configuration"); @@ -232,8 +234,11 @@ void setup() { SKETCH_DEBUG_PRINT("Force Setup Mode ? :"); SKETCH_DEBUG_PRINT(txStatus ? "No" : "Yes"); SKETCH_DEBUG_PRINTLN(); + if(txStatus == 0){ + mode = BOOTMODE_SETUP; + } - WifiSetup(mode, txStatus == 0, confSsid, confPassword, confHost, ip_mode, ip, gw, mask, dns, dns2); + WifiSetup(mode, confSsid, confPassword, confHost, ip_mode, ip, gw, mask, dns, dns2); if (mode == BOOTMODE_NORMAL) { MqttSetup(mqttServer, mqttUser, mqttPasswd, mqttPort, confHost); }