Removed onlyAP

This commit is contained in:
cschwinne 2019-10-18 14:06:07 +02:00
parent 733996772b
commit 90fa5b3b93
5 changed files with 48 additions and 36 deletions

View File

@ -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();
}

View File

@ -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

View File

@ -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()

View File

@ -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);

View File

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