summaryrefslogtreecommitdiff
path: root/HouseControl.ino
diff options
context:
space:
mode:
Diffstat (limited to 'HouseControl.ino')
-rw-r--r--HouseControl.ino45
1 files changed, 44 insertions, 1 deletions
diff --git a/HouseControl.ino b/HouseControl.ino
index 8d293f9..9035a29 100644
--- a/HouseControl.ino
+++ b/HouseControl.ino
@@ -144,6 +144,31 @@ char* time_to_str(void *buf, time_t t) {
return (char*)buf;
}
+bool str_to_bytearray(byte *buf, byte *dest, byte base, byte n, char delim) {
+ byte i;
+ char *cur = (char*)buf, *next;
+ unsigned long int v;
+ for (i=0;i<n;i++) {
+ v = strtoul(cur, &next, base);
+ if (i==(n-1)) delim = '\0';
+ if ((v > 255) || (next[0] != delim) || (next == cur))
+ return false;
+ buf[i] = v;
+ cur = ++next;
+ }
+ memcpy(dest,buf,n);
+ return true;
+}
+
+bool str_to_ip(byte *buf, byte *ip) {
+ return str_to_bytearray(buf,ip,10,4,'.');
+}
+
+bool str_to_mac(byte *buf, byte *mac) {
+ return str_to_bytearray(buf,mac,16,6,':');
+}
+
+
/*********************************************************************************/
/* NTP/Time functions */
@@ -326,12 +351,30 @@ void configSetHandler(WebServer &server, WebServer::ConnectionType type, char *u
if (type == WebServer::POST) {
server.httpSuccess();
while (server.readPOSTparam((char*)buf2, BUF2_SIZE, (char*)buf1, BUF1_SIZE)) {
+ if ((strcmp((const char*)buf2, "mac") == 0))
+ if (!str_to_mac(buf1, config.mac)) { server.print("Invalid MAC Address"); return; }
+
+ if ((strcmp((const char*)buf2, "def_ip") == 0))
+ if (!str_to_ip(buf1, config.def_ip)) { server.print("Invalid IP Address"); return; }
+
+ if ((strcmp((const char*)buf2, "def_nm") == 0))
+ if (!str_to_ip(buf1, config.def_netmask)) { server.print("Invalid Netmask"); return; }
+
+ if ((strcmp((const char*)buf2, "def_gw") == 0))
+ if (!str_to_ip(buf1, config.def_gateway)) { server.print("Invalid Gateway"); return; }
+
+ if ((strcmp((const char*)buf2, "ntpserver") == 0))
+ if (!str_to_ip(buf1, config.ntpServer)) { server.print("Invalid NTP Server"); return; }
+
+ if ((strcmp((const char*)buf2, "stathost") == 0))
+ if (!str_to_ip(buf1, config.notifyHost)) { server.print("Invalid Status target"); return; }
+
server.print((char*)buf2);
server.print(" = '");
server.print((char*)buf1);
server.print("'<br />\n");
}
- server.print("OK");
+ server.print("Settings Saved Successfully");
return;
}