Add udpNotifier2 (JSON+HTTP, closes #1205 )

Added Loxone defines
Fix missing timezones (#1201)
This commit is contained in:
cschwinne 2020-09-27 11:43:28 +02:00
parent b10ab358da
commit 8d3ff16037
13 changed files with 326 additions and 334 deletions

View File

@ -62,7 +62,31 @@ void colorHStoRGB(uint16_t hue, byte sat, byte* rgb) //hue, sat to rgb
if (useRGBW && strip.rgbwMode == RGBW_MODE_LEGACY) colorRGBtoRGBW(col);
}
void colorCTtoRGB(uint16_t mired, byte* rgb) //white spectrum to rgb
void colorKtoRGB(uint16_t kelvin, byte* rgb) //white spectrum to rgb, calc
{
float r = 0, g = 0, b = 0;
float temp = kelvin / 100;
if (temp <= 66) {
r = 255;
g = round(99.4708025861 * log(temp) - 161.1195681661);
if (temp <= 19) {
b = 0;
} else {
b = round(138.5177312231 * log((temp - 10)) - 305.0447927307);
}
} else {
r = round(329.698727446 * pow((temp - 60), -0.1332047592));
g = round(288.1221695283 * pow((temp - 60), -0.0755148492));
b = 255;
}
g += 15; //mod by Aircoookie, a bit less accurate but visibly less pinkish
rgb[0] = (uint8_t) constrain(r, 0, 255);
rgb[1] = (uint8_t) constrain(g, 0, 255);
rgb[2] = (uint8_t) constrain(b, 0, 255);
rgb[3] = 0;
}
void colorCTtoRGB(uint16_t mired, byte* rgb) //white spectrum to rgb, bins
{
//this is only an approximation using WS2812B with gamma correction enabled
if (mired > 475) {

View File

@ -31,16 +31,14 @@ Infrared remote:
<a href="https://github.com/Aircoookie/WLED/wiki/Infrared-Control" target="_blank">IR info</a>
<h3>WLED Broadcast</h3>
UDP Port: <input name="UP" type="number" min="1" max="65535" class="d5" required><br>
2nd Port: <input name="U2" type="number" min="1" max="65535" class="d5" required><br>
Receive <input type="checkbox" name="RB">Brightness, <input type="checkbox" name="RC">Color, and <input type="checkbox" name="RX">Effects<br>
Send notifications on direct change: <input type="checkbox" name="SD"><br>
Send notifications on button press: <input type="checkbox" name="SB"><br>
Send Alexa notifications: <input type="checkbox" name="SA"><br>
Send Philips Hue change notifications: <input type="checkbox" name="SH"><br>
Send Macro notifications: <input type="checkbox" name="SM"><br>
Send notifications twice: <input type="checkbox" name="S2">
<h3>UDP Api</h3>
Enable UDP Api: <input type="checkbox" name="UAE"><br>
Port: <input name="UAP" type="number" min="1" max="65535" class="d5"><br>
Send notifications twice: <input type="checkbox" name="S2"><br>
<i>Reboot required to apply changes. </i>
<h3>Realtime</h3>
Receive UDP realtime: <input type="checkbox" name="RD"><br><br>

View File

@ -103,7 +103,11 @@
<option value="10">JST(KST)</option>
<option value="11">AEST/AEDT</option>
<option value="12">NZST/NZDT</option>
<option value="13">North Korea</option>
<option value="13">North Korea</option>
<option value="14">IST (India)</option>
<option value="15">CA-Saskatchewan</option>
<option value="16">ACST</option>
<option value="17">ACST/ACDT</option>
</select><br>
UTC offset: <input name="UO" type="number" min="-65500" max="65500" required> seconds (max. 18 hours)<br>
Current local time is <span class="times">unknown</span>.

View File

@ -30,6 +30,7 @@ void colorFromUint32(uint32_t in, bool secondary = false);
void colorFromUint24(uint32_t in, bool secondary = false);
void relativeChangeWhite(int8_t amount, byte lowerBoundary = 0);
void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb
void colorKtoRGB(uint16_t kelvin, byte* rgb);
void colorCTtoRGB(uint16_t mired, byte* rgb); //white spectrum to rgb
void colorXYtoRGB(float x, float y, byte* rgb); // only defined if huesync disabled TODO
@ -102,6 +103,10 @@ void updateInterfaces(uint8_t callMode);
void handleTransitions();
void handleNightlight();
//lx_parser.cpp
bool parseLx(int lxValue, byte* rgbw);
void parseLxJson(int lxValue, byte segId, bool secondary);
//mqtt.cpp
bool initMqtt();
void publishMqtt();
@ -223,7 +228,4 @@ void sappend(char stype, const char* key, int val);
void sappends(char stype, const char* key, char* val);
void getSettingsJS(byte subPage, char* dest);
//lx_parser.cpp
bool parseLx(int lxValue, int rgbw[4]);
#endif

View File

@ -167,163 +167,163 @@ const char PAGE_settings_dmx[] PROGMEM = R"=====()=====";
// Autogenerated from wled00/data/settings_ui.htm, do not edit!!
const char PAGE_settings_ui[] PROGMEM = R"=====(<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport"
content="width=500"><title>UI Settings</title><script>var d = document;
var initial_ds, initial_st;
var sett = null;
var l = {
"comp":{
"labels":"Show button labels",
"colors":{
"LABEL":"Color selection methods",
"picker": "Color Wheel",
"rgb": "RGB sliders",
"quick": "Quick color selectors",
"hex": "HEX color input"
},
"pcmbot": "Show bottom tab bar in PC mode"
},
"theme":{
"alpha": {
"bg":"Background opacity",
"tab":"Button opacity"
},
"bg":{
"url":"BG image URL"
},
"color":{
"bg":"BG HEX color"
}
}
};
function gId(s)
{
return d.getElementById(s);
}
function isObject(item) {
return (item && typeof item === 'object' && !Array.isArray(item));
}
function set(path, obj, val) {
var tar = obj;
var pList = path.split('_');
var len = pList.length;
for(var i = 0; i < len-1; i++) {
var elem = pList[i];
if( !tar[elem] ) tar[elem] = {}
tar = tar[elem];
}
var initial_ds, initial_st;
var sett = null;
var l = {
"comp":{
"labels":"Show button labels",
"colors":{
"LABEL":"Color selection methods",
"picker": "Color Wheel",
"rgb": "RGB sliders",
"quick": "Quick color selectors",
"hex": "HEX color input"
},
"pcmbot": "Show bottom tab bar in PC mode"
},
"theme":{
"alpha": {
"bg":"Background opacity",
"tab":"Button opacity"
},
"bg":{
"url":"BG image URL"
},
"color":{
"bg":"BG HEX color"
}
}
tar[pList[len-1]] = val;
}
};
function gId(s)
{
return d.getElementById(s);
}
function isObject(item) {
return (item && typeof item === 'object' && !Array.isArray(item));
}
function set(path, obj, val) {
var tar = obj;
var pList = path.split('_');
var len = pList.length;
for(var i = 0; i < len-1; i++) {
var elem = pList[i];
if( !tar[elem] ) tar[elem] = {}
tar = tar[elem];
}
function addRec(s, path = "", label = null)
{
var str = "";
for (i in s)
{
var fk = path + (path?'_':'') + i;
if (isObject(s[i])) {
if (label && label[i] && label[i]["LABEL"]) str += `<h3>${label[i]["LABEL"]}</h3>`;
str += addRec(s[i], fk, label? label[i] : null);
} else {
var lb = fk;
if (label && label[i]) lb = label[i];
else if (s[i+'LABEL']) lb = s[i+'LABEL'];
if (i.indexOf('LABEL') > 0) continue;
var t = typeof s[i];
if (gId(fk)) { //already exists
if(t === 'boolean')
{
gId(fk).checked = s[i];
} else {
gId(fk).value = s[i];
}
if (gId(fk).previousElementSibling.matches('.l')) {
gId(fk).previousElementSibling.innerHTML = lb;
}
} else {
if(t === 'boolean')
{
str += `${lb}: <input class="agi cb" type="checkbox" id=${fk} ${s[i]?"checked":""}><br>`;
} else if (t === 'number')
{
str += `${lb}: <input class="agi" type="number" id=${fk} value=${s[i]}><br>`;
} else if (t === 'string')
{
str += `${lb}:<br><input class="agi" id=${fk} value=${s[i]}><br>`;
}
}
}
}
return str;
}
tar[pList[len-1]] = val;
}
function genForm(s) {
var str = "";
str = addRec(s,"",l);
gId('gen').innerHTML = str;
}
function GetLS()
{
sett = localStorage.getItem('wledUiCfg');
if (!sett) gId('lserr').style.display = "inline";
try {
sett = JSON.parse(sett);
} catch (e) {
sett = {};
gId('lserr').style.display = "inline";
gId('lserr').innerHTML = "&#9888; Settings JSON parsing failed. (" + e + ")";
}
genForm(sett);
gId('dm').checked = (gId('theme_base').value === 'light');
}
function SetLS()
{
var l = d.querySelectorAll('.agi');
for (var i = 0; i < l.length; i++) {
var e = l[i];
var val = e.classList.contains('cb') ? e.checked : e.value;
set(e.id, sett, val);
console.log(`${e.id} set to ${val}`);
}
try {
localStorage.setItem('wledUiCfg', JSON.stringify(sett));
gId('lssuc').style.display = "inline";
} catch (e) {
gId('lssuc').style.display = "none";
gId('lserr').style.display = "inline";
gId('lserr').innerHTML = "&#9888; Settings JSON saving failed. (" + e + ")";
}
}
function Save() {
SetLS();
if (d.Sf.DS.value != initial_ds || d.Sf.ST.checked != initial_st) d.Sf.submit();
}
function S()
{
GetV();
initial_ds = d.Sf.DS.value;
initial_st = d.Sf.ST.checked;
GetLS();
}
function H()
{
window.open("https://github.com/Aircoookie/WLED/wiki/Settings#user-interface-settings");
}
function B()
{
window.open("/settings","_self");
}
function UI()
{
gId('idonthateyou').style.display = (gId('dm').checked) ? 'inline':'none';
var f = gId('theme_base');
if (f) f.value = (gId('dm').checked) ? 'light':'dark';
}
function GetV() {var d=document;
function addRec(s, path = "", label = null)
{
var str = "";
for (i in s)
{
var fk = path + (path?'_':'') + i;
if (isObject(s[i])) {
if (label && label[i] && label[i]["LABEL"]) str += `<h3>${label[i]["LABEL"]}</h3>`;
str += addRec(s[i], fk, label? label[i] : null);
} else {
var lb = fk;
if (label && label[i]) lb = label[i];
else if (s[i+'LABEL']) lb = s[i+'LABEL'];
if (i.indexOf('LABEL') > 0) continue;
var t = typeof s[i];
if (gId(fk)) { //already exists
if(t === 'boolean')
{
gId(fk).checked = s[i];
} else {
gId(fk).value = s[i];
}
if (gId(fk).previousElementSibling.matches('.l')) {
gId(fk).previousElementSibling.innerHTML = lb;
}
} else {
if(t === 'boolean')
{
str += `${lb}: <input class="agi cb" type="checkbox" id=${fk} ${s[i]?"checked":""}><br>`;
} else if (t === 'number')
{
str += `${lb}: <input class="agi" type="number" id=${fk} value=${s[i]}><br>`;
} else if (t === 'string')
{
str += `${lb}:<br><input class="agi" id=${fk} value=${s[i]}><br>`;
}
}
}
}
return str;
}
function genForm(s) {
var str = "";
str = addRec(s,"",l);
gId('gen').innerHTML = str;
}
function GetLS()
{
sett = localStorage.getItem('wledUiCfg');
if (!sett) gId('lserr').style.display = "inline";
try {
sett = JSON.parse(sett);
} catch (e) {
sett = {};
gId('lserr').style.display = "inline";
gId('lserr').innerHTML = "&#9888; Settings JSON parsing failed. (" + e + ")";
}
genForm(sett);
gId('dm').checked = (gId('theme_base').value === 'light');
}
function SetLS()
{
var l = d.querySelectorAll('.agi');
for (var i = 0; i < l.length; i++) {
var e = l[i];
var val = e.classList.contains('cb') ? e.checked : e.value;
set(e.id, sett, val);
console.log(`${e.id} set to ${val}`);
}
try {
localStorage.setItem('wledUiCfg', JSON.stringify(sett));
gId('lssuc').style.display = "inline";
} catch (e) {
gId('lssuc').style.display = "none";
gId('lserr').style.display = "inline";
gId('lserr').innerHTML = "&#9888; Settings JSON saving failed. (" + e + ")";
}
}
function Save() {
SetLS();
if (d.Sf.DS.value != initial_ds || d.Sf.ST.checked != initial_st) d.Sf.submit();
}
function S()
{
GetV();
initial_ds = d.Sf.DS.value;
initial_st = d.Sf.ST.checked;
GetLS();
}
function H()
{
window.open("https://github.com/Aircoookie/WLED/wiki/Settings#user-interface-settings");
}
function B()
{
window.open("/settings","_self");
}
function UI()
{
gId('idonthateyou').style.display = (gId('dm').checked) ? 'inline':'none';
var f = gId('theme_base');
if (f) f.value = (gId('dm').checked) ? 'light':'dark';
}
function GetV() {var d=document;
%CSS%%SCSS%</head><body onload="S()">
<form id="form_s" name="Sf" method="post"><div
style="position:sticky;top:0;background-color:#222"><div class="helpB"><button
@ -370,16 +370,16 @@ On/Off button enabled: <input type="checkbox" name="BT"><br>Infrared remote:
9-key red</option></select><br><a
href="https://github.com/Aircoookie/WLED/wiki/Infrared-Control" target="_blank">
IR info</a><h3>WLED Broadcast</h3>UDP Port: <input name="UP" type="number"
min="1" max="65535" class="d5" required><br>Receive <input type="checkbox"
name="RB">Brightness, <input type="checkbox" name="RC">Color, and <input
type="checkbox" name="RX">Effects<br>Send notifications on direct change: <input
type="checkbox" name="SD"><br>Send notifications on button press: <input
type="checkbox" name="SB"><br>Send Alexa notifications: <input type="checkbox"
name="SA"><br>Send Philips Hue change notifications: <input type="checkbox"
name="SH"><br>Send Macro notifications: <input type="checkbox" name="SM"><br>
Send notifications twice: <input type="checkbox" name="S2"><h3>UDP Api</h3>
Enable UDP Api: <input type="checkbox" name="UAE"><br>Port: <input name="UAP"
type="number" min="1" max="65535" class="d5"><br><i>
min="1" max="65535" class="d5" required><br>2nd Port: <input name="U2"
type="number" min="1" max="65535" class="d5" required><br>Receive <input
type="checkbox" name="RB">Brightness, <input type="checkbox" name="RC">
Color, and <input type="checkbox" name="RX">Effects<br>
Send notifications on direct change: <input type="checkbox" name="SD"><br>
Send notifications on button press: <input type="checkbox" name="SB"><br>
Send Alexa notifications: <input type="checkbox" name="SA"><br>
Send Philips Hue change notifications: <input type="checkbox" name="SH"><br>
Send Macro notifications: <input type="checkbox" name="SM"><br>
Send notifications twice: <input type="checkbox" name="S2"><br><i>
Reboot required to apply changes.</i><h3>Realtime</h3>Receive UDP realtime:
<input type="checkbox" name="RD"><br><br><i>Network DMX input</i><br>Type:
<select name="DI" onchange="SP(),adj()"><option value="5568">E1.31 (sACN)
@ -453,7 +453,9 @@ value="5">US-CST/CDT</option><option value="6">US-MST/MDT</option><option
value="7">US-AZ</option><option value="8">US-PST/PDT</option><option value="9">
CST(AWST)</option><option value="10">JST(KST)</option><option value="11">
AEST/AEDT</option><option value="12">NZST/NZDT</option><option value="13">
North Korea</option></select><br>UTC offset: <input name="UO" type="number"
North Korea</option><option value="14">IST (India)</option><option value="15">
CA-Saskatchewan</option><option value="16">ACST</option><option value="17">
ACST/ACDT</option></select><br>UTC offset: <input name="UO" type="number"
min="-65500" max="65500" required> seconds (max. 18 hours)<br>
Current local time is <span class="times">unknown</span>.<h3>Clock</h3>
Clock Overlay: <select name="OL" onchange="Cs()"><option value="0" id="cn"

View File

@ -44,7 +44,14 @@ void deserializeSegment(JsonObject elem, byte it)
int rgbw[] = {0,0,0,0};
byte cp = copyArray(colX, rgbw);
if (cp == 1 && rgbw[0] == 0) seg.colors[i] = 0;
if (cp == 1) {
if (rgbw[0] == 0) seg.colors[i] = 0;
else {
byte ctrgb[] = {0,0,0,0};
colorKtoRGB(rgbw[0], ctrgb);
for (uint8_t c = 0; c < 3; c++) rgbw[c] = ctrgb[c];
}
}
if (id == strip.getMainSegmentId() && i < 2) //temporary, to make transition work on main segment
{
if (i == 0) {col[0] = rgbw[0]; col[1] = rgbw[1]; col[2] = rgbw[2]; col[3] = rgbw[3];}
@ -57,56 +64,16 @@ void deserializeSegment(JsonObject elem, byte it)
}
// lx parser
#ifdef WLED_ENABLE_LOXONE
int lx = elem[F("lx")] | -1;
if (lx > 0) {
DEBUG_PRINT(F("LX: Lox primary = "));
DEBUG_PRINTLN(lx);
int rgbw[] = {0,0,0,0};
if (parseLx(lx, rgbw)) {
if (bri == 0) {
DEBUG_PRINTLN(F("LX: turn on"));
toggleOnOff();
}
bri = 255;
nightlightActive = false; //always disable nightlight when toggling
if (id == strip.getMainSegmentId()) {
DEBUG_PRINTLN(F("LX: main segment"));
col[0] = rgbw[0];
col[1] = rgbw[1];
col[2] = rgbw[2];
col[3] = rgbw[3];
} else {
DEBUG_PRINT(F("LX: segment "));
DEBUG_PRINTLN(id);
seg.colors[0] = ((rgbw[3] << 24) | ((rgbw[0]&0xFF) << 16) | ((rgbw[1]&0xFF) << 8) | ((rgbw[2]&0xFF)));
}
}
parseLxJson(lx, id, false);
}
int ly = elem[F("ly")] | -1;
if (ly > 0) {
DEBUG_PRINT(F("LY: Lox secondary = "));
Serial.println(ly);
int rgbw[] = {0,0,0,0};
if (parseLx(ly, rgbw)) {
if (bri == 0) {
DEBUG_PRINTLN(F("LY: turn on"));
toggleOnOff();
}
bri = 255;
nightlightActive = false; //always disable nightlight when toggling
if (id == strip.getMainSegmentId()) {
DEBUG_PRINTLN(F("LY: main segment"));
colSec[0] = rgbw[0];
colSec[1] = rgbw[1];
colSec[2] = rgbw[2];
colSec[3] = rgbw[3];
} else {
DEBUG_PRINT(F("LY: segment "));
DEBUG_PRINTLN(id);
seg.colors[1] = ((rgbw[3] << 24) | ((rgbw[0]&0xFF) << 16) | ((rgbw[1]&0xFF) << 8) | ((rgbw[2]&0xFF)));
}
}
parseLxJson(ly, id, true);
}
#endif
//if (pal != seg.palette && pal < strip.getPaletteCount()) strip.setPalette(pal);
seg.setOption(SEG_OPTION_SELECTED, elem[F("sel")] | seg.getOption(SEG_OPTION_SELECTED));
@ -507,7 +474,7 @@ void serializeInfo(JsonObject root)
root[F("brand")] = "WLED";
root[F("product")] = F("FOSS");
root[F("mac")] = escapedMac;
root["mac"] = escapedMac;
}
void serveJson(AsyncWebServerRequest* request)

View File

@ -1,11 +1,16 @@
#include "wled.h"
bool parseLx(int lxValue, int rgbw[4])
/*
* Parser for Loxone formats
*/
bool parseLx(int lxValue, byte rgbw[4])
{
#ifdef WLED_ENABLE_LOXONE
DEBUG_PRINT(F("LX: Lox = "));
DEBUG_PRINTLN(lxValue);
bool ok = false;
float lxRed = 0;
float lxGreen = 0;
float lxBlue = 0;
float lxRed = 0, lxGreen = 0, lxBlue = 0;
if (lxValue < 200000000) {
// Loxone RGB
@ -21,58 +26,52 @@ bool parseLx(int lxValue, int rgbw[4])
float temp = 0;
tmpBri *= 2.55;
if (tmpBri < 0) {
tmpBri = 0;
} else if (tmpBri > 255) {
tmpBri = 255;
}
if (ct < 2700) {
ct = 2700;
} else if (ct > 6500) {
ct = 6500;
}
constrain(tmpBri, 0, 255);
colorKtoRGB(ct, rgbw);
lxRed = rgbw[0]; lxGreen = rgbw[1]; lxBlue = rgbw[2];
temp = ct / 100;
if (temp <= 66) {
lxRed = 255;
lxGreen = round(99.4708025861 * log(temp) - 161.1195681661);
if (temp <= 19) {
lxBlue = 0;
} else {
lxBlue = round(138.5177312231 * log((temp - 10)) - 305.0447927307);
}
} else {
lxRed = round(329.698727446 * pow((temp - 60), -0.1332047592));
lxGreen = round(288.1221695283 * pow((temp - 60), -0.0755148492));
lxBlue = 255;
}
lxRed *= (tmpBri/255);
lxGreen *= (tmpBri/255);
lxBlue *= (tmpBri/255);
}
if (ok) {
if (lxRed > 255) {
lxRed = 255;
} else if (lxRed < 0) {
lxRed = 0;
}
if (lxGreen > 255) {
lxGreen = 255;
} else if (lxGreen < 0) {
lxGreen = 0;
}
if (lxBlue > 255) {
lxBlue = 255;
} else if (lxBlue < 0) {
lxBlue = 0;
}
rgbw[0] = (uint8_t)lxRed;
rgbw[1] = (uint8_t)lxGreen;
rgbw[2] = (uint8_t)lxBlue;
rgbw[0] = (uint8_t) constrain(lxRed, 0, 255);
rgbw[1] = (uint8_t) constrain(lxGreen, 0, 255);
rgbw[2] = (uint8_t) constrain(lxBlue, 0, 255);
rgbw[3] = 0;
return true;
}
#endif
return false;
}
void parseLxJson(int lxValue, byte segId, bool secondary)
{
if (secondary) {
DEBUG_PRINT(F("LY: Lox secondary = "));
} else {
DEBUG_PRINT(F("LX: Lox primary = "));
}
DEBUG_PRINTLN(lxValue);
byte rgbw[] = {0,0,0,0};
if (parseLx(lxValue, rgbw)) {
if (bri == 0) {
DEBUG_PRINTLN(F("LX: turn on"));
toggleOnOff();
}
bri = 255;
nightlightActive = false; //always disable nightlight when toggling
if (segId == strip.getMainSegmentId()) {
DEBUG_PRINTLN(F("LX: main segment"));
if (secondary) for (byte i = 0; i < 4; i++) colSec[i] = rgbw[i];
else for (byte i = 0; i < 4; i++) col[i] = rgbw[i];
} else {
DEBUG_PRINT(F("LX: segment "));
DEBUG_PRINTLN(segId);
strip.getSegment(segId).colors[secondary] = ((rgbw[3] << 24) | ((rgbw[0]&0xFF) << 16) | ((rgbw[1]&0xFF) << 8) | ((rgbw[2]&0xFF)));
}
}
}

View File

@ -129,6 +129,8 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
irEnabled = request->arg(F("IR")).toInt();
int t = request->arg(F("UP")).toInt();
if (t > 0) udpPort = t;
t = request->arg(F("U2")).toInt();
if (t > 0) udpPort2 = t;
receiveNotificationBrightness = request->hasArg(F("RB"));
receiveNotificationColor = request->hasArg(F("RC"));
receiveNotificationEffects = request->hasArg(F("RX"));
@ -197,11 +199,6 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
hueStoreAllowed = true;
reconnectHue();
#endif
// UDP Api
udpApiEnabled = request->hasArg("UAE");
t = request->arg("UAP").toInt();
if (t > 0) udpApiPort = t;
}
//TIME
@ -514,35 +511,27 @@ bool handleSet(AsyncWebServerRequest *request, const String& req)
updateVal(&req, "B2=", &colSec[2]);
updateVal(&req, "W2=", &colSec[3]);
#ifdef WLED_ENABLE_LOXONE
//lox parser
int rgbw[4] = {0,0,0,0};
pos = req.indexOf(F("LX=")); // Lox primary color
if (pos > 0) {
int lxValue = getNumVal(&req, pos);
if (parseLx(lxValue, rgbw)) {
col[0] = rgbw[0];
col[1] = rgbw[1];
col[2] = rgbw[2];
if (parseLx(lxValue, col)) {
bri = 255;
nightlightActive = false; //always disable nightlight when toggling
DEBUG_PRINT(F("LX: Lox primary = "));
DEBUG_PRINTLN(lxValue);
}
}
pos = req.indexOf(F("LY")); // Lox secondary color
pos = req.indexOf(F("LY=")); // Lox secondary color
if (pos > 0) {
int lxValue = getNumVal(&req, pos);
if(parseLx(lxValue, rgbw)) {
colSec[0] = rgbw[0];
colSec[1] = rgbw[1];
colSec[2] = rgbw[2];
if(parseLx(lxValue, colSec)) {
bri = 255;
nightlightActive = false; //always disable nightlight when toggling
DEBUG_PRINT(F("LY: Lox secondary = "));
DEBUG_PRINTLN(lxValue);
}
}
#endif
//set hue
pos = req.indexOf(F("HU="));
if (pos > 0) {
@ -555,6 +544,12 @@ bool handleSet(AsyncWebServerRequest *request, const String& req)
colorHStoRGB(temphue,tempsat,(req.indexOf(F("H2"))>0)? colSec:col);
}
//set white spectrum (kelvin)
pos = req.indexOf(F("&K="));
if (pos > 0) {
colorKtoRGB(getNumVal(&req, pos),(req.indexOf(F("K2"))>0)? colSec:col);
}
//set color from HEX or 32bit DEC
pos = req.indexOf(F("CL="));
if (pos > 0) {

View File

@ -124,7 +124,12 @@ void handleNotifications()
//receive UDP notifications
if (!udpConnected || !(receiveNotifications || receiveDirect)) return;
bool isSupp = false;
uint16_t packetSize = notifierUdp.parsePacket();
if (!packetSize && udp2Connected) {
packetSize = notifier2Udp.parsePacket();
isSupp = true;
}
//hyperion / raw RGB
if (!packetSize && udpRgbConnected) {
@ -150,28 +155,13 @@ void handleNotifications()
}
}
// udp api
if (udpApiEnabled && !packetSize && udpApiConnected) {
packetSize = apiUdp.parsePacket();
if (packetSize) {
if (!receiveDirect) return;
if (packetSize > UDP_IN_MAXSIZE || packetSize < 3) return;
uint8_t lbuf[packetSize];
apiUdp.read(lbuf, packetSize);
lbuf[packetSize] = '\0';
String apireq = "win&";
apireq += (char*)lbuf;
handleSet(nullptr, apireq);
return;
}
}
//notifier and UDP realtime
if (!packetSize || packetSize > UDP_IN_MAXSIZE) return;
if (notifierUdp.remoteIP() == WiFi.localIP()) return; //don't process broadcasts we send ourselves
if (!isSupp && notifierUdp.remoteIP() == WiFi.localIP()) return; //don't process broadcasts we send ourselves
uint8_t udpIn[packetSize];
notifierUdp.read(udpIn, packetSize);
uint8_t udpIn[packetSize +1];
if (isSupp) notifier2Udp.read(udpIn, packetSize);
else notifierUdp.read(udpIn, packetSize);
//wled notifier, block if realtime packets active
if (udpIn[0] == 0 && !realtimeMode && receiveNotifications)
@ -230,7 +220,7 @@ void handleNotifications()
if (receiveNotificationBrightness || !someSel) bri = udpIn[2];
colorUpdated(NOTIFIER_CALL_MODE_NOTIFICATION);
return;
}
if (!receiveDirect) return;
@ -245,7 +235,7 @@ void handleNotifications()
}
if (tpmType != 0xda) return; //return if notTPM2.NET data
realtimeIP = notifierUdp.remoteIP();
realtimeIP = (isSupp) ? notifier2Udp.remoteIP() : notifierUdp.remoteIP();
realtimeLock(realtimeTimeoutMs, REALTIME_MODE_TPM2NET);
if (realtimeOverride) return;
@ -269,13 +259,14 @@ void handleNotifications()
tpmPacketCount = 0;
strip.show();
}
return;
}
//UDP realtime: 1 warls 2 drgb 3 drgbw
if (udpIn[0] > 0 && udpIn[0] < 5)
{
realtimeIP = notifierUdp.remoteIP();
DEBUG_PRINTLN(notifierUdp.remoteIP());
realtimeIP = (isSupp) ? notifier2Udp.remoteIP() : notifierUdp.remoteIP();
DEBUG_PRINTLN(realtimeIP);
if (packetSize < 2) return;
if (udpIn[1] == 0)
@ -322,6 +313,21 @@ void handleNotifications()
}
}
strip.show();
return;
}
// API over UDP
udpIn[packetSize] = '\0';
if (udpIn[0] >= 'A' && udpIn[0] <= 'Z') { //HTTP API
String apireq = "win&";
apireq += (char*)udpIn;
handleSet(nullptr, apireq);
} else if (udpIn[0] == '{') { //JSON API
DynamicJsonDocument jsonBuffer(2048);
DeserializationError error = deserializeJson(jsonBuffer, udpIn);
JsonObject root = jsonBuffer.as<JsonObject>();
if (!error && !root.isNull()) deserializeState(root);
}
}

View File

@ -264,15 +264,15 @@ void WLED::initAP(bool resetAP)
return;
if (!apSSID[0] || resetAP)
strcpy(apSSID, (const char*)F("WLED-AP"));
strcpy_P(apSSID, PSTR("WLED-AP"));
if (resetAP)
strcpy(apPass, DEFAULT_AP_PASS);
strcpy_P(apPass, PSTR(DEFAULT_AP_PASS));
DEBUG_PRINT(F("Opening access point "));
DEBUG_PRINTLN(apSSID);
WiFi.softAPConfig(IPAddress(4, 3, 2, 1), IPAddress(4, 3, 2, 1), IPAddress(255, 255, 255, 0));
WiFi.softAP(apSSID, apPass, apChannel, apHide);
if (!apActive) // start captive portal if AP active
if (!apActive) // start captive portal if AP active
{
DEBUG_PRINTLN(F("Init AP interfaces"));
server.begin();
@ -282,8 +282,8 @@ void WLED::initAP(bool resetAP)
if (udpRgbPort > 0 && udpRgbPort != ntpLocalPort && udpRgbPort != udpPort) {
udpRgbConnected = rgbUdp.begin(udpRgbPort);
}
if (udpApiEnabled && udpApiPort > 0 && udpApiPort != ntpLocalPort && udpApiPort != udpPort && udpApiPort != udpRgbPort) {
udpApiConnected = apiUdp.begin(udpApiPort);
if (udpPort2 > 0 && udpPort2 != ntpLocalPort && udpPort2 != udpPort && udpPort2 != udpRgbPort) {
udp2Connected = notifier2Udp.begin(udpPort2);
}
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
@ -411,8 +411,8 @@ void WLED::initInterfaces()
udpConnected = notifierUdp.begin(udpPort);
if (udpConnected && udpRgbPort != udpPort)
udpRgbConnected = rgbUdp.begin(udpRgbPort);
if (udpApiEnabled && udpConnected && udpApiPort != udpPort && udpApiPort != udpRgbPort)
udpApiConnected = apiUdp.begin(udpApiPort);
if (udpConnected && udpPort2 != udpPort && udpPort2 != udpRgbPort)
udp2Connected = notifier2Udp.begin(udpPort2);
}
if (ntpEnabled)
ntpConnected = ntpUdp.begin(ntpLocalPort);

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2009202
#define VERSION 2009260
// ESP8266-01 (blue) got too little storage space to work with all features of WLED. To use it, you must use ESP8266 Arduino Core v2.4.2 and the setting 512K(No SPIFFS).
@ -30,11 +30,12 @@
#endif
#define WLED_ENABLE_ADALIGHT // saves 500b only
//#define WLED_ENABLE_DMX // uses 3.5kb (use LEDPIN other than 2)
#define WLED_ENABLE_LOXONE // uses 1.2kb
#ifndef WLED_DISABLE_WEBSOCKETS
#define WLED_ENABLE_WEBSOCKETS
#endif
#define WLED_DISABLE_FILESYSTEM // SPIFFS is not used by any WLED feature yet
#define WLED_DISABLE_FILESYSTEM // SPIFFS is not used by any WLED feature yet
//#define WLED_ENABLE_FS_SERVING // Enable sending html file from SPIFFS before serving progmem version
//#define WLED_ENABLE_FS_EDITOR // enable /edit page for editing SPIFFS content. Will also be disabled with OTA lock
@ -214,8 +215,8 @@ WLED_GLOBAL bool buttonEnabled _INIT(true);
WLED_GLOBAL byte irEnabled _INIT(0); // Infrared receiver
WLED_GLOBAL uint16_t udpPort _INIT(21324); // WLED notifier default port
WLED_GLOBAL uint16_t udpPort2 _INIT(65506); // WLED notifier supplemental port
WLED_GLOBAL uint16_t udpRgbPort _INIT(19446); // Hyperion port
WLED_GLOBAL uint16_t udpApiPort _INIT(7000); // Udp api port
WLED_GLOBAL bool receiveNotificationBrightness _INIT(true); // apply brightness from incoming notifications
WLED_GLOBAL bool receiveNotificationColor _INIT(true); // apply color
@ -260,8 +261,6 @@ WLED_GLOBAL char mqttPass[41] _INIT(""); // optional: password
WLED_GLOBAL char mqttClientID[41] _INIT(""); // override the client ID
WLED_GLOBAL uint16_t mqttPort _INIT(1883);
WLED_GLOBAL bool udpApiEnabled _INIT(true);
WLED_GLOBAL bool huePollingEnabled _INIT(false); // poll hue bridge for light state
WLED_GLOBAL uint16_t huePollIntervalMs _INIT(2500); // low values (< 1sec) may cause lag but offer quicker response
WLED_GLOBAL char hueApiKey[47] _INIT("api"); // key token will be obtained from bridge
@ -380,7 +379,7 @@ WLED_GLOBAL byte effectIntensity _INIT(128);
WLED_GLOBAL byte effectPalette _INIT(0);
// network
WLED_GLOBAL bool udpConnected _INIT(false), udpRgbConnected _INIT(false), udpApiConnected _INIT(false);;
WLED_GLOBAL bool udpConnected _INIT(false), udp2Connected _INIT(false), udpRgbConnected _INIT(false);
// ui style
WLED_GLOBAL bool showWelcomePage _INIT(false);
@ -496,7 +495,7 @@ WLED_GLOBAL AsyncClient* hueClient _INIT(NULL);
WLED_GLOBAL AsyncMqttClient* mqtt _INIT(NULL);
// udp interface objects
WLED_GLOBAL WiFiUDP notifierUdp, rgbUdp, apiUdp;
WLED_GLOBAL WiFiUDP notifierUdp, rgbUdp, notifier2Udp;
WLED_GLOBAL WiFiUDP ntpUdp;
WLED_GLOBAL ESPAsyncE131 e131 _INIT_N(((handleE131Packet)));
WLED_GLOBAL bool e131NewData _INIT(false);

View File

@ -7,7 +7,7 @@
*/
//eeprom Version code, enables default settings instead of 0 init on update
#define EEPVER 21
#define EEPVER 22
//0 -> old version, default
//1 -> 0.4p 1711272 and up
//2 -> 0.4p 1711302 and up
@ -30,6 +30,7 @@
//19-> 0.9.1n
//20-> 0.9.1p
//21-> 0.10.1p
//22-> 2009260
void commit()
{
@ -146,6 +147,9 @@ void saveSettingsToEEPROM()
EEPROM.write(377, EEPVER); //eeprom was updated to latest
EEPROM.write(378, udpPort2 & 0xFF);
EEPROM.write(379, (udpPort2 >> 8) & 0xFF);
EEPROM.write(382, strip.paletteBlend);
EEPROM.write(383, strip.colorOrder);
@ -284,10 +288,6 @@ void saveSettingsToEEPROM()
} // last used: 2549. maybe leave a few bytes for future expansion and go on with 2600 kthxbye.
#endif
EEPROM.write(2550, udpApiEnabled);
EEPROM.write(2551, udpApiPort & 0xFF);
EEPROM.write(2552, (udpApiPort >> 8) & 0xFF);
commit();
}
@ -542,9 +542,8 @@ void loadSettingsFromEEPROM(bool first)
}
#endif
if (lastEEPROMversion > 19) {
udpApiEnabled = EEPROM.read(2550);
udpApiPort = EEPROM.read(2551) + ((EEPROM.read(2552) << 8) & 0xFF00);
if (lastEEPROMversion > 21) {
udpPort2 = EEPROM.read(378) + ((EEPROM.read(379) << 8) & 0xFF00);
}
receiveDirect = !EEPROM.read(2200);

View File

@ -292,6 +292,7 @@ void getSettingsJS(byte subPage, char* dest)
sappend('c',SET_F("BT"),buttonEnabled);
sappend('v',SET_F("IR"),irEnabled);
sappend('v',SET_F("UP"),udpPort);
sappend('v',SET_F("U2"),udpPort2);
sappend('c',SET_F("RB"),receiveNotificationBrightness);
sappend('c',SET_F("RC"),receiveNotificationColor);
sappend('c',SET_F("RX"),receiveNotificationEffects);
@ -316,10 +317,6 @@ void getSettingsJS(byte subPage, char* dest)
sappend('c',SET_F("SA"),notifyAlexa);
sappends('s',SET_F("BK"),(char*)((blynkEnabled)?SET_F("Hidden"):""));
// UDP Api
sappend('c',"UAE",udpApiEnabled);
sappend('v',"UAP",udpApiPort);
#ifdef WLED_ENABLE_MQTT
sappend('c',SET_F("MQ"),mqttEnabled);
sappends('s',SET_F("MS"),mqttServer);