NL=0 instant off bugfix attempt

added udpPort = 0 as off
implement all settings setters (notifyNightlight \n udpPort)
De-implement notification fwd and led_amount settings
descriptive text / title (server side + settings)
nightlight function different after brightness than 0
This commit is contained in:
cschwinne 2016-12-11 20:11:14 +01:00
parent a3a2c0448f
commit 945839e3d3
9 changed files with 116 additions and 58 deletions

View File

@ -1,8 +1,8 @@
color cycle
other vfx (fire...)
sequence
simple slide transition
additional color picker field
implement all settings setters (notifyNightlight \n udpPort)
implement HSB slider option
implement ranges
implement discrete range color setter
@ -11,11 +11,32 @@ svg icons in html
add preferred colors to settings -> quickly t. UI, button select,
use iframe for settings, seperate tabs for wifi and application confg
use iframe for all adv. features?
/dumpeeprom and /pusheeprom
/dumpeeprom and /pusheeprom (ota lock!)
aux trigger pin
descriptive text
randomizer
clock functions:
analog clock on range (dots)
5 min lines
slider clock on range (track)
get time from ntp
time zones + dst
adjustable chimes
timed light activation
alarm clock
countdown (= NL with seq. trans)
more button functions (hold for bri select, double click, etc.):
hold
single click
double click
triple click
quad click
funcs: toggle on/off
toggle nightlight
toggle notifier
var. brightness
BUGS
static ip disables mdns
? authentification for security relevant areas ([/settings, /reset])
(Unverified) led_amount does nothing (is always 16) because NeoPixelBus is initiated before EEPROM read

View File

@ -31,18 +31,19 @@
document.S_form.APHSSID.checked = (this.responseXML.getElementsByTagName('aphssid')[0].innerHTML)!=0?true:false;
document.S_form.APPASS.value = this.responseXML.getElementsByTagName('appass')[0].innerHTML; //fake pass like ******
document.S_form.APCHAN.value = this.responseXML.getElementsByTagName('apchan')[0].innerHTML;
document.S_form.LEDS.value = this.responseXML.getElementsByTagName('leds')[0].innerHTML;
document.S_form.DESC.value = this.responseXML.getElementsByTagName('desc')[0].innerHTML;
document.S_form.BTNON.checked = (this.responseXML.getElementsByTagName('btnon')[0].innerHTML)!=0?true:false;
document.S_form.TFADE.checked = (this.responseXML.getElementsByTagName('tfade')[0].innerHTML)!=0?true:false;
document.S_form.TDLAY.value = this.responseXML.getElementsByTagName('tdlay')[0].innerHTML;
document.S_form.TLBRI.value = this.responseXML.getElementsByTagName('tlbri')[0].innerHTML;
document.S_form.TLDUR.value = this.responseXML.getElementsByTagName('tldur')[0].innerHTML;
document.S_form.TLFDE.checked = (this.responseXML.getElementsByTagName('tlfde')[0].innerHTML)!=0?true:false;
document.S_form.NUDPP.value = this.responseXML.getElementsByTagName('nudpp')[0].innerHTML;
document.S_form.NRCVE.checked = (this.responseXML.getElementsByTagName('nrcve')[0].innerHTML)!=0?true:false;
document.S_form.NRBRI.value = this.responseXML.getElementsByTagName('nrbri')[0].innerHTML;
document.S_form.NSDIR.checked = (this.responseXML.getElementsByTagName('nsdir')[0].innerHTML)!=0?true:false;
document.S_form.NSBTN.checked = (this.responseXML.getElementsByTagName('nsbtn')[0].innerHTML)!=0?true:false;
document.S_form.NSFWD.checked = (this.responseXML.getElementsByTagName('nsfwd')[0].innerHTML)!=0?true:false;
document.S_form.NSIPS.innerHTML = this.responseXML.getElementsByTagName('nsips')[0].innerHTML;
document.S_form.NOOTA.checked = (this.responseXML.getElementsByTagName('noota')[0].innerHTML)!=0?true:false;
document.S_form.NORAP.checked = (this.responseXML.getElementsByTagName('norap')[0].innerHTML)!=0?true:false;
document.getElementsByClassName("sip")[0].innerHTML = this.responseXML.getElementsByTagName('sip')[0].innerHTML;
@ -102,25 +103,26 @@
AP IP: <span class="sip"> Not active </span> <br>
<h2>Application setup</h2>
<h3>Web setup</h3>
Server description: <input type="text" name="DESC" maxlength="32"> <br>
<h3>LED setup</h3>
The default boot LED color is the current color when settings are saved. <br>
LED amount: <input type="text" name="LEDS" maxlength="3" size="2"> <br>
Brightness factor: <input type="text" name="NRBRI" maxlength="3" size="2"> % <br>
<h3>Button setup</h3>
On/Off button enabled: <input type="checkbox" name="BTNON" value="0"> <br>
<h3>Transitions</h3>
Fade: <input type="checkbox" name="TFADE" value="0"> <br>
Transition Delay: <input type="text" name="TDLAY" maxlength="5" size="2"> ms <br>
<h3>Timed light</h3>
Turn off after: <input type="text" name="TLDUR" maxlength="3" size="2"> min <br>
Fade down: <input type="checkbox" name="TLFDE" value="0"> <br>
Target brightness: <input type="text" name="TLBRI" maxlength="3" size="2"> (0-255) <br>
Change after: <input type="text" name="TLDUR" maxlength="3" size="2"> min <br>
Fade: <input type="checkbox" name="TLFDE" value="0"> <br>
<h3>Daisy chain</h3>
UDP Port: <input type="text" name="NUDPP" maxlength="5" size="2"><br>
Receive notifications: <input type="checkbox" name="NRCVE" value="0"> <br>
Received brightness factor: <input type="text" name="NRBRI" maxlength="3" size="2"> % <br><br>
Send notifications on direct change: <input type="checkbox" name="NSDIR" value="0"> <br>
Send notifications on button press: <input type="checkbox" name="NSBTN" value="0"> <br>
Forward received notifications: <input type="checkbox" name="NSFWD" value="0"> <br>
Hosts to send notifications to: (1 IP per line) <br>
<textarea name="NSIPS" rows="8" cols="16"></textarea>
Send nightlight notifications: <input type="checkbox" name="NSFWD" value="0"> <br>
<h3>Security</h3>
OTA locked: <input type="checkbox" name="NOOTA" value="0"> <br>
Passphrase: <input type="password" name="OPASS" maxlength="32"> <br>

View File

@ -14,7 +14,11 @@
* @version 0.3pd
* @author Christian Schwinne
*/
//Hardware-settings (only changeble via code)
uint8_t led_amount = 16;
uint8_t buttonPin = 0; //needs pull-up
//Default CONFIG
String serverDescription = "WLED 0.3pd";
String clientssid = "Your_Network_Here";
String clientpass = "Dummy_Pass";
String cmdns = "led";
@ -27,21 +31,20 @@ IPAddress staticip(0, 0, 0, 0);
IPAddress staticgateway(0, 0, 0, 0);
IPAddress staticsubnet(255, 255, 255, 0);
byte col[]{255, 127, 0};
uint8_t bri_nl = 0;
boolean fadeTransition = true;
boolean seqTransition = false;
uint16_t transitionDelay = 1500;
boolean ota_lock = true;
String otapass = "wledota";
boolean only_ap = false;
uint8_t led_amount = 16;
uint8_t buttonPin = 3; //needs pull-up
boolean buttonEnabled = true;
boolean notifyDirect = true, notifyButton = true, notifyForward = true, notifyNightlight = false;
boolean notifyDirect = true, notifyButton = true, notifyNightlight = false;
boolean receiveNotifications = true;
uint8_t bri_n = 100;
uint8_t nightlightDelayMins = 60;
boolean nightlightFade = true;
unsigned int udpPort = 21324;
uint16_t udpPort = 21324;
double transitionResolution = 0.011;
@ -62,7 +65,6 @@ boolean buttonPressedBefore = false;
boolean nightlightActive = false;
boolean nightlightActive_old = false;
int transitionDelay_old;
long nightlightPassedTime = 0;
int nightlightDelayMs;
boolean udpConnected = false;
byte notifierBuffer[16];

View File

@ -41,7 +41,7 @@ void saveSettingsToEEPROM()
EEPROM.write(228, aphide);
EEPROM.write(229, led_amount);
EEPROM.write(230, notifyButton);
EEPROM.write(231, notifyForward);
EEPROM.write(231, notifyNightlight);
EEPROM.write(232, buttonEnabled);
//233 reserved for first boot flag
EEPROM.write(234, staticip[0]);
@ -70,7 +70,14 @@ void saveSettingsToEEPROM()
{
EEPROM.write(i, otapass.charAt(i-256));
}
EEPROM.write(288, bri_nl);
EEPROM.write(289, ota_lock);
EEPROM.write(290, (udpPort >> 0) & 0xFF);
EEPROM.write(291, (udpPort >> 8) & 0xFF);
for (int i = 292; i < 324; ++i)
{
EEPROM.write(i, serverDescription.charAt(i-292));
}
EEPROM.commit();
}
@ -120,7 +127,7 @@ void loadSettingsFromEEPROM()
if (aphide > 1) aphide = 1;
led_amount = EEPROM.read(229);
notifyButton = EEPROM.read(230);
notifyForward = EEPROM.read(231);
notifyNightlight = EEPROM.read(231);
buttonEnabled = EEPROM.read(232);
staticip[0] = EEPROM.read(234);
staticip[1] = EEPROM.read(235);
@ -149,5 +156,13 @@ void loadSettingsFromEEPROM()
if (EEPROM.read(i) == 0) break;
otapass += char(EEPROM.read(i));
}
bri_nl = EEPROM.read(288);
ota_lock = EEPROM.read(289);
udpPort = ((EEPROM.read(290) << 0) & 0xFF) + ((EEPROM.read(291) << 8) & 0xFF00);
serverDescription = "";
for (int i = 292; i < 324; ++i)
{
if (EEPROM.read(i) == 0) break;
serverDescription += char(EEPROM.read(i));
}
}

View File

@ -19,6 +19,12 @@ void XML_response()
resp = resp + col[i];
resp = resp + "</cl>";
}
resp = resp + "<nl>";
resp = resp + nightlightActive;
resp = resp + "</nl>";
resp = resp + "<desc>";
resp = resp + serverDescription;
resp = resp + "</desc>";
//enable toolbar here
resp = resp + "</vs>";
server.send(200, "text/xml", resp);
@ -75,9 +81,9 @@ void XML_response_settings()
resp = resp + "<apchan>";
resp = resp + apchannel;
resp = resp + "</apchan>";
resp = resp + "<leds>";
resp = resp + led_amount;
resp = resp + "</leds>";
resp = resp + "<desc>";
resp = resp + serverDescription;
resp = resp + "</desc>";
resp = resp + "<btnon>";
resp = resp + bool2int(buttonEnabled);
resp = resp + "</btnon><tfade>";
@ -85,12 +91,18 @@ void XML_response_settings()
resp = resp + "</tfade><tdlay>";
resp = resp + transitionDelay;
resp = resp + "</tdlay>";
resp = resp + "<tlbri>";
resp = resp + bri_nl;
resp = resp + "</tlbri>";
resp = resp + "<tldur>";
resp = resp + nightlightDelayMins;
resp = resp + "</tldur>";
resp = resp + "<tlfde>";
resp = resp + bool2int(nightlightFade);
resp = resp + "</tlfde>";
resp = resp + "<nudpp>";
resp = resp + udpPort;
resp = resp + "</nudpp>";
resp = resp + "<nrcve>";
resp = resp + bool2int(receiveNotifications);
resp = resp + "</nrcve><nrbri>";
@ -100,8 +112,8 @@ void XML_response_settings()
resp = resp + "</nsdir><nsbtn>";
resp = resp + bool2int(notifyButton);
resp = resp + "</nsbtn><nsfwd>";
resp = resp + bool2int(notifyForward);
resp = resp + "</nsfwd><nsips>Legacy</nsips>";
resp = resp + bool2int(notifyNightlight);
resp = resp + "</nsfwd>";
resp = resp + "<noota>";
resp = resp + bool2int(ota_lock);
resp = resp +"</noota>";
@ -134,7 +146,7 @@ void XML_response_settings()
{
resp = resp + "Not active";
}
resp = resp + "</sip><otastat>LS</otastat>";
resp = resp + "</sip>";
resp = resp + "<msg>WLED 0.3pd OK</msg>";
resp = resp + "</vs>";
Serial.println(resp);

View File

@ -93,11 +93,7 @@ void handleSettingsSet()
int i = server.arg("CSSN3").toInt();
if (i >= 0 && i <= 255) staticsubnet[3] = i;
}
if (server.hasArg("LEDS"))
{
int i = server.arg("LEDS").toInt();
if (i > 0) led_amount = i;
}
if (server.hasArg("DESC")) serverDescription = server.arg("DESC");
buttonEnabled = server.hasArg("BTNON");
fadeTransition = server.hasArg("TFADE");
if (server.hasArg("TDLAY"))
@ -108,12 +104,20 @@ void handleSettingsSet()
transitionDelay_old = transitionDelay;
}
}
if (server.hasArg("TLBRI"))
{
bri_nl = server.arg("TLBRI").toInt();
}
if (server.hasArg("TLDUR"))
{
int i = server.arg("TLDUR").toInt();
if (i > 0) nightlightDelayMins = i;
}
nightlightFade = server.hasArg("TLFDE");
if (server.hasArg("NUDPP"))
{
udpPort = server.arg("NUDPP").toInt();
}
receiveNotifications = server.hasArg("NRCVE");
if (server.hasArg("NRBRI"))
{
@ -122,7 +126,7 @@ void handleSettingsSet()
}
notifyDirect = server.hasArg("NSDIR");
notifyButton = server.hasArg("NSBTN");
notifyForward = server.hasArg("NSFWD");
notifyNightlight = server.hasArg("NSFWD");
if (server.hasArg("OPASS"))
{
if (!ota_lock)
@ -173,6 +177,7 @@ boolean handleSet(String req)
if (req.indexOf("NL=0") > 0)
{
nightlightActive = false;
bri = bri_t;
} else {
nightlightActive = true;
nightlightStartTime = millis();

View File

@ -59,7 +59,10 @@ void wledInit()
}
Serial.println("mDNS responder started");
if (udpPort > 0)
{
udpConnected = notifierUdp.begin(udpPort);
}
//SERVER INIT
//settings page

View File

@ -1,15 +1,16 @@
void notify(uint8_t callMode)
{
if (!udpConnected) return;
switch (callMode)
{
case 1: if (!notifyDirect) return; break;
case 2: if (!notifyButton) return; break;
case 3: if (!notifyForward) return; break;
case 3: return;
case 4: if (!notifyNightlight) return; break;
default: return;
}
byte udpOut[16];
udpOut[0] = 0; //reserved for future "port" feature
udpOut[0] = 0; //reserved
udpOut[1] = callMode;
udpOut[2] = bri;
udpOut[3] = col[0];
@ -32,21 +33,13 @@ void handleNotifications()
if(packetSize && notifierUdp.remoteIP() != WiFi.localIP())
{
notifierUdp.read(notifierBuffer, 16);
int bri_r = notifierBuffer[2]*(((float)bri_n)/100);
if (bri_r < 256)
{
bri_n = bri_r;
} else
{
bri_n = 255;
}
col[0] = notifierBuffer[3]
col[0] = notifierBuffer[3];
col[1] = notifierBuffer[4];
col[2] = notifierBuffer[5];
if (notifierBuffer[6])
nightlightActive = notifierBuffer[6];
if (!notifierBuffer[6])
{
nightlightActive = true;
} else {
bri = notifierBuffer[2];
colorUpdated(3);
}
}

View File

@ -1,6 +1,10 @@
void setAllLeds() {
double d = bri_t;
double val = d /256;
double d = bri_t*bri_n;
double val = d/25600;
if (val > 1.0)
{
val = 1.0;
}
int r = col_t[0]*val;
int g = col_t[1]*val;
int b = col_t[2]*val;
@ -25,7 +29,7 @@ void setLedsStandard()
void colorUpdated(int callMode)
{
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (no not.)
if (col[0] == col_it[0] && col[1] == col_it[1] && col[2] == col_it[2] && bri == bri_it)
{
return; //no change
@ -97,8 +101,8 @@ void initNightlightFade()
{
return;
}
bri = 0;
bri_it = 0;
bri = bri_nl;
bri_it = bri_nl;
transitionDelay = (int)(nightlightDelayMins*60000);
transitionStartTime = nightlightStartTime;
transitionActive = true;
@ -111,6 +115,7 @@ void handleNightlight()
{
if (!nightlightActive_old) //init
{
nightlightStartTime = millis();
notify(4);
nightlightDelayMs = (int)(nightlightDelayMins*60000);
nightlightActive_old = true;
@ -123,19 +128,19 @@ void handleNightlight()
if (nper >= 1)
{
nightlightActive = false;
}
} else if (nightlightActive_old) //de-init
if (!nightlightFade)
{
bri = bri_nl;
colorUpdated(5);
}
}
} else if (nightlightActive_old) //early de-init
{
nightlightPassedTime = 0;
nightlightActive_old = false;
if (nightlightFade)
{
transitionDelay = transitionDelay_old;
transitionActive = false;
} else
{
bri = 0;
colorUpdated(4);
}
}
}