X10 Server - IOT device to leverage a collection of old X10 devices for home automation and lighting control.
Dependencies: IniManager mbed HTTPClient SWUpdate mbed-rtos Watchdog X10 SW_HTTPServer SW_String EthernetInterface TimeInterface SSDP
X10 Server
See the X10 Server Nodebook page
Diff: WebPages.cpp
- Revision:
- 10:ca0c1db6d933
- Parent:
- 8:a45fe77efcc5
- Child:
- 11:f7a5b6c7305c
--- a/WebPages.cpp Sun Mar 03 00:26:40 2019 +0000 +++ b/WebPages.cpp Sun Mar 03 23:41:27 2019 +0000 @@ -3,12 +3,10 @@ #include "EthernetInterface.h" #include "SW_String.h" -#include "X10.h" #include "WebPages.h" #include "IniManager.h" // v20 extern INI ini; -extern X10Interface cm17a; extern EthernetInterface eth; extern const char * BUILD_DATE; @@ -51,8 +49,8 @@ " <friendlyName>%s</friendlyName>\n" " <manufacturer>Belkin International Inc.</manufacturer>\n" ///< must be "Belkin..." for Alexa discovery " <manufacturerURL>http://www.smart-family.net</manufacturerURL>\n" ///< - " <modelDescription>Special thing</modelDescription>\n" ///< - " <modelName>Smart Node</modelName>\n" ///< + " <modelDescription>WattEye</modelDescription>\n" ///< + " <modelName>WattEye</modelName>\n" ///< " <modelNumber>1.0.0</modelNumber>\n" #if 1 " <modelURL>http://www.smart-family.net</modelURL>\n" ///< This causes it to fail to send completely @@ -67,80 +65,6 @@ " <url>icon.jpg</url>\n" " </iconList>\n" " <presentationURL>http://%s:%d</presentationURL>\n" -#if 0 - " <serviceList>\n" - " <service>\n" - " <serviceType>urn:Belkin:service:WiFiSetup:1</serviceType>\n" - " <serviceId>urn:Belkin:serviceId:WiFiSetup1</serviceId>\n" - " <controlURL>/upnp/control/WiFiSetup1</controlURL>\n" - " <eventSubURL>/upnp/event/WiFiSetup1</eventSubURL>\n" - " <SCPDURL>/setupservice.xml</SCPDURL>\n" - " </service>\n" - " <service>\n" - " <serviceType>urn:Belkin:service:timesync:1</serviceType>\n" - " <serviceId>urn:Belkin:serviceId:timesync1</serviceId>\n" - " <controlURL>/upnp/control/timesync1</controlURL>\n" - " <eventSubURL>/upnp/event/timesync1</eventSubURL>\n" - " <SCPDURL>/timesyncservice.xml</SCPDURL>\n" - " </service>\n" - " <service>\n" - " <serviceType>urn:Belkin:service:basicevent:1</serviceType>\n" - " <serviceId>urn:Belkin:serviceId:basicevent1</serviceId>\n" - " <controlURL>/upnp/control/basicevent1</controlURL>\n" - " <eventSubURL>/upnp/event/basicevent1</eventSubURL>\n" - " <SCPDURL>/eventservice.xml</SCPDURL>\n" - " </service>\n" - " <service>\n" - " <serviceType>urn:Belkin:service:firmwareupdate:1</serviceType>\n" - " <serviceId>urn:Belkin:serviceId:firmwareupdate1</serviceId>\n" - " <controlURL>/upnp/control/firmwareupdate1</controlURL>\n" - " <eventSubURL>/upnp/event/firmwareupdate1</eventSubURL>\n" - " <SCPDURL>/firmwareupdate.xml</SCPDURL>\n" - " </service>\n" - " <service>\n" - " <serviceType>urn:Belkin:service:rules:1</serviceType>\n" - " <serviceId>urn:Belkin:serviceId:rules1</serviceId>\n" - " <controlURL>/upnp/control/rules1</controlURL>\n" - " <eventSubURL>/upnp/event/rules1</eventSubURL>\n" - " <SCPDURL>/rulesservice.xml</SCPDURL>\n" - " </service>\n" - " <service>\n" - " <serviceType>urn:Belkin:service:metainfo:1</serviceType>\n" - " <serviceId>urn:Belkin:serviceId:metainfo1</serviceId>\n" - " <controlURL>/upnp/control/metainfo1</controlURL>\n" - " <eventSubURL>/upnp/event/metainfo1</eventSubURL>\n" - " <SCPDURL>/metainfoservice.xml</SCPDURL>\n" - " </service>\n" - " <service>\n" - " <serviceType>urn:Belkin:service:remoteaccess:1</serviceType>\n" - " <serviceId>urn:Belkin:serviceId:remoteaccess1</serviceId>\n" - " <controlURL>/upnp/control/remoteaccess1</controlURL>\n" - " <eventSubURL>/upnp/event/remoteaccess1</eventSubURL>\n" - " <SCPDURL>/remoteaccess.xml</SCPDURL>\n" - " </service>\n" - " <service>\n" - " <serviceType>urn:Belkin:service:deviceinfo:1</serviceType>\n" - " <serviceId>urn:Belkin:serviceId:deviceinfo1</serviceId>\n" - " <controlURL>/upnp/control/deviceinfo1</controlURL>\n" - " <eventSubURL>/upnp/event/deviceinfo1</eventSubURL>\n" - " <SCPDURL>/deviceinfoservice.xml</SCPDURL>\n" - " </service>\n" - " <service>\n" - " <serviceType>urn:Belkin:service:smartsetup:1</serviceType>\n" - " <serviceId>urn:Belkin:serviceId:smartsetup1</serviceId>\n" - " <controlURL>/upnp/control/smartsetup1</controlURL>\n" - " <eventSubURL>/upnp/event/smartsetup1</eventSubURL>\n" - " <SCPDURL>/smartsetup.xml</SCPDURL>\n" - " </service>\n" - " <service>\n" - " <serviceType>urn:Belkin:service:manufacture:1</serviceType>\n" - " <serviceId>urn:Belkin:serviceId:manufacture1</serviceId>\n" - " <controlURL>/upnp/control/manufacture1</controlURL>\n" - " <eventSubURL>/upnp/event/manufacture1</eventSubURL>\n" - " <SCPDURL>/manufacture.xml</SCPDURL>\n" - " </service>\n" - " </serviceList>\n" -#endif " </device>\n" "</root>\n"; @@ -179,7 +103,7 @@ HTTPServer::CallBackResults RootPage(HTTPServer *svr, HTTPServer::CallBackType type, char * path, const HTTPServer::namevalue *queryParams, int queryParamCount) { - char smallBuf[100]; + //char smallBuf[100]; char bigBuf[3000] = ""; // sized by test and adjust, and then round up generously. int count; HTTPServer::CallBackResults ret = HTTPServer::ACCEPT_ERROR; @@ -212,7 +136,7 @@ strcat_s(cmdBuf, sizeof(cmdBuf), " "); strcat_s(cmdBuf, sizeof(cmdBuf), p); printf("Web Command: '%s'\r\n", cmdBuf); - cm17a.ParseCommand(cmdBuf); + //cm17a.ParseCommand(cmdBuf); svr->header(HTTPServer::Found, "Found", "Location: /\r\n"); svr->send("\r\n"); break; @@ -222,7 +146,7 @@ } svr->header(HTTPServer::OK, "OK", "Content-Type: text/html\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "<!DOCTYPE html>\r\n<html>\r\n<head>\r\n<title>X10 Server Info</title>\r\n"); + strcat_s(bigBuf, sizeof(bigBuf), "<!DOCTYPE html>\r\n<html>\r\n<head>\r\n<title>WattEye</title>\r\n"); strcat_s(bigBuf, sizeof(bigBuf), "<style>\n"); strcat_s(bigBuf, sizeof(bigBuf), "body {\n"); strcat_s(bigBuf, sizeof(bigBuf), " transform: scale(1.6);\n"); @@ -231,48 +155,11 @@ strcat_s(bigBuf, sizeof(bigBuf), "</style>\n"); strcat_s(bigBuf, sizeof(bigBuf), "</head>\r\n"); strcat_s(bigBuf, sizeof(bigBuf), "<body>\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "<h1>X10 Server Info</h1>\r\n"); + strcat_s(bigBuf, sizeof(bigBuf), "<h1>WattEye</h1>\r\n"); strcat_s(bigBuf, sizeof(bigBuf), "<blockquote>\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "<table border='1'>\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "<tr><th><h2>Command</h2></th></tr>\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "<tr><td>\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "<form method='get'>\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "<table border='0'><tr><th>House</th><th>Unit</th><th>Cmd</th><th> </th></tr>\r\n"); - // House code - strcat_s(bigBuf, sizeof(bigBuf), "<tr><td align='center'><select name='House'>\r\n"); - for (int i = 'A'; i <= 'P'; i++) { - snprintf(smallBuf, 100, "<option value='%c'>%c</option>\r\n", i, i); - strcat_s(bigBuf, sizeof(bigBuf), smallBuf); - } - strcat_s(bigBuf, sizeof(bigBuf), "</select></td>\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "<td><select name='Unit'>\r\n"); - for (int i = 1; i <= 16; i++) { - snprintf(smallBuf, 100, "<option value='%d'>%d</option>\r\n", i, i); - strcat_s(bigBuf, sizeof(bigBuf), smallBuf); - } - strcat_s(bigBuf, sizeof(bigBuf), "</select></td>\r\n"); - // Unit code - strcat_s(bigBuf, sizeof(bigBuf), "<td><select name='Cmd'>\r\n"); - for (int i = -6; i <= 7; i++) { - if (i < 0) - snprintf(smallBuf, 100, "<option value='%+d'>%+d</option>\r\n", i, i); - else if (i == 0) - snprintf(smallBuf, 100, "<option value='%d' selected>%d</option>\r\n", i, i); - else if (i == 1) - snprintf(smallBuf, 100, "<option value='%d'>%d</option>\r\n", i, i); - else // if (i > 1) - snprintf(smallBuf, 100, "<option value='%+d'>%+d</option>\r\n", i-1, i-1); - strcat_s(bigBuf, sizeof(bigBuf), smallBuf); - } - strcat_s(bigBuf, sizeof(bigBuf), "</select></td>\r\n"); - - strcat_s(bigBuf, sizeof(bigBuf), "<td><input type='Submit' value='Send'></td>\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "</tr></table>\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "</form>\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "</td></tr></table>\r\n"); strcat_s(bigBuf, sizeof(bigBuf), "<br/><br/><a href='/info'>info Page</a> | <a href='/setup.xml'>setup.xml</a>\r\n"); strcat_s(bigBuf, sizeof(bigBuf), "</blockquote>\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "X10 Server, Copyright © 2019 by Smartware Computing, all rights reserved."); + strcat_s(bigBuf, sizeof(bigBuf), "WattEye, Copyright © 2019 by Smartware Computing, all rights reserved."); strcat_s(bigBuf, sizeof(bigBuf), "</body></html>"); printf("bigBuf size is %d bytes\r\n", strlen(bigBuf)); svr->send(bigBuf); @@ -305,13 +192,13 @@ switch (type) { case HTTPServer::SEND_PAGE: svr->header(HTTPServer::OK, "OK", "Content-Type: text/html\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "<!DOCTYPE html>\r\n<html><head><title>X10 Server Info</title></head>\r\n"); + strcat_s(bigBuf, sizeof(bigBuf), "<!DOCTYPE html>\r\n<html><head><title>WattEye Info</title></head>\r\n"); strcat_s(bigBuf, sizeof(bigBuf), "<body>\r\n"); - strcat_s(bigBuf, sizeof(bigBuf), "<h1>X10 Server Info</h1>\r\n"); + strcat_s(bigBuf, sizeof(bigBuf), "<h1>WattEye Info</h1>\r\n"); strcat_s(bigBuf, sizeof(bigBuf), "<table border='1' width='100%'>\r\n"); strcat_s(bigBuf, sizeof(bigBuf), "<tr><th>Configuration</th><th>Software</th></tr>\r\n"); strcat_s(bigBuf, sizeof(bigBuf), "<tr><td valign='top' width='50%'><pre>\r\n"); - fh = fopen("/local/X10svr.ini", "rt"); + fh = fopen("/local/WattEye.ini", "rt"); if (fh) { char fileBuf[60]; while(fgets(fileBuf, sizeof(fileBuf), fh)) {