replace StrContains and num functions

settings html now contains all fields planned for v0.3
This commit is contained in:
cschwinne 2016-10-31 21:16:39 +01:00
parent d190964b95
commit 9baf2f3eb8
3 changed files with 48 additions and 82 deletions

View File

@ -12,7 +12,6 @@ do not reboot after settings set -> add reboot button
svg icons in html svg icons in html
notifier function -> send get request notifier function -> send get request
nightlight function -> turns off after set time (+implement fading) nightlight function -> turns off after set time (+implement fading)
(replace StrContains and num functions)
add preferred colors to settings -> quickly t. UI, button select, add preferred colors to settings -> quickly t. UI, button select,
BUGS BUGS

View File

@ -104,14 +104,25 @@
<h3>Transitions</h3> <h3>Transitions</h3>
Fade: <input type="checkbox" name="TFADE" value="0"> <br> Fade: <input type="checkbox" name="TFADE" value="0"> <br>
Transition Delay: <input type="text" name="TDLAY" maxlength="5" size="2"> ms <br> Transition Delay: <input type="text" name="TDLAY" maxlength="5" size="2"> ms <br>
<h3>Timed light</h3>
Turn off after: <input type="text" name="TLDUR" maxlength="3" size="2"> min <br>
Fade down: <input type="checkbox" name="TLFDE" value="0"> <br>
<h3>Daisy chain</h3> <h3>Daisy chain</h3>
<i>Not implemented</i> <br> Receive notifications: <input type="checkbox" name="NRCVE" value="0"> <br>
Received brightness factor: <input type="text" name="NRBRI" maxlength="3" size="2"> % <br><br>
Send notifications on direct change: <input type="checkbox" name="NSDIR" value="0"> <br>
Send notifications on button press: <input type="checkbox" name="NSBTN" value="0"> <br>
Send received notifications: <input type="checkbox" name="NSRCV" value="0"> <br>
Hosts to send notifications to: (1 IP per line) <br>
<textarea name="NSIPS" rows="8" cols="16"></textarea>
<h3>Security</h3> <h3>Security</h3>
Disable OTA: <input type="checkbox" name="NOOTA" value="0"> <br> OTA enabled: <input type="checkbox" name="NOOTA" value="0"> <br>
ArduinoOTA and the edit page will be inaccessible until a SPIFFS reflash! <br> Passphrase: <input type="password" name="OPASS" maxlength="32"> <br>
Checking this is advised for added security if you don't need software changes. <br> To enable OTA, for security reasons you need to also enter the correct password! <br>
The password may/should be changed when OTA is enabled. <br>
Disable OTA when not in use, otherwise an attacker could reflash device software! <br>
Current status: <span class="otastat"> Unknown </span> <br> <br> Current status: <span class="otastat"> Unknown </span> <br> <br>
Disable recovery AP: <input type="checkbox" name="NORAP" value="0"> <br> Disable recovery AP (<i>Not implemented</i>): <input type="checkbox" name="NORAP" value="0"> <br>
In case of a connection error there will be no wireless recovery possible! <br> In case of a connection error there will be no wireless recovery possible! <br>
Completely disables all Access Point functions. <br> <br> Completely disables all Access Point functions. <br> <br>
Factory reset: <input type="checkbox" name="RESET" value="0"> <br> Factory reset: <input type="checkbox" name="RESET" value="0"> <br>

View File

@ -48,8 +48,6 @@ boolean buttonPressedBefore = false;
NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(led_amount, 1); NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(led_amount, 1);
char HTTP_req[150];
ESP8266WebServer server(80); ESP8266WebServer server(80);
ESP8266HTTPUpdateServer httpUpdater; ESP8266HTTPUpdateServer httpUpdater;
@ -319,48 +317,6 @@ void XML_response_settings()
server.send(200, "text/xml", resp); server.send(200, "text/xml", resp);
} }
char StrContains(char *str, char *sfind)
{
char found = 0;
char index = 0;
char len;
len = strlen(str);
if (strlen(sfind) > len) {
return 0;
}
while (index < len) {
if (str[index] == sfind[found]) {
found++;
if (strlen(sfind) == found) {
return index;
}
}
else {
found = 0;
}
index++;
}
return 0;
}
uint8_t getNumberAfterStringPos(char str[], char spos)
{
String op;
boolean no_n = false;
int i = 0;
while (!no_n) {
if (str[spos + i + 1] > 47 && str[spos + i + 1] < 58)
{
op += str[spos + i + 1];
}
else {no_n = true;}
i++;
}
return op.toInt();
}
void handleSettingsSet() void handleSettingsSet()
{ {
if (server.hasArg("CSSID")) clientssid = server.arg("CSSID"); if (server.hasArg("CSSID")) clientssid = server.arg("CSSID");
@ -473,11 +429,8 @@ void handleSettingsSet()
boolean handleSet(String req) boolean handleSet(String req)
{ {
Serial.println("handleSet:"); if (!(req.indexOf("ajax_in") >= 0)) {
Serial.println(req); if (req.indexOf("get-settings") >= 0)
req.toCharArray(HTTP_req, 150, 0);
if (!StrContains(HTTP_req, "ajax_in")) {
if (StrContains(HTTP_req, "get-settings"))
{ {
XML_response_settings(); XML_response_settings();
return true; return true;
@ -485,22 +438,22 @@ boolean handleSet(String req)
return false; return false;
} }
int pos = 0; int pos = 0;
pos = StrContains(HTTP_req, "A="); pos = req.indexOf("A=");
if (pos > 0) { if (pos > 0) {
bri = getNumberAfterStringPos(HTTP_req, pos); bri = req.substring(pos + 2).toInt();
} }
pos = StrContains(HTTP_req, "R="); pos = req.indexOf("R=");
if (pos > 0) { if (pos > 0) {
col[0] = getNumberAfterStringPos(HTTP_req, pos); col[0] = req.substring(pos + 2).toInt();
} }
pos = StrContains(HTTP_req, "G="); pos = req.indexOf("G=");
if (pos > 0) { if (pos > 0) {
col[1] = getNumberAfterStringPos(HTTP_req, pos); col[1] = req.substring(pos + 2).toInt();
} }
pos = StrContains(HTTP_req, "B="); pos = req.indexOf("B=");
if (pos > 0) { if (pos > 0) {
col[2] = getNumberAfterStringPos(HTTP_req, pos); col[2] = req.substring(pos + 2).toInt();
} }
XML_response(); XML_response();
colorUpdated(); colorUpdated();
return true; return true;
@ -708,25 +661,28 @@ void handleAnimations(){};
void handleButton() void handleButton()
{ {
if (digitalRead(buttonPin) == LOW && !buttonPressedBefore) if (buttonEnabled)
{ {
buttonPressedBefore = true; if (digitalRead(buttonPin) == LOW && !buttonPressedBefore)
if (bri == 0)
{ {
bri = bri_last; buttonPressedBefore = true;
} else if (bri == 0)
{ {
bri_last = bri; bri = bri_last;
bri = 0; } else
{
bri_last = bri;
bri = 0;
}
colorUpdated();
} }
colorUpdated(); else if (digitalRead(buttonPin) == HIGH && buttonPressedBefore)
}
else if (digitalRead(buttonPin) == HIGH && buttonPressedBefore)
{
delay(15);
if (digitalRead(buttonPin) == HIGH)
{ {
buttonPressedBefore = false; delay(15);
if (digitalRead(buttonPin) == HIGH)
{
buttonPressedBefore = false;
}
} }
} }
} }