From 3ef4a2b9d25aca5ecda9bf30b6e33e0baba7020e Mon Sep 17 00:00:00 2001 From: cschwinne Date: Wed, 14 Mar 2018 11:41:24 +0100 Subject: [PATCH] Added Captive Portal DNS server for AP Fixed overlay and AP password bugs --- wled00/data/settings_leds.htm | Bin 8222 -> 8174 bytes wled00/data/settings_sec.htm | Bin 7664 -> 7616 bytes wled00/data/settings_sync.htm | Bin 7868 -> 7820 bytes wled00/data/settings_time.htm | Bin 12684 -> 12636 bytes wled00/data/settings_ui.htm | Bin 7454 -> 7406 bytes wled00/data/settings_wifi.htm | Bin 7164 -> 7114 bytes wled00/wled00.ino | 10 +++++++-- wled00/wled02_xml.ino | 2 +- wled00/wled03_set.ino | 1 + wled00/wled05_init.ino | 39 ++++++++++++++++++++++++++-------- wled00/wled11_ol.ino | 31 +++++++++++++-------------- 11 files changed, 55 insertions(+), 28 deletions(-) diff --git a/wled00/data/settings_leds.htm b/wled00/data/settings_leds.htm index 4dd33b0a8fa6d19472ddfd5d4daf890d41a1aa9d..8c9cc52512489e72d1319c5e8da352fda9fb177b 100644 GIT binary patch delta 20 ccmbQ|@Xmh2FYe7kJadF63-QQIek5-L09@k--T(jq delta 64 zcmaE7KhI&qFK$r{GD5V@+Ns304fp? AQ~&?~ diff --git a/wled00/data/settings_sec.htm b/wled00/data/settings_sec.htm index 9e20586700fd6f44711a7185c428692a20293a2f..c809cffbcecc7642c9634dbf0fcf9b57de2d74cd 100644 GIT binary patch delta 20 ccmexheZYFd9G=Zvc=icQ-om3dd55e80A~vb;Q#;t delta 64 zcmX?L{lR*}93D{xhCGHuhFpeJ23rOthG2$J1}6sJ%`OZS1dpf!LmopSLoP!qgDry+Loh=qgA;@A #include #include +#include #include "src/dependencies/webserver/ESP8266HTTPUpdateServer.h" #include "src/dependencies/time/Time.h" #include "src/dependencies/time/TimeLib.h" @@ -32,7 +33,7 @@ #include "WS2812FX.h" //version in format yymmddb (b = daily build) -#define VERSION 1803141 +#define VERSION 1803142 const String versionString = "0.6.0_dev"; //AP and OTA default passwords (change them!) @@ -59,7 +60,7 @@ uint8_t auxTriggeredState = 0; //0: input 1: high 2: low String serverDescription = versionString; uint8_t currentTheme = 0; String clientssid = "Your_Network_Here"; -String clientpass = "Dummy_Pass"; +String clientpass = ""; String cmdns = "led"; uint8_t ledcount = 10; //lowered to prevent accidental overcurrent String apssid = ""; //AP off by default (unless setup) @@ -229,6 +230,10 @@ unsigned int portMulti = 1900; char packetBuffer[255]; String escapedMac; +//dns server +DNSServer dnsServer; +bool dnsActive = false; + #ifdef ARDUINO_ARCH_ESP32 WebServer server(80); #else @@ -317,6 +322,7 @@ void loop() { handleOverlays(); if (!arlsTimeout) //block stuff if WARLS is enabled { + if (dnsActive) dnsServer.processNextRequest(); handleHue(); handleNightlight(); if (bri_t) strip.service(); //do not update strip if off, prevents flicker on ESP32 diff --git a/wled00/wled02_xml.ino b/wled00/wled02_xml.ino index 91960e7c..14a3def2 100644 --- a/wled00/wled02_xml.ino +++ b/wled00/wled02_xml.ino @@ -97,7 +97,7 @@ String getSettings(uint8_t subPage) resp += ds + "APSSID" + v + "\"" + apssid + "\";"; resp += ds + "APHSSID" + c + aphide + ";"; resp += ds + "APPASS" + v + "\""; - for (int i = 0; i < clientpass.length(); i++) + for (int i = 0; i < appass.length(); i++) { resp += "*"; } diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index e5a38acb..9fa62773 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -231,6 +231,7 @@ void handleSettingsSet(uint8_t subPage) } nightlightFade = server.hasArg("TLFDE"); reverseMode = server.hasArg("LEDRV"); + strip.setReverseMode(reverseMode); if (server.hasArg("WOFFS")) { int i = server.arg("WOFFS").toInt(); diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino index 41d01d4f..5b915528 100644 --- a/wled00/wled05_init.ino +++ b/wled00/wled05_init.ino @@ -77,6 +77,14 @@ void wledInit() if (ntpEnabled && WiFi.status() == WL_CONNECTED) ntpConnected = ntpUdp.begin(ntpLocalPort); + //start captive portal + if (onlyAP || apssid.length() > 0) + { + dnsServer.setErrorReplyCode(DNSReplyCode::NoError); + dnsServer.start(53, "*", WiFi.softAPIP()); + dnsActive = true; + } + //SERVER INIT //settings page server.on("/settings", HTTP_GET, [](){ @@ -114,15 +122,15 @@ void wledInit() }); server.on("/", HTTP_GET, [](){ - if (!showWelcomePage){ - if(!handleFileRead("/index.htm")) { - serveIndex(); - } - }else{ - if(!handleFileRead("/welcome.htm")) { - serveSettings(255); - } - } + serveIndexOrWelcome(); + }); + + server.on("/generate_204", HTTP_GET, [](){ + serveIndexOrWelcome(); + }); + + server.on("/fwlink", HTTP_GET, [](){ + serveIndexOrWelcome(); }); server.on("/sliders", HTTP_GET, serveIndex); @@ -375,6 +383,19 @@ void buildCssColorString() cssColorString+=";}"; } +void serveIndexOrWelcome() +{ + if (!showWelcomePage){ + if(!handleFileRead("/index.htm")) { + serveIndex(); + } + }else{ + if(!handleFileRead("/welcome.htm")) { + serveSettings(255); + } + } +} + void serveIndex() { if (!arlsTimeout) //do not serve while receiving realtime diff --git a/wled00/wled11_ol.ino b/wled00/wled11_ol.ino index ec39aebb..8858b847 100644 --- a/wled00/wled11_ol.ino +++ b/wled00/wled11_ol.ino @@ -137,7 +137,8 @@ void handleOverlays() void _overlaySolid() { - uint32_t cls = (useGammaCorrectionRGB)? gamma8[white*16777216] + gamma8[col[0]]*65536 + gamma8[col[1]]*256 + gamma8[col[2]]:white*16777216 + col[0]*65536 + col[1]*256 + col[2]; + strip.unlockAll(); + uint32_t cls = (useGammaCorrectionRGB)? gamma8[white_sec*16777216] + gamma8[col_sec[0]]*65536 + gamma8[col_sec[1]]*256 + gamma8[col_sec[2]]:white_sec*16777216 + col_sec[0]*65536 + col_sec[1]*256 + col_sec[2]; strip.setRange(overlayMin,overlayMax,cls); overlayRefreshMs = 1902; } @@ -161,6 +162,17 @@ void _overlayAnalogClock() if (minutePixel > overlayMax) minutePixel = overlayMin -1 + minutePixel - overlayMax; int secondPixel = floor(analogClock12pixel + overlaySize*secondP); if (secondPixel > overlayMax) secondPixel = overlayMin -1 + secondPixel - overlayMax; + if (analogClockSecondsTrail) + { + if (secondPixel < analogClock12pixel) + { + strip.setRange(analogClock12pixel, overlayMax, 0xFF0000); + strip.setRange(overlayMin, secondPixel, 0xFF0000); + } else + { + strip.setRange(analogClock12pixel, secondPixel, 0xFF0000); + } + } if (analogClock5MinuteMarks) { int pix; @@ -168,23 +180,10 @@ void _overlayAnalogClock() { pix = overlayMin + analogClock12pixel + (overlaySize/12)*i; if (pix > overlayMax) pix = pix - overlayMax; - strip.setIndividual(pix, 0xAAAAAA); + strip.setIndividual(pix,0x00FFAA); } } - if (analogClockSecondsTrail) - { - if (secondPixel < analogClock12pixel) - { - strip.setRange(analogClock12pixel, secondPixel, 0xFF0000); - strip.setRange(secondPixel, overlayMax, 0xFF0000); - } else - { - strip.setRange(analogClock12pixel, secondPixel, 0xFF0000); - } - } else - { - strip.setIndividual(secondPixel, 0xFF0000); - } + if (!analogClockSecondsTrail) strip.setIndividual(secondPixel, 0xFF0000); strip.setIndividual(minutePixel, 0x00FF00); strip.setIndividual(hourPixel, 0x0000FF); overlayRefreshMs = 998;