From 90fa5b3b93aaa5a93e2e5fba8bd3f8317c5278bf Mon Sep 17 00:00:00 2001 From: cschwinne Date: Fri, 18 Oct 2019 14:06:07 +0200 Subject: [PATCH] Removed onlyAP --- wled00/wled00.ino | 26 ++++++++++++-------------- wled00/wled05_init.ino | 30 ++++++++++++++++++++++-------- wled00/wled15_hue.ino | 22 +++++++++++----------- wled00/wled16_blynk.ino | 2 +- wled00/wled17_mqtt.ino | 4 ++-- 5 files changed, 48 insertions(+), 36 deletions(-) diff --git a/wled00/wled00.ino b/wled00/wled00.ino index bad1db94a..12eb3136c 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -30,7 +30,7 @@ //#define WLED_ENABLE_FS_EDITOR //enable /edit page for editing SPIFFS content. Will also be disabled with OTA lock //to toggle usb serial debug (un)comment the following line -//#define WLED_DEBUG +#define WLED_DEBUG //library inclusions @@ -315,7 +315,6 @@ byte effectIntensity = effectIntensityDefault; byte effectPalette = effectPaletteDefault; //network -bool onlyAP = false; //only Access Point active, no connection to home network bool udpConnected = false, udpRgbConnected = false; //ui style @@ -379,7 +378,7 @@ IPAddress realtimeIP = (0,0,0,0); unsigned long realtimeTimeout = 0; //mqtt -long nextMQTTReconnectAttempt = 0; +long lastMqttReconnectAttempt = 0; long lastInterfaceUpdate = 0; byte interfaceUpdateCallMode = 0; @@ -516,7 +515,7 @@ void loop() { handleIO(); handleIR(); handleNetworkTime(); - if (!onlyAP) handleAlexa(); + handleAlexa(); handleOverlays(); @@ -531,17 +530,16 @@ void loop() { #endif handleNightlight(); yield(); - if (!onlyAP) { - handleHue(); - handleBlynk(); - yield(); - if (millis() > nextMQTTReconnectAttempt) - { - yield(); - initMqtt(); - nextMQTTReconnectAttempt = millis() + 30000; - } + + handleHue(); + handleBlynk(); + yield(); + if (millis() - lastMqttReconnectAttempt > 30000) + { + initMqtt(); + lastMqttReconnectAttempt = millis(); } + yield(); if (!offMode) strip.service(); } diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino index 0eb712eeb..8ec6fae8f 100644 --- a/wled00/wled05_init.ino +++ b/wled00/wled05_init.ino @@ -67,7 +67,7 @@ void wledInit() ntpConnected = ntpUdp.begin(ntpLocalPort); //start captive portal if AP active - if (onlyAP || strlen(apSSID) > 0) + if (!WLED_CONNECTED || strlen(apSSID) > 0) { dnsServer.setErrorReplyCode(DNSReplyCode::NoError); dnsServer.start(53, "*", WiFi.softAPIP()); @@ -98,13 +98,13 @@ void wledInit() strip.service(); //init Alexa hue emulation - if (alexaEnabled && !onlyAP) alexaInit(); + if (alexaEnabled) alexaInit(); server.begin(); DEBUG_PRINTLN("HTTP server started"); //init ArduinoOTA - if (!onlyAP) { + if (WLED_CONNECTED) { #ifndef WLED_DISABLE_OTA if (aOtaEnabled) { @@ -121,7 +121,7 @@ void wledInit() strip.service(); // Set up mDNS responder: - if (strlen(cmDNS) > 0 && !onlyAP) + if (strlen(cmDNS) > 0 && WLED_CONNECTED) { MDNS.begin(cmDNS); DEBUG_PRINTLN("mDNS responder started"); @@ -176,6 +176,7 @@ void beginStrip() void initAP(bool resetAP=false){ + DEBUG_PRINTLN("Opening AP..."); bool set = apSSID[0]; if (!set || resetAP) strcpy(apSSID, "WLED-AP"); //if (resetAP) strcpy(apPass,"wled1234"); @@ -207,9 +208,14 @@ void initCon() DEBUG_PRINTLN(" NO AP"); WiFi.softAPdisconnect(true); } - int fail_count = 0; + if (strlen(clientSSID) <1 || strcmp(clientSSID,"Your_Network") == 0) - fail_count = apWaitTimeSecs*2; //instantly go to ap mode + { + DEBUG_PRINT("No connection configured. "); + initAP(); //instantly go to ap mode + return; + } + #ifndef ARDUINO_ARCH_ESP32 WiFi.hostname(serverDescription); #endif @@ -217,6 +223,8 @@ void initCon() #ifdef ARDUINO_ARCH_ESP32 WiFi.setHostname(serverDescription); #endif + //wifiInit = true; + uint32_t fail_count = 0; unsigned long lastTry = 0; bool con = false; while(!con) @@ -233,8 +241,7 @@ void initCon() if (!recoveryAPDisabled && fail_count > apWaitTimeSecs*2) { WiFi.disconnect(); - DEBUG_PRINTLN("Can't connect. Opening AP..."); - onlyAP = true; + DEBUG_PRINT("Can't connect. "); initAP(); return; } @@ -244,6 +251,13 @@ void initCon() } +void handleConnection() { + if (!WLED_CONNECTED) { + + } +} + + bool checkClientIsMobile(String useragent) { //to save complexity this function is not comprehensive diff --git a/wled00/wled15_hue.ino b/wled00/wled15_hue.ino index d13ce43a0..da400f5e8 100644 --- a/wled00/wled15_hue.ino +++ b/wled00/wled15_hue.ino @@ -4,17 +4,6 @@ #ifndef WLED_DISABLE_HUESYNC void handleHue() { - if (hueClient != nullptr && millis() - hueLastRequestSent > huePollIntervalMs && WLED_CONNECTED) - { - hueLastRequestSent = millis(); - if (huePollingEnabled) - { - reconnectHue(); - } else { - hueClient->close(); - if (hueError[0] == 'A') strcpy(hueError,"Inactive"); - } - } if (hueReceived) { colorUpdated(7); hueReceived = false; @@ -25,6 +14,17 @@ void handleHue() hueNewKey = false; } } + + if (!WLED_CONNECTED || hueClient == nullptr || millis() - hueLastRequestSent < huePollIntervalMs) return; + + hueLastRequestSent = millis(); + if (huePollingEnabled) + { + reconnectHue(); + } else { + hueClient->close(); + if (hueError[0] == 'A') strcpy(hueError,"Inactive"); + } } void reconnectHue() diff --git a/wled00/wled16_blynk.ino b/wled00/wled16_blynk.ino index 5b04da9e1..c09d0c185 100644 --- a/wled00/wled16_blynk.ino +++ b/wled00/wled16_blynk.ino @@ -25,7 +25,7 @@ void handleBlynk() void updateBlynk() { #ifndef WLED_DISABLE_BLYNK - if (onlyAP) return; + if (!WLED_CONNECTED) return; Blynk.virtualWrite(V0, bri); //we need a RGB -> HSB convert here Blynk.virtualWrite(V3, bri? 1:0); diff --git a/wled00/wled17_mqtt.ino b/wled00/wled17_mqtt.ino index c70048868..159080f84 100644 --- a/wled00/wled17_mqtt.ino +++ b/wled00/wled17_mqtt.ino @@ -215,8 +215,8 @@ Send out HA MQTT Discovery message on MQTT connect (~2.4kB): bool initMqtt() { - if (mqttServer[0] == 0) return false; - if (WiFi.status() != WL_CONNECTED) return false; + if (mqttServer[0] == 0 || !WLED_CONNECTED) return false; + if (!mqtt) mqtt = new AsyncMqttClient(); if (mqtt->connected()) return true;