pull/337/head
cschwinne 2019-10-18 14:06:07 +02:00
rodzic 733996772b
commit 90fa5b3b93
5 zmienionych plików z 48 dodań i 36 usunięć

Wyświetl plik

@ -30,7 +30,7 @@
//#define WLED_ENABLE_FS_EDITOR //enable /edit page for editing SPIFFS content. Will also be disabled with OTA lock //#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 //to toggle usb serial debug (un)comment the following line
//#define WLED_DEBUG #define WLED_DEBUG
//library inclusions //library inclusions
@ -315,7 +315,6 @@ byte effectIntensity = effectIntensityDefault;
byte effectPalette = effectPaletteDefault; byte effectPalette = effectPaletteDefault;
//network //network
bool onlyAP = false; //only Access Point active, no connection to home network
bool udpConnected = false, udpRgbConnected = false; bool udpConnected = false, udpRgbConnected = false;
//ui style //ui style
@ -379,7 +378,7 @@ IPAddress realtimeIP = (0,0,0,0);
unsigned long realtimeTimeout = 0; unsigned long realtimeTimeout = 0;
//mqtt //mqtt
long nextMQTTReconnectAttempt = 0; long lastMqttReconnectAttempt = 0;
long lastInterfaceUpdate = 0; long lastInterfaceUpdate = 0;
byte interfaceUpdateCallMode = 0; byte interfaceUpdateCallMode = 0;
@ -516,7 +515,7 @@ void loop() {
handleIO(); handleIO();
handleIR(); handleIR();
handleNetworkTime(); handleNetworkTime();
if (!onlyAP) handleAlexa(); handleAlexa();
handleOverlays(); handleOverlays();
@ -531,17 +530,16 @@ void loop() {
#endif #endif
handleNightlight(); handleNightlight();
yield(); yield();
if (!onlyAP) {
handleHue(); handleHue();
handleBlynk(); handleBlynk();
yield(); yield();
if (millis() > nextMQTTReconnectAttempt) if (millis() - lastMqttReconnectAttempt > 30000)
{ {
yield();
initMqtt(); initMqtt();
nextMQTTReconnectAttempt = millis() + 30000; lastMqttReconnectAttempt = millis();
}
} }
yield(); yield();
if (!offMode) strip.service(); if (!offMode) strip.service();
} }

Wyświetl plik

@ -67,7 +67,7 @@ void wledInit()
ntpConnected = ntpUdp.begin(ntpLocalPort); ntpConnected = ntpUdp.begin(ntpLocalPort);
//start captive portal if AP active //start captive portal if AP active
if (onlyAP || strlen(apSSID) > 0) if (!WLED_CONNECTED || strlen(apSSID) > 0)
{ {
dnsServer.setErrorReplyCode(DNSReplyCode::NoError); dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
dnsServer.start(53, "*", WiFi.softAPIP()); dnsServer.start(53, "*", WiFi.softAPIP());
@ -98,13 +98,13 @@ void wledInit()
strip.service(); strip.service();
//init Alexa hue emulation //init Alexa hue emulation
if (alexaEnabled && !onlyAP) alexaInit(); if (alexaEnabled) alexaInit();
server.begin(); server.begin();
DEBUG_PRINTLN("HTTP server started"); DEBUG_PRINTLN("HTTP server started");
//init ArduinoOTA //init ArduinoOTA
if (!onlyAP) { if (WLED_CONNECTED) {
#ifndef WLED_DISABLE_OTA #ifndef WLED_DISABLE_OTA
if (aOtaEnabled) if (aOtaEnabled)
{ {
@ -121,7 +121,7 @@ void wledInit()
strip.service(); strip.service();
// Set up mDNS responder: // Set up mDNS responder:
if (strlen(cmDNS) > 0 && !onlyAP) if (strlen(cmDNS) > 0 && WLED_CONNECTED)
{ {
MDNS.begin(cmDNS); MDNS.begin(cmDNS);
DEBUG_PRINTLN("mDNS responder started"); DEBUG_PRINTLN("mDNS responder started");
@ -176,6 +176,7 @@ void beginStrip()
void initAP(bool resetAP=false){ void initAP(bool resetAP=false){
DEBUG_PRINTLN("Opening AP...");
bool set = apSSID[0]; bool set = apSSID[0];
if (!set || resetAP) strcpy(apSSID, "WLED-AP"); if (!set || resetAP) strcpy(apSSID, "WLED-AP");
//if (resetAP) strcpy(apPass,"wled1234"); //if (resetAP) strcpy(apPass,"wled1234");
@ -207,9 +208,14 @@ void initCon()
DEBUG_PRINTLN(" NO AP"); DEBUG_PRINTLN(" NO AP");
WiFi.softAPdisconnect(true); WiFi.softAPdisconnect(true);
} }
int fail_count = 0;
if (strlen(clientSSID) <1 || strcmp(clientSSID,"Your_Network") == 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 #ifndef ARDUINO_ARCH_ESP32
WiFi.hostname(serverDescription); WiFi.hostname(serverDescription);
#endif #endif
@ -217,6 +223,8 @@ void initCon()
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
WiFi.setHostname(serverDescription); WiFi.setHostname(serverDescription);
#endif #endif
//wifiInit = true;
uint32_t fail_count = 0;
unsigned long lastTry = 0; unsigned long lastTry = 0;
bool con = false; bool con = false;
while(!con) while(!con)
@ -233,8 +241,7 @@ void initCon()
if (!recoveryAPDisabled && fail_count > apWaitTimeSecs*2) if (!recoveryAPDisabled && fail_count > apWaitTimeSecs*2)
{ {
WiFi.disconnect(); WiFi.disconnect();
DEBUG_PRINTLN("Can't connect. Opening AP..."); DEBUG_PRINT("Can't connect. ");
onlyAP = true;
initAP(); initAP();
return; return;
} }
@ -244,6 +251,13 @@ void initCon()
} }
void handleConnection() {
if (!WLED_CONNECTED) {
}
}
bool checkClientIsMobile(String useragent) bool checkClientIsMobile(String useragent)
{ {
//to save complexity this function is not comprehensive //to save complexity this function is not comprehensive

Wyświetl plik

@ -4,17 +4,6 @@
#ifndef WLED_DISABLE_HUESYNC #ifndef WLED_DISABLE_HUESYNC
void handleHue() 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) if (hueReceived)
{ {
colorUpdated(7); hueReceived = false; colorUpdated(7); hueReceived = false;
@ -25,6 +14,17 @@ void handleHue()
hueNewKey = false; 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() void reconnectHue()

Wyświetl plik

@ -25,7 +25,7 @@ void handleBlynk()
void updateBlynk() void updateBlynk()
{ {
#ifndef WLED_DISABLE_BLYNK #ifndef WLED_DISABLE_BLYNK
if (onlyAP) return; if (!WLED_CONNECTED) return;
Blynk.virtualWrite(V0, bri); Blynk.virtualWrite(V0, bri);
//we need a RGB -> HSB convert here //we need a RGB -> HSB convert here
Blynk.virtualWrite(V3, bri? 1:0); Blynk.virtualWrite(V3, bri? 1:0);

Wyświetl plik

@ -215,8 +215,8 @@ Send out HA MQTT Discovery message on MQTT connect (~2.4kB):
bool initMqtt() bool initMqtt()
{ {
if (mqttServer[0] == 0) return false; if (mqttServer[0] == 0 || !WLED_CONNECTED) return false;
if (WiFi.status() != WL_CONNECTED) return false;
if (!mqtt) mqtt = new AsyncMqttClient(); if (!mqtt) mqtt = new AsyncMqttClient();
if (mqtt->connected()) return true; if (mqtt->connected()) return true;