first notifier working demo

NOTES:
udp broadcast notifier?
timeout problem!!
This commit is contained in:
cschwinne 2016-11-20 00:07:04 +01:00
parent acfdb4ab75
commit e22fb965f7
7 changed files with 42 additions and 13 deletions

View File

@ -35,6 +35,8 @@
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.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.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;

View File

@ -35,28 +35,30 @@ boolean only_ap = false;
uint8_t led_amount = 16;
uint8_t buttonPin = 3; //needs pull-up
boolean buttonEnabled = true;
String notifier_ips[]{"10.10.1.128","10.10.1.129"};
String notifier_ips[]{"10.10.1.191","10.10.1.129"};
boolean notifyDirect = true, notifyButton = true, notifyForward = true;
boolean receiveNotifications = true;
uint8_t bri_n = 100;
uint8_t nightlightDelayMins = 60;
boolean nightlightFade = true;
double transitionResolution = 0.01;
double transitionResolution = 0.015;
//Internal vars
byte col_old[]{0, 0, 0};
byte col_t[]{0, 0, 0};
byte col_it[]{0, 0, 0};
long transitionStartTime;
long nightlightStartTime;
float tper_last = 0;
byte bri = 127;
byte bri_old = 0;
byte bri_t = 0;
byte bri_it = 0;
byte bri_last = 127;
boolean transitionActive = false;
boolean buttonPressedBefore = false;
int notifier_ips_count = 0;
int notifier_ips_count = 1;
String notifier_ips_raw = "";
boolean nightlightActive = false;

View File

@ -34,6 +34,8 @@ void saveSettingsToEEPROM()
{
EEPROM.write(i, appass.charAt(i-160));
}
EEPROM.write(224, nightlightDelayMins);
EEPROM.write(225, nightlightFade);
EEPROM.write(228, aphide);
EEPROM.write(227, apchannel);
EEPROM.write(229, led_amount);

View File

@ -79,6 +79,12 @@ void XML_response_settings()
resp = resp + "</tfade><tdlay>";
resp = resp + transitionDelay;
resp = resp + "</tdlay>";
resp = resp + "<tldur>";
resp = resp + nightlightDelayMins;
resp = resp + "</tldur>";
resp = resp + "<tlfde>";
resp = resp + bool2int(nightlightFade);
resp = resp + "</tlfde>";
resp = resp + "<nrcve>";
resp = resp + bool2int(receiveNotifications);
resp = resp + "</nrcve><nrbri>";

View File

@ -68,6 +68,9 @@ void wledInit()
server.on("/button.png", HTTP_GET, [](){
if(!handleFileRead("/button.png")) server.send(404, "text/plain", "FileNotFound");
});
server.on("/moon.png", HTTP_GET, [](){
if(!handleFileRead("/moon.png")) server.send(404, "text/plain", "FileNotFound");
});
server.on("/favicon.ico", HTTP_GET, [](){
if(!handleFileRead("/favicon.ico")) server.send(404, "text/plain", "FileNotFound");
});

View File

@ -7,7 +7,7 @@ void notify(int callMode)
case 3: if (!notifyForward) return; break;
default: return;
}
String snd = "/ajax_in&N=1&A=";
String snd = "/ajax_inputs&N=1&A=";
snd = snd + bri;
snd = snd + "&R=";
snd = snd + col[0];
@ -15,17 +15,27 @@ void notify(int callMode)
snd = snd + col[1];
snd = snd + "&B=";
snd = snd + col[2];
//snd = snd + " HTTP/1.1";
HTTPClient hclient;
WiFiClient hclient;
hclient.setTimeout(50);
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();
Serial.println("NCON...");
if (hclient.connect(notifier_ips[i].c_str(), 80))
{
Serial.println("CON!");
Serial.println(snd);
hclient.print(String("GET ") + snd + " HTTP/1.1\r\n" +
"Host: " + notifier_ips[i] + "\r\n" +
"Connection: close\r\n\r\n");
} else
{
Serial.println("NO CONNECTION");
hclient.stop();
}
}
}

View File

@ -26,10 +26,14 @@ void setLedsStandard()
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)
if (col[0] == col_it[0] && col[1] == col_it[1] && col[2] == col_it[2] && bri == bri_it)
{
return; //no change
}
col_it[0] = col[0];
col_it[1] = col[1];
col_it[2] = col[2];
bri_it = bri;
if (bri > 0) bri_last = bri;
notify(callMode);
if (fadeTransition || seqTransition)