udp notifier finished
This commit is contained in:
parent
c88b9d6143
commit
a3a2c0448f
4
TODO.txt
4
TODO.txt
@ -2,13 +2,12 @@ color cycle
|
|||||||
sequence
|
sequence
|
||||||
simple slide transition
|
simple slide transition
|
||||||
additional color picker field
|
additional color picker field
|
||||||
implement all settings setters
|
implement all settings setters (notifyNightlight \n udpPort)
|
||||||
implement HSB slider option
|
implement HSB slider option
|
||||||
implement ranges
|
implement ranges
|
||||||
implement discrete range color setter
|
implement discrete range color setter
|
||||||
implement discrete single color setter
|
implement discrete single color setter
|
||||||
svg icons in html
|
svg icons in html
|
||||||
notifier function -> send get request
|
|
||||||
add preferred colors to settings -> quickly t. UI, button select,
|
add preferred colors to settings -> quickly t. UI, button select,
|
||||||
use iframe for settings, seperate tabs for wifi and application confg
|
use iframe for settings, seperate tabs for wifi and application confg
|
||||||
use iframe for all adv. features?
|
use iframe for all adv. features?
|
||||||
@ -20,4 +19,3 @@ BUGS
|
|||||||
static ip disables mdns
|
static ip disables mdns
|
||||||
? authentification for security relevant areas ([/settings, /reset])
|
? authentification for security relevant areas ([/settings, /reset])
|
||||||
(Unverified) led_amount does nothing (is always 16) because NeoPixelBus is initiated before EEPROM read
|
(Unverified) led_amount does nothing (is always 16) because NeoPixelBus is initiated before EEPROM read
|
||||||
notifier wrong ips
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
#include <ESP8266HTTPClient.h>
|
|
||||||
#include <ESP8266HTTPUpdateServer.h>
|
#include <ESP8266HTTPUpdateServer.h>
|
||||||
#include <ESP8266mDNS.h>
|
#include <ESP8266mDNS.h>
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include <Hash.h>
|
#include <Hash.h>
|
||||||
#include <NeoPixelBus.h>
|
#include <NeoPixelBus.h>
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
#include <WiFiUDP.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @title WLED project sketch
|
* @title WLED project sketch
|
||||||
@ -36,12 +36,12 @@ boolean only_ap = false;
|
|||||||
uint8_t led_amount = 16;
|
uint8_t led_amount = 16;
|
||||||
uint8_t buttonPin = 3; //needs pull-up
|
uint8_t buttonPin = 3; //needs pull-up
|
||||||
boolean buttonEnabled = true;
|
boolean buttonEnabled = true;
|
||||||
String notifier_ips[]{"10.10.1.191","10.10.1.129"};
|
|
||||||
boolean notifyDirect = true, notifyButton = true, notifyForward = true, notifyNightlight = false;
|
boolean notifyDirect = true, notifyButton = true, notifyForward = true, notifyNightlight = false;
|
||||||
boolean receiveNotifications = true;
|
boolean receiveNotifications = true;
|
||||||
uint8_t bri_n = 100;
|
uint8_t bri_n = 100;
|
||||||
uint8_t nightlightDelayMins = 60;
|
uint8_t nightlightDelayMins = 60;
|
||||||
boolean nightlightFade = true;
|
boolean nightlightFade = true;
|
||||||
|
unsigned int udpPort = 21324;
|
||||||
|
|
||||||
double transitionResolution = 0.011;
|
double transitionResolution = 0.011;
|
||||||
|
|
||||||
@ -59,18 +59,19 @@ byte bri_it = 0;
|
|||||||
byte bri_last = 127;
|
byte bri_last = 127;
|
||||||
boolean transitionActive = false;
|
boolean transitionActive = false;
|
||||||
boolean buttonPressedBefore = false;
|
boolean buttonPressedBefore = false;
|
||||||
int notifier_ips_count = 1;
|
|
||||||
String notifier_ips_raw = "";
|
|
||||||
boolean nightlightActive = false;
|
boolean nightlightActive = false;
|
||||||
boolean nightlightActive_old = false;
|
boolean nightlightActive_old = false;
|
||||||
int transitionDelay_old;
|
int transitionDelay_old;
|
||||||
long nightlightPassedTime = 0;
|
long nightlightPassedTime = 0;
|
||||||
int nightlightDelayMs;
|
int nightlightDelayMs;
|
||||||
|
boolean udpConnected = false;
|
||||||
|
byte notifierBuffer[16];
|
||||||
|
|
||||||
NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(led_amount, 1);
|
NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(led_amount, 1);
|
||||||
|
|
||||||
ESP8266WebServer server(80);
|
ESP8266WebServer server(80);
|
||||||
ESP8266HTTPUpdateServer httpUpdater;
|
ESP8266HTTPUpdateServer httpUpdater;
|
||||||
|
WiFiUDP notifierUdp;
|
||||||
|
|
||||||
File fsUploadFile;
|
File fsUploadFile;
|
||||||
|
|
||||||
@ -102,6 +103,7 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
|
handleNotifications();
|
||||||
handleTransitions();
|
handleTransitions();
|
||||||
handleNightlight();
|
handleNightlight();
|
||||||
handleButton();
|
handleButton();
|
||||||
|
@ -101,13 +101,7 @@ void XML_response_settings()
|
|||||||
resp = resp + bool2int(notifyButton);
|
resp = resp + bool2int(notifyButton);
|
||||||
resp = resp + "</nsbtn><nsfwd>";
|
resp = resp + "</nsbtn><nsfwd>";
|
||||||
resp = resp + bool2int(notifyForward);
|
resp = resp + bool2int(notifyForward);
|
||||||
resp = resp + "</nsfwd><nsips>";
|
resp = resp + "</nsfwd><nsips>Legacy</nsips>";
|
||||||
for (int i = 0; i < notifier_ips_count; i++)
|
|
||||||
{
|
|
||||||
resp = resp + notifier_ips[i];
|
|
||||||
resp = resp + "\n";
|
|
||||||
}
|
|
||||||
resp = resp + "</nsips>";
|
|
||||||
resp = resp + "<noota>";
|
resp = resp + "<noota>";
|
||||||
resp = resp + bool2int(ota_lock);
|
resp = resp + bool2int(ota_lock);
|
||||||
resp = resp +"</noota>";
|
resp = resp +"</noota>";
|
||||||
|
@ -123,10 +123,6 @@ void handleSettingsSet()
|
|||||||
notifyDirect = server.hasArg("NSDIR");
|
notifyDirect = server.hasArg("NSDIR");
|
||||||
notifyButton = server.hasArg("NSBTN");
|
notifyButton = server.hasArg("NSBTN");
|
||||||
notifyForward = server.hasArg("NSFWD");
|
notifyForward = server.hasArg("NSFWD");
|
||||||
if (server.hasArg("NSIPS"))
|
|
||||||
{
|
|
||||||
notifier_ips_raw = server.arg("NSIPS");
|
|
||||||
}
|
|
||||||
if (server.hasArg("OPASS"))
|
if (server.hasArg("OPASS"))
|
||||||
{
|
{
|
||||||
if (!ota_lock)
|
if (!ota_lock)
|
||||||
@ -156,8 +152,6 @@ boolean handleSet(String req)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
boolean isNotification = false;
|
|
||||||
if (req.indexOf("N=") > 0) isNotification = true;
|
|
||||||
pos = req.indexOf("A=");
|
pos = req.indexOf("A=");
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
bri = req.substring(pos + 2).toInt();
|
bri = req.substring(pos + 2).toInt();
|
||||||
@ -184,17 +178,6 @@ boolean handleSet(String req)
|
|||||||
nightlightStartTime = millis();
|
nightlightStartTime = millis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isNotification)
|
|
||||||
{
|
|
||||||
if (receiveNotifications)
|
|
||||||
{
|
|
||||||
colorUpdated(3);
|
|
||||||
server.send(200, "text/plain", "");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
server.send(202, "text/plain", "");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
XML_response();
|
XML_response();
|
||||||
colorUpdated(1);
|
colorUpdated(1);
|
||||||
return true;
|
return true;
|
||||||
|
@ -59,6 +59,8 @@ void wledInit()
|
|||||||
}
|
}
|
||||||
Serial.println("mDNS responder started");
|
Serial.println("mDNS responder started");
|
||||||
|
|
||||||
|
udpConnected = notifierUdp.begin(udpPort);
|
||||||
|
|
||||||
//SERVER INIT
|
//SERVER INIT
|
||||||
//settings page
|
//settings page
|
||||||
server.on("/settings", HTTP_GET, [](){
|
server.on("/settings", HTTP_GET, [](){
|
||||||
@ -123,15 +125,12 @@ void wledInit()
|
|||||||
|
|
||||||
server.begin();
|
server.begin();
|
||||||
Serial.println("HTTP server started");
|
Serial.println("HTTP server started");
|
||||||
|
|
||||||
// Add service to MDNS
|
// Add service to MDNS
|
||||||
MDNS.addService("http", "tcp", 80);
|
MDNS.addService("http", "tcp", 80);
|
||||||
// Initialize NeoPixel Strip
|
// Initialize NeoPixel Strip
|
||||||
strip.Begin();
|
strip.Begin();
|
||||||
colorUpdated(0);
|
colorUpdated(0);
|
||||||
pinMode(buttonPin, INPUT_PULLUP);
|
pinMode(buttonPin, INPUT_PULLUP);
|
||||||
|
|
||||||
Serial.println(otapass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void initAP(){
|
void initAP(){
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
void notify(int callMode)
|
void notify(uint8_t callMode)
|
||||||
{
|
{
|
||||||
switch (callMode)
|
switch (callMode)
|
||||||
{
|
{
|
||||||
@ -8,35 +8,49 @@ void notify(int callMode)
|
|||||||
case 4: if (!notifyNightlight) return; break;
|
case 4: if (!notifyNightlight) return; break;
|
||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
String snd = "/ajax_inputs&N=1&A=";
|
byte udpOut[16];
|
||||||
snd = snd + bri;
|
udpOut[0] = 0; //reserved for future "port" feature
|
||||||
snd = snd + "&R=";
|
udpOut[1] = callMode;
|
||||||
snd = snd + col[0];
|
udpOut[2] = bri;
|
||||||
snd = snd + "&G=";
|
udpOut[3] = col[0];
|
||||||
snd = snd + col[1];
|
udpOut[4] = col[1];
|
||||||
snd = snd + "&B=";
|
udpOut[5] = col[2];
|
||||||
snd = snd + col[2];
|
udpOut[6] = nightlightActive;
|
||||||
//snd = snd + " HTTP/1.1";
|
|
||||||
|
|
||||||
WiFiClient hclient;
|
IPAddress broadcastIp;
|
||||||
hclient.setTimeout(50);
|
broadcastIp = ~WiFi.subnetMask() | WiFi.gatewayIP();
|
||||||
|
|
||||||
for (int i = 0; i < notifier_ips_count; i++)
|
notifierUdp.beginPacket(broadcastIp, udpPort);
|
||||||
|
notifierUdp.write(udpOut, 16);
|
||||||
|
notifierUdp.endPacket();
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleNotifications()
|
||||||
|
{
|
||||||
|
if(udpConnected && receiveNotifications){
|
||||||
|
int packetSize = notifierUdp.parsePacket();
|
||||||
|
if(packetSize && notifierUdp.remoteIP() != WiFi.localIP())
|
||||||
{
|
{
|
||||||
|
notifierUdp.read(notifierBuffer, 16);
|
||||||
Serial.println("NCON...");
|
int bri_r = notifierBuffer[2]*(((float)bri_n)/100);
|
||||||
if (hclient.connect(notifier_ips[i].c_str(), 80))
|
if (bri_r < 256)
|
||||||
{
|
{
|
||||||
Serial.println("CON!");
|
bri_n = bri_r;
|
||||||
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
|
} else
|
||||||
{
|
{
|
||||||
Serial.println("NO CONNECTION");
|
bri_n = 255;
|
||||||
hclient.stop();
|
}
|
||||||
|
col[0] = notifierBuffer[3]
|
||||||
|
col[1] = notifierBuffer[4];
|
||||||
|
col[2] = notifierBuffer[5];
|
||||||
|
if (notifierBuffer[6])
|
||||||
|
{
|
||||||
|
nightlightActive = true;
|
||||||
|
} else {
|
||||||
|
colorUpdated(3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,6 +111,7 @@ void handleNightlight()
|
|||||||
{
|
{
|
||||||
if (!nightlightActive_old) //init
|
if (!nightlightActive_old) //init
|
||||||
{
|
{
|
||||||
|
notify(4);
|
||||||
nightlightDelayMs = (int)(nightlightDelayMins*60000);
|
nightlightDelayMs = (int)(nightlightDelayMins*60000);
|
||||||
nightlightActive_old = true;
|
nightlightActive_old = true;
|
||||||
if (nightlightFade)
|
if (nightlightFade)
|
||||||
|
Loading…
Reference in New Issue
Block a user