notifier base function implemented
notifier settings getter implemented
This commit is contained in:
parent
9baf2f3eb8
commit
def391b282
1
TODO.txt
1
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
|
||||
|
@ -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: <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>
|
||||
Send received notifications: <input type="checkbox" name="NSRCV" 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>
|
||||
<h3>Security</h3>
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <ESP8266HTTPUpdateServer.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <EEPROM.h>
|
||||
@ -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<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(led_amount, 1);
|
||||
|
||||
@ -273,14 +279,32 @@ void XML_response_settings()
|
||||
resp = resp + "</apchan>";
|
||||
resp = resp + "<leds>";
|
||||
resp = resp + led_amount;
|
||||
resp = resp + "</leds><tfade>";
|
||||
resp = resp + "</leds>";
|
||||
resp = resp + "<btnon>";
|
||||
resp = resp + bool2int(buttonEnabled);
|
||||
resp = resp + "</btnon><tfade>";
|
||||
resp = resp + bool2int(fadeTransition);
|
||||
resp = resp + "</tfade><tdlay>";
|
||||
resp = resp + transitionDelay;
|
||||
resp = resp + "</tdlay>";
|
||||
resp = resp + "<btnon>";
|
||||
resp = resp + bool2int(buttonEnabled);
|
||||
resp = resp + "</btnon><noota>0</noota>"; //NI
|
||||
resp = resp + "<nrcve>";
|
||||
resp = resp + bool2int(receiveNotifications);
|
||||
resp = resp + "</nrcve><nrbri>";
|
||||
resp = resp + bri_n;
|
||||
resp = resp + "</nrbri><nsdir>";
|
||||
resp = resp + bool2int(notifyDirect);
|
||||
resp = resp + "</nsdir><nsbtn>";
|
||||
resp = resp + bool2int(notifyButton);
|
||||
resp = resp + "</nsbtn><nsfwd>";
|
||||
resp = resp + bool2int(notifyForward);
|
||||
resp = resp + "</nsfwd><nsips>";
|
||||
for (int i = 0; i < notifier_ips_count; i++)
|
||||
{
|
||||
resp = resp + notifier_ips[i];
|
||||
resp = resp + "\n";
|
||||
}
|
||||
resp = resp + "</nsips>";
|
||||
resp = resp + "<noota>0</noota>"; //NI
|
||||
resp = resp + "<norap>0</norap>"; //NI
|
||||
resp = resp + "<sip>";
|
||||
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();
|
||||
@ -454,8 +480,19 @@ boolean handleSet(String req)
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user