mirror of
https://github.com/wled/WLED.git
synced 2025-08-29 12:39:24 +00:00
Compare commits
4 Commits
nightly
...
http-api-r
Author | SHA1 | Date | |
---|---|---|---|
![]() |
cab2f91bc6 | ||
![]() |
e65f6c7bc7 | ||
![]() |
4d0b79f300 | ||
![]() |
e570460cd9 |
@@ -235,7 +235,7 @@ void handleRemote(uint8_t *data, size_t len);
|
|||||||
//set.cpp
|
//set.cpp
|
||||||
bool isAsterisksOnly(const char* str, byte maxLen);
|
bool isAsterisksOnly(const char* str, byte maxLen);
|
||||||
void handleSettingsSet(AsyncWebServerRequest *request, byte subPage);
|
void handleSettingsSet(AsyncWebServerRequest *request, byte subPage);
|
||||||
bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply=true);
|
bool handleHttpApi(const String& req, bool apply=true);
|
||||||
|
|
||||||
//udp.cpp
|
//udp.cpp
|
||||||
void notify(byte callMode, bool followUp=false);
|
void notify(byte callMode, bool followUp=false);
|
||||||
|
@@ -599,16 +599,14 @@ static void decodeIRJson(uint32_t code)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// HTTP API command
|
// HTTP API command
|
||||||
String apireq = "win"; apireq += '&'; // reduce flash string usage
|
|
||||||
if (cmdStr.indexOf("~") > 0 || fdo["rpt"]) lastValidCode = code; // repeatable action
|
if (cmdStr.indexOf("~") > 0 || fdo["rpt"]) lastValidCode = code; // repeatable action
|
||||||
if (!cmdStr.startsWith(apireq)) cmdStr = apireq + cmdStr; // if no "win&" prefix
|
|
||||||
if (!irApplyToAllSelected && cmdStr.indexOf(F("SS="))<0) {
|
if (!irApplyToAllSelected && cmdStr.indexOf(F("SS="))<0) {
|
||||||
char tmp[10];
|
char tmp[10];
|
||||||
sprintf_P(tmp, PSTR("&SS=%d"), strip.getMainSegmentId());
|
sprintf_P(tmp, PSTR("&SS=%d"), strip.getMainSegmentId());
|
||||||
cmdStr += tmp;
|
cmdStr += tmp;
|
||||||
}
|
}
|
||||||
fdo.clear(); // clear JSON buffer (it is no longer needed)
|
fdo.clear(); // clear JSON buffer (it is no longer needed)
|
||||||
handleSet(nullptr, cmdStr, false); // no stateUpdated() call here
|
handleHttpApi(cmdStr, false); // no stateUpdated() call here
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// command is JSON object (TODO: currently will not handle irApplyToAllSelected correctly)
|
// command is JSON object (TODO: currently will not handle irApplyToAllSelected correctly)
|
||||||
|
@@ -449,9 +449,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
|
|||||||
// HTTP API commands (must be handled before "ps")
|
// HTTP API commands (must be handled before "ps")
|
||||||
const char* httpwin = root["win"];
|
const char* httpwin = root["win"];
|
||||||
if (httpwin) {
|
if (httpwin) {
|
||||||
String apireq = "win"; apireq += '&'; // reduce flash string usage
|
handleHttpApi(httpwin, false); // may set stateChanged
|
||||||
apireq += httpwin;
|
|
||||||
handleSet(nullptr, apireq, false); // may set stateChanged
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Applying preset from JSON API has 2 cases: a) "pd" AKA "preset direct" and b) "ps" AKA "preset select"
|
// Applying preset from JSON API has 2 cases: a) "pd" AKA "preset direct" and b) "ps" AKA "preset select"
|
||||||
@@ -462,7 +460,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
|
|||||||
if (!root[F("pd")].isNull() && stateChanged) {
|
if (!root[F("pd")].isNull() && stateChanged) {
|
||||||
// a) already applied preset content (requires "seg" or "win" but will ignore the rest)
|
// a) already applied preset content (requires "seg" or "win" but will ignore the rest)
|
||||||
currentPreset = root[F("pd")] | currentPreset;
|
currentPreset = root[F("pd")] | currentPreset;
|
||||||
if (root["win"].isNull()) presetCycCurr = currentPreset; // otherwise presetCycCurr was set in handleSet() [set.cpp]
|
if (root["win"].isNull()) presetCycCurr = currentPreset; // otherwise presetCycCurr was set in handleHttpApi() [set.cpp]
|
||||||
presetToRestore = currentPreset; // stateUpdated() will clear the preset, so we need to restore it after
|
presetToRestore = currentPreset; // stateUpdated() will clear the preset, so we need to restore it after
|
||||||
DEBUG_PRINTF_P(PSTR("Preset direct: %d\n"), currentPreset);
|
DEBUG_PRINTF_P(PSTR("Preset direct: %d\n"), currentPreset);
|
||||||
} else if (!root["ps"].isNull()) {
|
} else if (!root["ps"].isNull()) {
|
||||||
|
@@ -107,9 +107,7 @@ static void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProp
|
|||||||
deserializeJson(*pDoc, payloadStr);
|
deserializeJson(*pDoc, payloadStr);
|
||||||
deserializeState(pDoc->as<JsonObject>());
|
deserializeState(pDoc->as<JsonObject>());
|
||||||
} else { //HTTP API
|
} else { //HTTP API
|
||||||
String apireq = "win"; apireq += '&'; // reduce flash string usage
|
handleHttpApi(payloadStr);
|
||||||
apireq += payloadStr;
|
|
||||||
handleSet(nullptr, apireq);
|
|
||||||
}
|
}
|
||||||
releaseJSONBufferLock();
|
releaseJSONBufferLock();
|
||||||
}
|
}
|
||||||
|
@@ -180,10 +180,7 @@ void handlePresets()
|
|||||||
//HTTP API commands
|
//HTTP API commands
|
||||||
const char* httpwin = fdo["win"];
|
const char* httpwin = fdo["win"];
|
||||||
if (httpwin) {
|
if (httpwin) {
|
||||||
String apireq = "win"; // reduce flash string usage
|
handleHttpApi(httpwin, false); // may call applyPreset() via PL=
|
||||||
apireq += F("&IN&"); // internal call
|
|
||||||
apireq += httpwin;
|
|
||||||
handleSet(nullptr, apireq, false); // may call applyPreset() via PL=
|
|
||||||
setValuesFromFirstSelectedSeg(); // fills legacy values
|
setValuesFromFirstSelectedSeg(); // fills legacy values
|
||||||
changePreset = true;
|
changePreset = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -208,7 +205,7 @@ void handlePresets()
|
|||||||
updateInterfaces(tmpMode);
|
updateInterfaces(tmpMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
//called from handleSet(PS=) [network callback (sObj is empty), IR (irrational), deserializeState, UDP] and deserializeState() [network callback (filedoc!=nullptr)]
|
//called from handleHttpApi(PS=) [network callback (sObj is empty), IR (irrational), deserializeState, UDP] and deserializeState() [network callback (filedoc!=nullptr)]
|
||||||
void savePreset(byte index, const char* pname, JsonObject sObj)
|
void savePreset(byte index, const char* pname, JsonObject sObj)
|
||||||
{
|
{
|
||||||
if (!saveName) saveName = new char[33];
|
if (!saveName) saveName = new char[33];
|
||||||
|
@@ -153,16 +153,14 @@ static bool remoteJson(int button)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// HTTP API command
|
// HTTP API command
|
||||||
String apireq = "win"; apireq += '&'; // reduce flash string usage
|
|
||||||
//if (cmdStr.indexOf("~") || fdo["rpt"]) lastValidCode = code; // repeatable action
|
//if (cmdStr.indexOf("~") || fdo["rpt"]) lastValidCode = code; // repeatable action
|
||||||
if (!cmdStr.startsWith(apireq)) cmdStr = apireq + cmdStr; // if no "win&" prefix
|
|
||||||
if (!irApplyToAllSelected && cmdStr.indexOf(F("SS="))<0) {
|
if (!irApplyToAllSelected && cmdStr.indexOf(F("SS="))<0) {
|
||||||
char tmp[10];
|
char tmp[10];
|
||||||
sprintf_P(tmp, PSTR("&SS=%d"), strip.getMainSegmentId());
|
sprintf_P(tmp, PSTR("&SS=%d"), strip.getMainSegmentId());
|
||||||
cmdStr += tmp;
|
cmdStr += tmp;
|
||||||
}
|
}
|
||||||
fdo.clear(); // clear JSON buffer (it is no longer needed)
|
fdo.clear(); // clear JSON buffer (it is no longer needed)
|
||||||
handleSet(nullptr, cmdStr, false); // no stateUpdated() call here
|
handleHttpApi(cmdStr, false); // no stateUpdated() call here
|
||||||
stateUpdated(CALL_MODE_BUTTON);
|
stateUpdated(CALL_MODE_BUTTON);
|
||||||
parsed = true;
|
parsed = true;
|
||||||
}
|
}
|
||||||
|
105
wled00/set.cpp
105
wled00/set.cpp
@@ -803,16 +803,14 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
|
|
||||||
|
|
||||||
//HTTP API request parser
|
//HTTP API request parser
|
||||||
bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
bool handleHttpApi(const String& req, bool apply)
|
||||||
{
|
{
|
||||||
if (!(req.indexOf("win") >= 0)) return false;
|
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
DEBUG_PRINTF_P(PSTR("API req: %s\n"), req.c_str());
|
DEBUG_PRINTF_P(PSTR("API req: %s\n"), req.c_str());
|
||||||
|
|
||||||
//segment select (sets main segment)
|
//segment select (sets main segment)
|
||||||
pos = req.indexOf(F("SM="));
|
pos = req.indexOf(F("SM="));
|
||||||
if (pos > 0 && !realtimeMode) {
|
if (pos >= 0 && !realtimeMode) {
|
||||||
strip.setMainSegmentId(getNumVal(&req, pos));
|
strip.setMainSegmentId(getNumVal(&req, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -821,7 +819,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
bool singleSegment = false;
|
bool singleSegment = false;
|
||||||
|
|
||||||
pos = req.indexOf(F("SS="));
|
pos = req.indexOf(F("SS="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
unsigned t = getNumVal(&req, pos);
|
unsigned t = getNumVal(&req, pos);
|
||||||
if (t < strip.getSegmentsNum()) {
|
if (t < strip.getSegmentsNum()) {
|
||||||
selectedSeg = t;
|
selectedSeg = t;
|
||||||
@@ -831,7 +829,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
|
|
||||||
Segment& selseg = strip.getSegment(selectedSeg);
|
Segment& selseg = strip.getSegment(selectedSeg);
|
||||||
pos = req.indexOf(F("SV=")); //segment selected
|
pos = req.indexOf(F("SV=")); //segment selected
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
unsigned t = getNumVal(&req, pos);
|
unsigned t = getNumVal(&req, pos);
|
||||||
if (t == 2) for (unsigned i = 0; i < strip.getSegmentsNum(); i++) strip.getSegment(i).selected = false; // unselect other segments
|
if (t == 2) for (unsigned i = 0; i < strip.getSegmentsNum(); i++) strip.getSegment(i).selected = false; // unselect other segments
|
||||||
selseg.selected = t;
|
selseg.selected = t;
|
||||||
@@ -859,31 +857,31 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
uint8_t grpI = selseg.grouping;
|
uint8_t grpI = selseg.grouping;
|
||||||
uint16_t spcI = selseg.spacing;
|
uint16_t spcI = selseg.spacing;
|
||||||
pos = req.indexOf(F("&S=")); //segment start
|
pos = req.indexOf(F("&S=")); //segment start
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
startI = std::abs(getNumVal(&req, pos));
|
startI = std::abs(getNumVal(&req, pos));
|
||||||
}
|
}
|
||||||
pos = req.indexOf(F("S2=")); //segment stop
|
pos = req.indexOf(F("S2=")); //segment stop
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
stopI = std::abs(getNumVal(&req, pos));
|
stopI = std::abs(getNumVal(&req, pos));
|
||||||
}
|
}
|
||||||
pos = req.indexOf(F("GP=")); //segment grouping
|
pos = req.indexOf(F("GP=")); //segment grouping
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
grpI = std::max(1,getNumVal(&req, pos));
|
grpI = std::max(1,getNumVal(&req, pos));
|
||||||
}
|
}
|
||||||
pos = req.indexOf(F("SP=")); //segment spacing
|
pos = req.indexOf(F("SP=")); //segment spacing
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
spcI = std::max(0,getNumVal(&req, pos));
|
spcI = std::max(0,getNumVal(&req, pos));
|
||||||
}
|
}
|
||||||
strip.setSegment(selectedSeg, startI, stopI, grpI, spcI, UINT16_MAX, startY, stopY);
|
strip.setSegment(selectedSeg, startI, stopI, grpI, spcI, UINT16_MAX, startY, stopY);
|
||||||
|
|
||||||
pos = req.indexOf(F("RV=")); //Segment reverse
|
pos = req.indexOf(F("RV=")); //Segment reverse
|
||||||
if (pos > 0) selseg.reverse = req.charAt(pos+3) != '0';
|
if (pos >= 0) selseg.reverse = req.charAt(pos+3) != '0';
|
||||||
|
|
||||||
pos = req.indexOf(F("MI=")); //Segment mirror
|
pos = req.indexOf(F("MI=")); //Segment mirror
|
||||||
if (pos > 0) selseg.mirror = req.charAt(pos+3) != '0';
|
if (pos >= 0) selseg.mirror = req.charAt(pos+3) != '0';
|
||||||
|
|
||||||
pos = req.indexOf(F("SB=")); //Segment brightness/opacity
|
pos = req.indexOf(F("SB=")); //Segment brightness/opacity
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
byte segbri = getNumVal(&req, pos);
|
byte segbri = getNumVal(&req, pos);
|
||||||
selseg.setOption(SEG_OPTION_ON, segbri); // use transition
|
selseg.setOption(SEG_OPTION_ON, segbri); // use transition
|
||||||
if (segbri) {
|
if (segbri) {
|
||||||
@@ -892,7 +890,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pos = req.indexOf(F("SW=")); //segment power
|
pos = req.indexOf(F("SW=")); //segment power
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
switch (getNumVal(&req, pos)) {
|
switch (getNumVal(&req, pos)) {
|
||||||
case 0: selseg.setOption(SEG_OPTION_ON, false); break; // use transition
|
case 0: selseg.setOption(SEG_OPTION_ON, false); break; // use transition
|
||||||
case 1: selseg.setOption(SEG_OPTION_ON, true); break; // use transition
|
case 1: selseg.setOption(SEG_OPTION_ON, true); break; // use transition
|
||||||
@@ -901,13 +899,13 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pos = req.indexOf(F("PS=")); //saves current in preset
|
pos = req.indexOf(F("PS=")); //saves current in preset
|
||||||
if (pos > 0) savePreset(getNumVal(&req, pos));
|
if (pos >= 0) savePreset(getNumVal(&req, pos));
|
||||||
|
|
||||||
pos = req.indexOf(F("P1=")); //sets first preset for cycle
|
pos = req.indexOf(F("P1=")); //sets first preset for cycle
|
||||||
if (pos > 0) presetCycMin = getNumVal(&req, pos);
|
if (pos >= 0) presetCycMin = getNumVal(&req, pos);
|
||||||
|
|
||||||
pos = req.indexOf(F("P2=")); //sets last preset for cycle
|
pos = req.indexOf(F("P2=")); //sets last preset for cycle
|
||||||
if (pos > 0) presetCycMax = getNumVal(&req, pos);
|
if (pos >= 0) presetCycMax = getNumVal(&req, pos);
|
||||||
|
|
||||||
//apply preset
|
//apply preset
|
||||||
if (updateVal(req.c_str(), "PL=", &presetCycCurr, presetCycMin, presetCycMax)) {
|
if (updateVal(req.c_str(), "PL=", &presetCycCurr, presetCycMin, presetCycMax)) {
|
||||||
@@ -915,7 +913,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pos = req.indexOf(F("NP")); //advances to next preset in a playlist
|
pos = req.indexOf(F("NP")); //advances to next preset in a playlist
|
||||||
if (pos > 0) doAdvancePlaylist = true;
|
if (pos >= 0) doAdvancePlaylist = true;
|
||||||
|
|
||||||
//set brightness
|
//set brightness
|
||||||
updateVal(req.c_str(), "&A=", &bri);
|
updateVal(req.c_str(), "&A=", &bri);
|
||||||
@@ -935,7 +933,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
#ifdef WLED_ENABLE_LOXONE
|
#ifdef WLED_ENABLE_LOXONE
|
||||||
//lox parser
|
//lox parser
|
||||||
pos = req.indexOf(F("LX=")); // Lox primary color
|
pos = req.indexOf(F("LX=")); // Lox primary color
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
int lxValue = getNumVal(&req, pos);
|
int lxValue = getNumVal(&req, pos);
|
||||||
if (parseLx(lxValue, colIn)) {
|
if (parseLx(lxValue, colIn)) {
|
||||||
bri = 255;
|
bri = 255;
|
||||||
@@ -944,7 +942,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pos = req.indexOf(F("LY=")); // Lox secondary color
|
pos = req.indexOf(F("LY=")); // Lox secondary color
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
int lxValue = getNumVal(&req, pos);
|
int lxValue = getNumVal(&req, pos);
|
||||||
if(parseLx(lxValue, colInSec)) {
|
if(parseLx(lxValue, colInSec)) {
|
||||||
bri = 255;
|
bri = 255;
|
||||||
@@ -956,11 +954,11 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
|
|
||||||
//set hue
|
//set hue
|
||||||
pos = req.indexOf(F("HU="));
|
pos = req.indexOf(F("HU="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
uint16_t temphue = getNumVal(&req, pos);
|
uint16_t temphue = getNumVal(&req, pos);
|
||||||
byte tempsat = 255;
|
byte tempsat = 255;
|
||||||
pos = req.indexOf(F("SA="));
|
pos = req.indexOf(F("SA="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
tempsat = getNumVal(&req, pos);
|
tempsat = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
byte sec = req.indexOf(F("H2"));
|
byte sec = req.indexOf(F("H2"));
|
||||||
@@ -970,7 +968,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
|
|
||||||
//set white spectrum (kelvin)
|
//set white spectrum (kelvin)
|
||||||
pos = req.indexOf(F("&K="));
|
pos = req.indexOf(F("&K="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
byte sec = req.indexOf(F("K2"));
|
byte sec = req.indexOf(F("K2"));
|
||||||
colorKtoRGB(getNumVal(&req, pos), (sec>0) ? colInSec : colIn);
|
colorKtoRGB(getNumVal(&req, pos), (sec>0) ? colInSec : colIn);
|
||||||
col0Changed |= (!sec); col1Changed |= sec;
|
col0Changed |= (!sec); col1Changed |= sec;
|
||||||
@@ -979,17 +977,17 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
//set color from HEX or 32bit DEC
|
//set color from HEX or 32bit DEC
|
||||||
byte tmpCol[4];
|
byte tmpCol[4];
|
||||||
pos = req.indexOf(F("CL="));
|
pos = req.indexOf(F("CL="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
colorFromDecOrHexString(colIn, (char*)req.substring(pos + 3).c_str());
|
colorFromDecOrHexString(colIn, (char*)req.substring(pos + 3).c_str());
|
||||||
col0Changed = true;
|
col0Changed = true;
|
||||||
}
|
}
|
||||||
pos = req.indexOf(F("C2="));
|
pos = req.indexOf(F("C2="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
colorFromDecOrHexString(colInSec, (char*)req.substring(pos + 3).c_str());
|
colorFromDecOrHexString(colInSec, (char*)req.substring(pos + 3).c_str());
|
||||||
col1Changed = true;
|
col1Changed = true;
|
||||||
}
|
}
|
||||||
pos = req.indexOf(F("C3="));
|
pos = req.indexOf(F("C3="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
colorFromDecOrHexString(tmpCol, (char*)req.substring(pos + 3).c_str());
|
colorFromDecOrHexString(tmpCol, (char*)req.substring(pos + 3).c_str());
|
||||||
uint32_t col2 = RGBW32(tmpCol[0], tmpCol[1], tmpCol[2], tmpCol[3]);
|
uint32_t col2 = RGBW32(tmpCol[0], tmpCol[1], tmpCol[2], tmpCol[3]);
|
||||||
selseg.setColor(2, col2); // defined above (SS= or main)
|
selseg.setColor(2, col2); // defined above (SS= or main)
|
||||||
@@ -998,7 +996,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
|
|
||||||
//set to random hue SR=0->1st SR=1->2nd
|
//set to random hue SR=0->1st SR=1->2nd
|
||||||
pos = req.indexOf(F("SR"));
|
pos = req.indexOf(F("SR"));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
byte sec = getNumVal(&req, pos);
|
byte sec = getNumVal(&req, pos);
|
||||||
setRandomColor(sec? colInSec : colIn);
|
setRandomColor(sec? colInSec : colIn);
|
||||||
col0Changed |= (!sec); col1Changed |= sec;
|
col0Changed |= (!sec); col1Changed |= sec;
|
||||||
@@ -1006,7 +1004,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
|
|
||||||
//swap 2nd & 1st
|
//swap 2nd & 1st
|
||||||
pos = req.indexOf(F("SC"));
|
pos = req.indexOf(F("SC"));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
byte temp;
|
byte temp;
|
||||||
for (unsigned i=0; i<4; i++) {
|
for (unsigned i=0; i<4; i++) {
|
||||||
temp = colIn[i];
|
temp = colIn[i];
|
||||||
@@ -1032,10 +1030,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
bool fxModeChanged = false, speedChanged = false, intensityChanged = false, paletteChanged = false;
|
bool fxModeChanged = false, speedChanged = false, intensityChanged = false, paletteChanged = false;
|
||||||
bool custom1Changed = false, custom2Changed = false, custom3Changed = false, check1Changed = false, check2Changed = false, check3Changed = false;
|
bool custom1Changed = false, custom2Changed = false, custom3Changed = false, check1Changed = false, check2Changed = false, check3Changed = false;
|
||||||
// set effect parameters
|
// set effect parameters
|
||||||
if (updateVal(req.c_str(), "FX=", &effectIn, 0, strip.getModeCount()-1)) {
|
fxModeChanged = updateVal(req.c_str(), "FX=", &effectIn, 0, strip.getModeCount()-1);
|
||||||
if (request != nullptr) unloadPlaylist(); // unload playlist if changing FX using web request
|
|
||||||
fxModeChanged = true;
|
|
||||||
}
|
|
||||||
speedChanged = updateVal(req.c_str(), "SX=", &speedIn);
|
speedChanged = updateVal(req.c_str(), "SX=", &speedIn);
|
||||||
intensityChanged = updateVal(req.c_str(), "IX=", &intensityIn);
|
intensityChanged = updateVal(req.c_str(), "IX=", &intensityIn);
|
||||||
paletteChanged = updateVal(req.c_str(), "FP=", &paletteIn, 0, strip.getPaletteCount()-1);
|
paletteChanged = updateVal(req.c_str(), "FP=", &paletteIn, 0, strip.getPaletteCount()-1);
|
||||||
@@ -1066,31 +1061,31 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
|
|
||||||
//set advanced overlay
|
//set advanced overlay
|
||||||
pos = req.indexOf(F("OL="));
|
pos = req.indexOf(F("OL="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
overlayCurrent = getNumVal(&req, pos);
|
overlayCurrent = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
//apply macro (deprecated, added for compatibility with pre-0.11 automations)
|
//apply macro (deprecated, added for compatibility with pre-0.11 automations)
|
||||||
pos = req.indexOf(F("&M="));
|
pos = req.indexOf(F("&M="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
applyPreset(getNumVal(&req, pos) + 16);
|
applyPreset(getNumVal(&req, pos) + 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
//toggle send UDP direct notifications
|
//toggle send UDP direct notifications
|
||||||
pos = req.indexOf(F("SN="));
|
pos = req.indexOf(F("SN="));
|
||||||
if (pos > 0) notifyDirect = (req.charAt(pos+3) != '0');
|
if (pos >= 0) notifyDirect = (req.charAt(pos+3) != '0');
|
||||||
|
|
||||||
//toggle receive UDP direct notifications
|
//toggle receive UDP direct notifications
|
||||||
pos = req.indexOf(F("RN="));
|
pos = req.indexOf(F("RN="));
|
||||||
if (pos > 0) receiveGroups = (req.charAt(pos+3) != '0') ? receiveGroups | 1 : receiveGroups & 0xFE;
|
if (pos >= 0) receiveGroups = (req.charAt(pos+3) != '0') ? receiveGroups | 1 : receiveGroups & 0xFE;
|
||||||
|
|
||||||
//receive live data via UDP/Hyperion
|
//receive live data via UDP/Hyperion
|
||||||
pos = req.indexOf(F("RD="));
|
pos = req.indexOf(F("RD="));
|
||||||
if (pos > 0) receiveDirect = (req.charAt(pos+3) != '0');
|
if (pos >= 0) receiveDirect = (req.charAt(pos+3) != '0');
|
||||||
|
|
||||||
//main toggle on/off (parse before nightlight, #1214)
|
//main toggle on/off (parse before nightlight, #1214)
|
||||||
pos = req.indexOf(F("&T="));
|
pos = req.indexOf(F("&T="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
nightlightActive = false; //always disable nightlight when toggling
|
nightlightActive = false; //always disable nightlight when toggling
|
||||||
switch (getNumVal(&req, pos))
|
switch (getNumVal(&req, pos))
|
||||||
{
|
{
|
||||||
@@ -1102,9 +1097,9 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
|
|
||||||
//toggle nightlight mode
|
//toggle nightlight mode
|
||||||
bool aNlDef = false;
|
bool aNlDef = false;
|
||||||
if (req.indexOf(F("&ND")) > 0) aNlDef = true;
|
if (req.indexOf(F("&ND")) >= 0) aNlDef = true;
|
||||||
pos = req.indexOf(F("NL="));
|
pos = req.indexOf(F("NL="));
|
||||||
if (pos > 0)
|
if (pos >= 0)
|
||||||
{
|
{
|
||||||
if (req.charAt(pos+3) == '0')
|
if (req.charAt(pos+3) == '0')
|
||||||
{
|
{
|
||||||
@@ -1124,14 +1119,14 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
|
|
||||||
//set nightlight target brightness
|
//set nightlight target brightness
|
||||||
pos = req.indexOf(F("NT="));
|
pos = req.indexOf(F("NT="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
nightlightTargetBri = getNumVal(&req, pos);
|
nightlightTargetBri = getNumVal(&req, pos);
|
||||||
nightlightActiveOld = false; //re-init
|
nightlightActiveOld = false; //re-init
|
||||||
}
|
}
|
||||||
|
|
||||||
//toggle nightlight fade
|
//toggle nightlight fade
|
||||||
pos = req.indexOf(F("NF="));
|
pos = req.indexOf(F("NF="));
|
||||||
if (pos > 0)
|
if (pos >= 0)
|
||||||
{
|
{
|
||||||
nightlightMode = getNumVal(&req, pos);
|
nightlightMode = getNumVal(&req, pos);
|
||||||
|
|
||||||
@@ -1140,24 +1135,24 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
if (nightlightMode > NL_MODE_SUN) nightlightMode = NL_MODE_SUN;
|
if (nightlightMode > NL_MODE_SUN) nightlightMode = NL_MODE_SUN;
|
||||||
|
|
||||||
pos = req.indexOf(F("TT="));
|
pos = req.indexOf(F("TT="));
|
||||||
if (pos > 0) transitionDelay = getNumVal(&req, pos);
|
if (pos >= 0) transitionDelay = getNumVal(&req, pos);
|
||||||
if (fadeTransition) strip.setTransition(transitionDelay);
|
if (fadeTransition) strip.setTransition(transitionDelay);
|
||||||
|
|
||||||
//set time (unix timestamp)
|
//set time (unix timestamp)
|
||||||
pos = req.indexOf(F("ST="));
|
pos = req.indexOf(F("ST="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
setTimeFromAPI(getNumVal(&req, pos));
|
setTimeFromAPI(getNumVal(&req, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
//set countdown goal (unix timestamp)
|
//set countdown goal (unix timestamp)
|
||||||
pos = req.indexOf(F("CT="));
|
pos = req.indexOf(F("CT="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
countdownTime = getNumVal(&req, pos);
|
countdownTime = getNumVal(&req, pos);
|
||||||
if (countdownTime - toki.second() > 0) countdownOverTriggered = false;
|
if (countdownTime - toki.second() > 0) countdownOverTriggered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = req.indexOf(F("LO="));
|
pos = req.indexOf(F("LO="));
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
realtimeOverride = getNumVal(&req, pos);
|
realtimeOverride = getNumVal(&req, pos);
|
||||||
if (realtimeOverride > 2) realtimeOverride = REALTIME_OVERRIDE_ALWAYS;
|
if (realtimeOverride > 2) realtimeOverride = REALTIME_OVERRIDE_ALWAYS;
|
||||||
if (realtimeMode && useMainSegmentOnly) {
|
if (realtimeMode && useMainSegmentOnly) {
|
||||||
@@ -1166,19 +1161,19 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pos = req.indexOf(F("RB"));
|
pos = req.indexOf(F("RB"));
|
||||||
if (pos > 0) doReboot = true;
|
if (pos >= 0) doReboot = true;
|
||||||
|
|
||||||
// clock mode, 0: normal, 1: countdown
|
// clock mode, 0: normal, 1: countdown
|
||||||
pos = req.indexOf(F("NM="));
|
pos = req.indexOf(F("NM="));
|
||||||
if (pos > 0) countdownMode = (req.charAt(pos+3) != '0');
|
if (pos >= 0) countdownMode = (req.charAt(pos+3) != '0');
|
||||||
|
|
||||||
pos = req.indexOf(F("U0=")); //user var 0
|
pos = req.indexOf(F("U0=")); //user var 0
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
userVar0 = getNumVal(&req, pos);
|
userVar0 = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = req.indexOf(F("U1=")); //user var 1
|
pos = req.indexOf(F("U1=")); //user var 1
|
||||||
if (pos > 0) {
|
if (pos >= 0) {
|
||||||
userVar1 = getNumVal(&req, pos);
|
userVar1 = getNumVal(&req, pos);
|
||||||
}
|
}
|
||||||
// you can add more if you need
|
// you can add more if you need
|
||||||
@@ -1187,15 +1182,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
|||||||
if (!apply) return true; // when called by JSON API, do not call colorUpdated() here
|
if (!apply) return true; // when called by JSON API, do not call colorUpdated() here
|
||||||
|
|
||||||
pos = req.indexOf(F("&NN")); //do not send UDP notifications this time
|
pos = req.indexOf(F("&NN")); //do not send UDP notifications this time
|
||||||
stateUpdated((pos > 0) ? CALL_MODE_NO_NOTIFY : CALL_MODE_DIRECT_CHANGE);
|
stateUpdated((pos >= 0) ? CALL_MODE_NO_NOTIFY : CALL_MODE_DIRECT_CHANGE);
|
||||||
|
|
||||||
// internal call, does not send XML response
|
|
||||||
pos = req.indexOf(F("IN"));
|
|
||||||
if ((request != nullptr) && (pos < 1)) {
|
|
||||||
auto response = request->beginResponseStream("text/xml");
|
|
||||||
XML_response(*response);
|
|
||||||
request->send(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -681,9 +681,7 @@ void handleNotifications()
|
|||||||
|
|
||||||
if (requestJSONBufferLock(18)) {
|
if (requestJSONBufferLock(18)) {
|
||||||
if (udpIn[0] >= 'A' && udpIn[0] <= 'Z') { //HTTP API
|
if (udpIn[0] >= 'A' && udpIn[0] <= 'Z') { //HTTP API
|
||||||
String apireq = "win"; apireq += '&'; // reduce flash string usage
|
handleHttpApi((char*)udpIn);
|
||||||
apireq += (char*)udpIn;
|
|
||||||
handleSet(nullptr, apireq);
|
|
||||||
} else if (udpIn[0] == '{') { //JSON API
|
} else if (udpIn[0] == '{') { //JSON API
|
||||||
DeserializationError error = deserializeJson(*pDoc, udpIn);
|
DeserializationError error = deserializeJson(*pDoc, udpIn);
|
||||||
JsonObject root = pDoc->as<JsonObject>();
|
JsonObject root = pDoc->as<JsonObject>();
|
||||||
|
@@ -482,7 +482,17 @@ void initServer()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(handleSet(request, request->url())) return;
|
if (request->url().indexOf("win") == 0) {
|
||||||
|
if (handleHttpApi(request->url().substring(3))) {
|
||||||
|
if (request->url().indexOf(F("&FX=")) > 0) {
|
||||||
|
unloadPlaylist(); // Setting an FX via HTTP disables any active playlist.
|
||||||
|
}
|
||||||
|
auto response = request->beginResponseStream(CONTENT_TYPE_XML);
|
||||||
|
XML_response(*response);
|
||||||
|
request->send(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
#ifndef WLED_DISABLE_ALEXA
|
#ifndef WLED_DISABLE_ALEXA
|
||||||
if(espalexa.handleAlexaApiCall(request)) return;
|
if(espalexa.handleAlexaApiCall(request)) return;
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user