2016-12-31 00:38:51 +01:00
|
|
|
/*
|
|
|
|
* Receives client input
|
|
|
|
*/
|
|
|
|
|
2016-11-19 19:39:17 +01:00
|
|
|
void handleSettingsSet()
|
|
|
|
{
|
|
|
|
if (server.hasArg("CSSID")) clientssid = server.arg("CSSID");
|
|
|
|
if (server.hasArg("CPASS"))
|
|
|
|
{
|
|
|
|
if (!server.arg("CPASS").indexOf('*') == 0)
|
|
|
|
{
|
2017-01-15 00:24:28 +01:00
|
|
|
DEBUG_PRINTLN("Setting pass");
|
2016-11-19 19:39:17 +01:00
|
|
|
clientpass = server.arg("CPASS");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (server.hasArg("CMDNS")) cmdns = server.arg("CMDNS");
|
2017-11-20 00:07:37 +01:00
|
|
|
if (server.hasArg("APWTM"))
|
2016-11-19 19:39:17 +01:00
|
|
|
{
|
2017-11-20 00:07:37 +01:00
|
|
|
int i = server.arg("APWTM").toInt();
|
|
|
|
if (i >= 0 && i <= 255) apWaitTimeSecs = i;
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
2017-11-20 00:07:37 +01:00
|
|
|
if (server.hasArg("APSSID")) apssid = server.arg("APSSID");
|
|
|
|
aphide = server.hasArg("APHSSID");
|
2016-11-19 19:39:17 +01:00
|
|
|
if (server.hasArg("APPASS"))
|
|
|
|
{
|
|
|
|
if (!server.arg("APPASS").indexOf('*') == 0) appass = server.arg("APPASS");
|
|
|
|
}
|
|
|
|
if (server.hasArg("APCHAN"))
|
|
|
|
{
|
|
|
|
int chan = server.arg("APCHAN").toInt();
|
|
|
|
if (chan > 0 && chan < 14) apchannel = chan;
|
|
|
|
}
|
|
|
|
if (server.hasArg("RESET")) //might be dangerous in case arg is always sent
|
|
|
|
{
|
|
|
|
clearEEPROM();
|
2017-11-20 00:07:37 +01:00
|
|
|
server.send(200, "text/plain", "Settings erased. Rebooting...");
|
2016-11-19 19:39:17 +01:00
|
|
|
reset();
|
|
|
|
}
|
|
|
|
if (server.hasArg("CSIP0"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CSIP0").toInt();
|
|
|
|
if (i >= 0 && i <= 255) staticip[0] = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("CSIP1"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CSIP1").toInt();
|
|
|
|
if (i >= 0 && i <= 255) staticip[1] = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("CSIP2"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CSIP2").toInt();
|
|
|
|
if (i >= 0 && i <= 255) staticip[2] = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("CSIP3"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CSIP3").toInt();
|
|
|
|
if (i >= 0 && i <= 255) staticip[3] = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("CSGW0"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CSGW0").toInt();
|
|
|
|
if (i >= 0 && i <= 255) staticgateway[0] = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("CSGW1"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CSGW1").toInt();
|
|
|
|
if (i >= 0 && i <= 255) staticgateway[1] = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("CSGW2"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CSGW2").toInt();
|
|
|
|
if (i >= 0 && i <= 255) staticgateway[2] = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("CSGW3"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CSGW3").toInt();
|
|
|
|
if (i >= 0 && i <= 255) staticgateway[3] = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("CSSN0"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CSSN0").toInt();
|
|
|
|
if (i >= 0 && i <= 255) staticsubnet[0] = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("CSSN1"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CSSN1").toInt();
|
|
|
|
if (i >= 0 && i <= 255) staticsubnet[1] = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("CSSN2"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CSSN2").toInt();
|
|
|
|
if (i >= 0 && i <= 255) staticsubnet[2] = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("CSSN3"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CSSN3").toInt();
|
|
|
|
if (i >= 0 && i <= 255) staticsubnet[3] = i;
|
|
|
|
}
|
2016-12-11 20:11:14 +01:00
|
|
|
if (server.hasArg("DESC")) serverDescription = server.arg("DESC");
|
2017-05-07 23:51:42 +02:00
|
|
|
useHSBDefault = server.hasArg("COLMD");
|
|
|
|
useHSB = useHSBDefault;
|
2017-02-24 23:21:48 +01:00
|
|
|
if (server.hasArg("LEDCN"))
|
|
|
|
{
|
|
|
|
int i = server.arg("LEDCN").toInt();
|
|
|
|
if (i >= 0 && i <= 255) ledcount = i;
|
|
|
|
strip.setLedCount(ledcount);
|
|
|
|
}
|
2016-12-29 00:03:58 +01:00
|
|
|
if (server.hasArg("CBEOR"))
|
|
|
|
{
|
|
|
|
col_s[0] = col[0];
|
|
|
|
col_s[1] = col[1];
|
|
|
|
col_s[2] = col[2];
|
|
|
|
bri_s = bri;
|
|
|
|
effectDefault = effectCurrent;
|
|
|
|
effectSpeedDefault = effectSpeed;
|
|
|
|
} else {
|
|
|
|
if (server.hasArg("CLDFR"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CLDFR").toInt();
|
|
|
|
if (i >= 0 && i <= 255) col_s[0] = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("CLDFG"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CLDFG").toInt();
|
|
|
|
if (i >= 0 && i <= 255) col_s[1] = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("CLDFB"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CLDFB").toInt();
|
|
|
|
if (i >= 0 && i <= 255) col_s[2] = i;
|
|
|
|
}
|
2017-10-12 17:09:59 +02:00
|
|
|
if (server.hasArg("CLDFW"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CLDFW").toInt();
|
2017-10-12 22:20:37 +02:00
|
|
|
if (i >= 0 && i <= 255)
|
|
|
|
{
|
|
|
|
useRGBW = true;
|
|
|
|
white_s = i;
|
|
|
|
} else {
|
|
|
|
useRGBW = false;
|
|
|
|
white_s = 0;
|
|
|
|
}
|
2017-10-12 17:09:59 +02:00
|
|
|
}
|
2016-12-29 00:03:58 +01:00
|
|
|
if (server.hasArg("CLDFA"))
|
|
|
|
{
|
|
|
|
int i = server.arg("CLDFA").toInt();
|
|
|
|
if (i >= 0 && i <= 255) bri_s = i;
|
|
|
|
}
|
2017-03-07 22:05:18 +01:00
|
|
|
turnOnAtBoot = server.hasArg("BOOTN");
|
2016-12-29 00:03:58 +01:00
|
|
|
if (server.hasArg("FXDEF"))
|
|
|
|
{
|
|
|
|
int i = server.arg("FXDEF").toInt();
|
|
|
|
if (i >= 0 && i <= 255) effectDefault = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("SXDEF"))
|
|
|
|
{
|
|
|
|
int i = server.arg("SXDEF").toInt();
|
|
|
|
if (i >= 0 && i <= 255) effectSpeedDefault = i;
|
|
|
|
}
|
|
|
|
}
|
2017-02-01 19:25:36 +01:00
|
|
|
useGammaCorrectionBri = server.hasArg("GCBRI");
|
|
|
|
useGammaCorrectionRGB = server.hasArg("GCRGB");
|
2016-11-19 19:39:17 +01:00
|
|
|
buttonEnabled = server.hasArg("BTNON");
|
|
|
|
fadeTransition = server.hasArg("TFADE");
|
2017-10-28 22:22:37 +02:00
|
|
|
sweepTransition = server.hasArg("TSWEE");
|
|
|
|
sweepDirection = !server.hasArg("TSDIR");
|
2016-11-19 19:39:17 +01:00
|
|
|
if (server.hasArg("TDLAY"))
|
|
|
|
{
|
|
|
|
int i = server.arg("TDLAY").toInt();
|
2016-11-27 16:45:54 +01:00
|
|
|
if (i > 0){
|
|
|
|
transitionDelay = i;
|
|
|
|
}
|
2016-11-19 19:39:17 +01:00
|
|
|
}
|
2016-12-11 20:11:14 +01:00
|
|
|
if (server.hasArg("TLBRI"))
|
|
|
|
{
|
|
|
|
bri_nl = server.arg("TLBRI").toInt();
|
|
|
|
}
|
2016-11-20 01:47:15 +01:00
|
|
|
if (server.hasArg("TLDUR"))
|
|
|
|
{
|
|
|
|
int i = server.arg("TLDUR").toInt();
|
|
|
|
if (i > 0) nightlightDelayMins = i;
|
|
|
|
}
|
|
|
|
nightlightFade = server.hasArg("TLFDE");
|
2016-12-11 20:11:14 +01:00
|
|
|
if (server.hasArg("NUDPP"))
|
|
|
|
{
|
|
|
|
udpPort = server.arg("NUDPP").toInt();
|
|
|
|
}
|
2016-11-19 19:39:17 +01:00
|
|
|
receiveNotifications = server.hasArg("NRCVE");
|
2016-12-14 21:40:09 +01:00
|
|
|
receiveNotificationsDefault = receiveNotifications;
|
2016-11-19 19:39:17 +01:00
|
|
|
if (server.hasArg("NRBRI"))
|
|
|
|
{
|
|
|
|
int i = server.arg("NRBRI").toInt();
|
|
|
|
if (i > 0) bri_n = i;
|
|
|
|
}
|
2017-05-08 21:46:04 +02:00
|
|
|
notifyDirectDefault = server.hasArg("NSDIR");
|
|
|
|
notifyDirect = notifyDirectDefault;
|
2016-11-19 19:39:17 +01:00
|
|
|
notifyButton = server.hasArg("NSBTN");
|
2017-02-24 23:21:48 +01:00
|
|
|
alexaEnabled = server.hasArg("ALEXA");
|
|
|
|
if (server.hasArg("AINVN")) alexaInvocationName = server.arg("AINVN");
|
|
|
|
alexaNotify = server.hasArg("NSALX");
|
2016-12-29 00:03:58 +01:00
|
|
|
ntpEnabled = server.hasArg("NTPON");
|
2017-02-24 23:21:48 +01:00
|
|
|
if (server.hasArg("OLDEF"))
|
|
|
|
{
|
|
|
|
int i = server.arg("OLDEF").toInt();
|
|
|
|
if (i >= 0 && i <= 255) overlayDefault = i;
|
|
|
|
}
|
|
|
|
if (server.hasArg("WOFFS"))
|
|
|
|
{
|
|
|
|
int i = server.arg("WOFFS").toInt();
|
|
|
|
if (i >= 0 && i <= 255) arlsOffset = i;
|
|
|
|
arlsSign = true;
|
|
|
|
if (server.hasArg("WOFFN"))
|
|
|
|
{
|
|
|
|
arlsSign = false;
|
|
|
|
arlsOffset = -arlsOffset;
|
|
|
|
}
|
|
|
|
}
|
2016-11-20 01:47:15 +01:00
|
|
|
if (server.hasArg("OPASS"))
|
|
|
|
{
|
2017-11-20 00:07:37 +01:00
|
|
|
if (!otaLock)
|
2016-11-20 01:47:15 +01:00
|
|
|
{
|
|
|
|
if (server.arg("OPASS").length() > 0)
|
|
|
|
otapass = server.arg("OPASS");
|
|
|
|
} else if (!server.hasArg("NOOTA"))
|
|
|
|
{
|
|
|
|
if (otapass.equals(server.arg("OPASS")))
|
|
|
|
{
|
2017-11-20 00:07:37 +01:00
|
|
|
otaLock = false;
|
2016-11-20 01:47:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-20 00:07:37 +01:00
|
|
|
if (server.hasArg("NOOTA")) otaLock = true;
|
|
|
|
if (server.hasArg("NORAP")) {
|
|
|
|
if (!otaLock) recoveryAPDisabled = true;
|
|
|
|
} else {
|
|
|
|
recoveryAPDisabled = false;
|
|
|
|
}
|
2016-11-19 19:39:17 +01:00
|
|
|
saveSettingsToEEPROM();
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean handleSet(String req)
|
|
|
|
{
|
2016-12-14 23:40:47 +01:00
|
|
|
boolean effectUpdated = false;
|
2017-02-01 19:25:36 +01:00
|
|
|
if (!(req.indexOf("win") >= 0)) {
|
2016-11-19 19:39:17 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int pos = 0;
|
2017-11-19 15:31:17 +01:00
|
|
|
//set brigthness
|
2016-11-19 19:39:17 +01:00
|
|
|
pos = req.indexOf("A=");
|
|
|
|
if (pos > 0) {
|
|
|
|
bri = req.substring(pos + 2).toInt();
|
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//set red value
|
2016-11-19 19:39:17 +01:00
|
|
|
pos = req.indexOf("R=");
|
|
|
|
if (pos > 0) {
|
|
|
|
col[0] = req.substring(pos + 2).toInt();
|
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//set green value
|
2016-11-19 19:39:17 +01:00
|
|
|
pos = req.indexOf("G=");
|
|
|
|
if (pos > 0) {
|
|
|
|
col[1] = req.substring(pos + 2).toInt();
|
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//set blue value
|
2016-11-19 19:39:17 +01:00
|
|
|
pos = req.indexOf("B=");
|
|
|
|
if (pos > 0) {
|
|
|
|
col[2] = req.substring(pos + 2).toInt();
|
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//set white value
|
2017-10-12 17:09:59 +02:00
|
|
|
pos = req.indexOf("W=");
|
|
|
|
if (pos > 0) {
|
|
|
|
white = req.substring(pos + 2).toInt();
|
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//set current effect index
|
2016-12-14 21:40:09 +01:00
|
|
|
pos = req.indexOf("FX=");
|
|
|
|
if (pos > 0) {
|
2016-12-17 23:43:07 +01:00
|
|
|
if (effectCurrent != req.substring(pos + 3).toInt())
|
|
|
|
{
|
|
|
|
effectCurrent = req.substring(pos + 3).toInt();
|
|
|
|
strip.setMode(effectCurrent);
|
|
|
|
effectUpdated = true;
|
|
|
|
}
|
2016-12-14 21:40:09 +01:00
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//set effect speed
|
2016-12-31 00:38:51 +01:00
|
|
|
pos = req.indexOf("SX=");
|
2016-12-14 21:40:09 +01:00
|
|
|
if (pos > 0) {
|
2016-12-17 23:43:07 +01:00
|
|
|
if (effectSpeed != req.substring(pos + 3).toInt())
|
|
|
|
{
|
|
|
|
effectSpeed = req.substring(pos + 3).toInt();
|
|
|
|
strip.setSpeed(effectSpeed);
|
|
|
|
effectUpdated = true;
|
|
|
|
}
|
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//set default control mode (0 - RGB, 1 - HSB)
|
2017-05-07 23:51:42 +02:00
|
|
|
pos = req.indexOf("MD=");
|
|
|
|
if (pos > 0) {
|
|
|
|
useHSB = req.substring(pos + 3).toInt();
|
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//set advanced overlay
|
2016-12-31 21:10:33 +01:00
|
|
|
pos = req.indexOf("OL=");
|
|
|
|
if (pos > 0) {
|
|
|
|
overlayCurrent = req.substring(pos + 3).toInt();
|
|
|
|
strip.unlockAll();
|
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//set individual pixel (range) to current color
|
2016-12-17 23:43:07 +01:00
|
|
|
pos = req.indexOf("I=");
|
|
|
|
if (pos > 0){
|
|
|
|
int index = req.substring(pos + 2).toInt();
|
|
|
|
pos = req.indexOf("I2=");
|
|
|
|
if (pos > 0){
|
|
|
|
int index2 = req.substring(pos + 3).toInt();
|
|
|
|
strip.setRange(index, index2);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
strip.setIndividual(index);
|
|
|
|
}
|
2016-12-14 21:40:09 +01:00
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//(un)lock pixel (ranges)
|
|
|
|
pos = req.indexOf("L=");
|
|
|
|
if (pos > 0){
|
|
|
|
int index = req.substring(pos + 2).toInt();
|
|
|
|
pos = req.indexOf("L2=");
|
|
|
|
if (pos > 0){
|
|
|
|
int index2 = req.substring(pos + 3).toInt();
|
|
|
|
if (req.indexOf("UL=") > 0)
|
|
|
|
{
|
|
|
|
strip.unlockRange(index, index2);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
strip.lockRange(index, index2);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (req.indexOf("UL=") > 0)
|
|
|
|
{
|
|
|
|
strip.unlock(index);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
strip.lock(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//toggle send UDP direct notifications
|
2017-05-07 23:51:42 +02:00
|
|
|
if (req.indexOf("SN=") > 0)
|
2016-12-14 21:40:09 +01:00
|
|
|
{
|
2017-05-08 21:46:04 +02:00
|
|
|
notifyDirect = true;
|
2017-05-07 23:51:42 +02:00
|
|
|
if (req.indexOf("SN=0") > 0)
|
2016-12-14 21:40:09 +01:00
|
|
|
{
|
2017-05-08 21:46:04 +02:00
|
|
|
notifyDirect = false;
|
2016-12-14 21:40:09 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//toggle receive UDP direct notifications
|
2017-05-07 23:51:42 +02:00
|
|
|
if (req.indexOf("RN=") > 0)
|
2016-12-14 21:40:09 +01:00
|
|
|
{
|
|
|
|
receiveNotifications = true;
|
2017-05-07 23:51:42 +02:00
|
|
|
if (req.indexOf("RN=0") > 0)
|
2016-12-14 21:40:09 +01:00
|
|
|
{
|
|
|
|
receiveNotifications = false;
|
|
|
|
}
|
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//toggle nightlight mode
|
2016-11-19 19:39:17 +01:00
|
|
|
if (req.indexOf("NL=") > 0)
|
|
|
|
{
|
|
|
|
if (req.indexOf("NL=0") > 0)
|
|
|
|
{
|
|
|
|
nightlightActive = false;
|
2016-12-11 20:11:14 +01:00
|
|
|
bri = bri_t;
|
2016-11-19 19:39:17 +01:00
|
|
|
} else {
|
|
|
|
nightlightActive = true;
|
|
|
|
nightlightStartTime = millis();
|
|
|
|
}
|
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//toggle general purpose output
|
2017-01-27 22:59:01 +01:00
|
|
|
pos = req.indexOf("AX=");
|
|
|
|
if (pos > 0) {
|
2017-02-07 13:00:33 +01:00
|
|
|
auxTime = req.substring(pos + 3).toInt();
|
|
|
|
auxActive = true;
|
|
|
|
if (auxTime == 0) auxActive = false;
|
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//main toggle on/off
|
2017-02-07 13:00:33 +01:00
|
|
|
pos = req.indexOf("T=");
|
|
|
|
if (pos > 0) {
|
|
|
|
switch (req.substring(pos + 2).toInt())
|
|
|
|
{
|
|
|
|
case 0: if (bri != 0){bri_last = bri; bri = 0;} break; //off
|
|
|
|
case 1: bri = bri_last; break; //on
|
|
|
|
default: if (bri == 0) //toggle
|
|
|
|
{
|
|
|
|
bri = bri_last;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
bri_last = bri;
|
|
|
|
bri = 0;
|
|
|
|
}
|
|
|
|
}
|
2017-01-27 22:59:01 +01:00
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//internal call, does not send XML response
|
2017-02-21 23:59:47 +01:00
|
|
|
pos = req.indexOf("IN");
|
|
|
|
if (pos < 1)
|
|
|
|
{
|
|
|
|
XML_response();
|
|
|
|
}
|
2017-11-19 15:31:17 +01:00
|
|
|
//do not send UDP notifications this time
|
2017-02-21 23:59:47 +01:00
|
|
|
pos = req.indexOf("NN");
|
|
|
|
if (pos > 0)
|
|
|
|
{
|
|
|
|
colorUpdated(5);
|
|
|
|
return true;
|
|
|
|
}
|
2016-12-14 23:40:47 +01:00
|
|
|
if (effectUpdated)
|
|
|
|
{
|
|
|
|
colorUpdated(6);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
colorUpdated(1);
|
|
|
|
}
|
2016-11-19 19:39:17 +01:00
|
|
|
return true;
|
|
|
|
}
|