diff --git a/TODO.txt b/TODO.txt index 9eaca2f4..d4930924 100644 --- a/TODO.txt +++ b/TODO.txt @@ -13,6 +13,7 @@ svg icons in html notifier function -> send get request nightlight function -> turns off after set time (+implement fading) add preferred colors to settings -> quickly t. UI, button select, +use iframe for settings, seperate tabs for wifi and application confg BUGS static ip disables mdns diff --git a/wled00/data/settings.htm b/wled00/data/settings.htm index 805949cc..0217df2e 100644 --- a/wled00/data/settings.htm +++ b/wled00/data/settings.htm @@ -35,6 +35,12 @@ 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.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; @@ -112,7 +118,7 @@ Received brightness factor: %

Send notifications on direct change:
Send notifications on button press:
- Send received notifications:
+ Forward received notifications:
Hosts to send notifications to: (1 IP per line)

Security

diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 72edb391..51b2ec1c 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -34,6 +35,10 @@ boolean only_ap = false; int led_amount = 16; int buttonPin = 3; //needs pull-up boolean buttonEnabled = true; +String notifier_ips[]{"10.10.1.128","10.10.1.129"}; +boolean notifyDirect = true, notifyButton = true, notifyForward = true; +boolean receiveNotifications = true; +uint8_t bri_n = 100; //Internal vars byte col_old[]{0, 0, 0}; @@ -45,6 +50,7 @@ byte bri_t = 0; byte bri_last = 127; boolean transitionActive = false; boolean buttonPressedBefore = false; +int notifier_ips_count = 2; NeoPixelBus strip(led_amount, 1); @@ -273,14 +279,32 @@ void XML_response_settings() resp = resp + ""; resp = resp + ""; resp = resp + led_amount; - resp = resp + ""; + resp = resp + ""; + resp = resp + ""; + resp = resp + bool2int(buttonEnabled); + resp = resp + ""; resp = resp + bool2int(fadeTransition); resp = resp + ""; resp = resp + transitionDelay; resp = resp + ""; - resp = resp + ""; - resp = resp + bool2int(buttonEnabled); - resp = resp + "0"; //NI + resp = resp + ""; + resp = resp + bool2int(receiveNotifications); + resp = resp + ""; + resp = resp + bri_n; + resp = resp + ""; + resp = resp + bool2int(notifyDirect); + resp = resp + ""; + resp = resp + bool2int(notifyButton); + resp = resp + ""; + resp = resp + bool2int(notifyForward); + resp = resp + ""; + for (int i = 0; i < notifier_ips_count; i++) + { + resp = resp + notifier_ips[i]; + resp = resp + "\n"; + } + resp = resp + ""; + resp = resp + "0"; //NI resp = resp + "0"; //NI resp = resp + ""; if (!WiFi.localIP()[0] == 0) @@ -438,6 +462,8 @@ boolean handleSet(String req) return false; } int pos = 0; + boolean isNotification = false; + if (req.indexOf("N=") > 0) isNotification = true; pos = req.indexOf("A="); if (pos > 0) { bri = req.substring(pos + 2).toInt(); @@ -453,9 +479,20 @@ boolean handleSet(String req) pos = req.indexOf("B="); if (pos > 0) { col[2] = req.substring(pos + 2).toInt(); - } + } + if (isNotification) + { + if (receiveNotifications) + { + colorUpdated(3); + server.send(200, "text/plain", ""); + return true; + } + server.send(202, "text/plain", ""); + return true; + } XML_response(); - colorUpdated(); + colorUpdated(1); return true; } @@ -580,7 +617,37 @@ void handleFileList() { server.send(200, "text/json", output); } -void notify(){}; +void notify(int callMode) +{ + switch (callMode) + { + case 1: if (!notifyDirect) return; break; + case 2: if (!notifyButton) return; break; + case 3: if (!notifyForward) return; break; + default: return; + } + String snd = "/ajax_in&N=1&A="; + snd = snd + bri; + snd = snd + "&R="; + snd = snd + col[0]; + snd = snd + "&G="; + snd = snd + col[1]; + snd = snd + "&B="; + snd = snd + col[2]; + + HTTPClient hclient; + + for (int i = 0; i < notifier_ips_count; i++) + { + String url = "http://"; + url = url + notifier_ips[i]; + url = url + snd; + + hclient.begin(url); + hclient.GET(); + hclient.end(); + } +} void setAllLeds() { double d = bri_t; @@ -607,14 +674,15 @@ void setLedsStandard() setAllLeds(); } -void colorUpdated() +void colorUpdated(int callMode) { + //call for notifier -> 0: init 1: direct change 2: button 3: notification if (col[0] == col_old[0] && col[1] == col_old[1] && col[2] == col_old[2] && bri == bri_old) { return; //no change } if (bri > 0) bri_last = bri; - notify(); + notify(callMode); if (fadeTransition || seqTransition) { if (transitionActive) @@ -674,7 +742,7 @@ void handleButton() bri_last = bri; bri = 0; } - colorUpdated(); + colorUpdated(2); } else if (digitalRead(buttonPin) == HIGH && buttonPressedBefore) { @@ -795,7 +863,7 @@ void setup() { MDNS.addService("http", "tcp", 80); // Initialize NeoPixel Strip strip.Begin(); - colorUpdated(); + colorUpdated(0); pinMode(buttonPin, INPUT_PULLUP); }