Added Captive Portal DNS server for AP

Fixed overlay and AP password bugs
This commit is contained in:
cschwinne 2018-03-14 11:41:24 +01:00
parent 37f91c4d50
commit 3ef4a2b9d2
11 changed files with 55 additions and 28 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -22,6 +22,7 @@
#include <EEPROM.h> #include <EEPROM.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
#include <WiFiUDP.h> #include <WiFiUDP.h>
#include <DNSServer.h>
#include "src/dependencies/webserver/ESP8266HTTPUpdateServer.h" #include "src/dependencies/webserver/ESP8266HTTPUpdateServer.h"
#include "src/dependencies/time/Time.h" #include "src/dependencies/time/Time.h"
#include "src/dependencies/time/TimeLib.h" #include "src/dependencies/time/TimeLib.h"
@ -32,7 +33,7 @@
#include "WS2812FX.h" #include "WS2812FX.h"
//version in format yymmddb (b = daily build) //version in format yymmddb (b = daily build)
#define VERSION 1803141 #define VERSION 1803142
const String versionString = "0.6.0_dev"; const String versionString = "0.6.0_dev";
//AP and OTA default passwords (change them!) //AP and OTA default passwords (change them!)
@ -59,7 +60,7 @@ uint8_t auxTriggeredState = 0; //0: input 1: high 2: low
String serverDescription = versionString; String serverDescription = versionString;
uint8_t currentTheme = 0; uint8_t currentTheme = 0;
String clientssid = "Your_Network_Here"; String clientssid = "Your_Network_Here";
String clientpass = "Dummy_Pass"; String clientpass = "";
String cmdns = "led"; String cmdns = "led";
uint8_t ledcount = 10; //lowered to prevent accidental overcurrent uint8_t ledcount = 10; //lowered to prevent accidental overcurrent
String apssid = ""; //AP off by default (unless setup) String apssid = ""; //AP off by default (unless setup)
@ -229,6 +230,10 @@ unsigned int portMulti = 1900;
char packetBuffer[255]; char packetBuffer[255];
String escapedMac; String escapedMac;
//dns server
DNSServer dnsServer;
bool dnsActive = false;
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
WebServer server(80); WebServer server(80);
#else #else
@ -317,6 +322,7 @@ void loop() {
handleOverlays(); handleOverlays();
if (!arlsTimeout) //block stuff if WARLS is enabled if (!arlsTimeout) //block stuff if WARLS is enabled
{ {
if (dnsActive) dnsServer.processNextRequest();
handleHue(); handleHue();
handleNightlight(); handleNightlight();
if (bri_t) strip.service(); //do not update strip if off, prevents flicker on ESP32 if (bri_t) strip.service(); //do not update strip if off, prevents flicker on ESP32

View File

@ -97,7 +97,7 @@ String getSettings(uint8_t subPage)
resp += ds + "APSSID" + v + "\"" + apssid + "\";"; resp += ds + "APSSID" + v + "\"" + apssid + "\";";
resp += ds + "APHSSID" + c + aphide + ";"; resp += ds + "APHSSID" + c + aphide + ";";
resp += ds + "APPASS" + v + "\""; resp += ds + "APPASS" + v + "\"";
for (int i = 0; i < clientpass.length(); i++) for (int i = 0; i < appass.length(); i++)
{ {
resp += "*"; resp += "*";
} }

View File

@ -231,6 +231,7 @@ void handleSettingsSet(uint8_t subPage)
} }
nightlightFade = server.hasArg("TLFDE"); nightlightFade = server.hasArg("TLFDE");
reverseMode = server.hasArg("LEDRV"); reverseMode = server.hasArg("LEDRV");
strip.setReverseMode(reverseMode);
if (server.hasArg("WOFFS")) if (server.hasArg("WOFFS"))
{ {
int i = server.arg("WOFFS").toInt(); int i = server.arg("WOFFS").toInt();

View File

@ -77,6 +77,14 @@ void wledInit()
if (ntpEnabled && WiFi.status() == WL_CONNECTED) if (ntpEnabled && WiFi.status() == WL_CONNECTED)
ntpConnected = ntpUdp.begin(ntpLocalPort); 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 //SERVER INIT
//settings page //settings page
server.on("/settings", HTTP_GET, [](){ server.on("/settings", HTTP_GET, [](){
@ -114,15 +122,15 @@ void wledInit()
}); });
server.on("/", HTTP_GET, [](){ server.on("/", HTTP_GET, [](){
if (!showWelcomePage){ serveIndexOrWelcome();
if(!handleFileRead("/index.htm")) { });
serveIndex();
} server.on("/generate_204", HTTP_GET, [](){
}else{ serveIndexOrWelcome();
if(!handleFileRead("/welcome.htm")) { });
serveSettings(255);
} server.on("/fwlink", HTTP_GET, [](){
} serveIndexOrWelcome();
}); });
server.on("/sliders", HTTP_GET, serveIndex); server.on("/sliders", HTTP_GET, serveIndex);
@ -375,6 +383,19 @@ void buildCssColorString()
cssColorString+=";}"; cssColorString+=";}";
} }
void serveIndexOrWelcome()
{
if (!showWelcomePage){
if(!handleFileRead("/index.htm")) {
serveIndex();
}
}else{
if(!handleFileRead("/welcome.htm")) {
serveSettings(255);
}
}
}
void serveIndex() void serveIndex()
{ {
if (!arlsTimeout) //do not serve while receiving realtime if (!arlsTimeout) //do not serve while receiving realtime

View File

@ -137,7 +137,8 @@ void handleOverlays()
void _overlaySolid() 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); strip.setRange(overlayMin,overlayMax,cls);
overlayRefreshMs = 1902; overlayRefreshMs = 1902;
} }
@ -161,6 +162,17 @@ void _overlayAnalogClock()
if (minutePixel > overlayMax) minutePixel = overlayMin -1 + minutePixel - overlayMax; if (minutePixel > overlayMax) minutePixel = overlayMin -1 + minutePixel - overlayMax;
int secondPixel = floor(analogClock12pixel + overlaySize*secondP); int secondPixel = floor(analogClock12pixel + overlaySize*secondP);
if (secondPixel > overlayMax) secondPixel = overlayMin -1 + secondPixel - overlayMax; 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) if (analogClock5MinuteMarks)
{ {
int pix; int pix;
@ -168,23 +180,10 @@ void _overlayAnalogClock()
{ {
pix = overlayMin + analogClock12pixel + (overlaySize/12)*i; pix = overlayMin + analogClock12pixel + (overlaySize/12)*i;
if (pix > overlayMax) pix = pix - overlayMax; if (pix > overlayMax) pix = pix - overlayMax;
strip.setIndividual(pix, 0xAAAAAA); strip.setIndividual(pix,0x00FFAA);
} }
} }
if (analogClockSecondsTrail) if (!analogClockSecondsTrail) strip.setIndividual(secondPixel, 0xFF0000);
{
if (secondPixel < analogClock12pixel)
{
strip.setRange(analogClock12pixel, secondPixel, 0xFF0000);
strip.setRange(secondPixel, overlayMax, 0xFF0000);
} else
{
strip.setRange(analogClock12pixel, secondPixel, 0xFF0000);
}
} else
{
strip.setIndividual(secondPixel, 0xFF0000);
}
strip.setIndividual(minutePixel, 0x00FF00); strip.setIndividual(minutePixel, 0x00FF00);
strip.setIndividual(hourPixel, 0x0000FF); strip.setIndividual(hourPixel, 0x0000FF);
overlayRefreshMs = 998; overlayRefreshMs = 998;