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

Revision:
4:5da66fab599c
Parent:
0:de1dfa2ab813
Child:
5:6244e237def1
--- a/main.cpp	Tue Jul 10 23:16:02 2018 +0000
+++ b/main.cpp	Fri Aug 31 22:51:15 2018 +0000
@@ -18,24 +18,44 @@
 Watchdog wd;
 time_t lastboottime;
 
+PwmOut signOfLife(LED4);        // LED sign of life. 100% WD reset, 20% restart, sine-wave: running
+
 //FlashFileSystem flash("flash");             // static files here for reliability and speed
 LocalFileSystem local("local");             // some place to hold settings and maybe the static web pages
-
 const char * Server_Root = "/local";
 
 // public for the WebPages handler to see
 //
 const char * BUILD_DATE = __DATE__ " " __TIME__;
 const char * PROG_NAME = "SSDP Server";
-const char * My_Name = "MBED SSDP Node";
+char * My_Name = "MBED SSDP Node";
 const char * My_SerialNum = "0000001";
-const int Server_Port = 80;
+int Server_Port = 80;
 // end public information
 
 
+
+
+/// ShowSignOfLife
+///
+/// Pulse an LED to indicate a sign of life of the program.
+/// This also has some moderate entertainment value.
+///
+void ShowSignOfLife(int degreeIncrement = 1)
+{
+#define PI 3.14159265359
+    static int degrees = 0;
+    float v;
+
+    degrees += degreeIncrement;
+    v = sin(degrees * PI / 180)/2 + 0.5;
+    signOfLife = v;     // a little dimmer
+}
+
 int main() {
     pc.baud(460800);
     pc.printf("\r\n%s Build %s\r\n", PROG_NAME, BUILD_DATE);
+    lastboottime = ntp.timelocal();
     if (wd.WatchdogCausedReset()) {
         pc.printf("**** Watchdog Event caused reset at %s ****\r\n", ntp.ctime(&lastboottime));
     }
@@ -48,11 +68,23 @@
     HTTPServer svr(Server_Port, Server_Root, 15, 30, 20, 50, &pc);
     svr.RegisterHandler("/", RootPage);
     svr.RegisterHandler("/setup.xml", Setup_xml);
-    SSDP ssdp("Friendly Node", eth.getMACAddress(), eth.getIPAddress(), Server_Port);
-    
+    SSDP ssdp(My_Name, eth.getMACAddress(), eth.getIPAddress(), Server_Port);
+
+    ntp.set_dst("3/11,2:00","11/4,2:00");   // mm/dd,hh:mm
+    ntp.set_tzo_min(-360);
+    int res = ntp.setTime("pool.ntp.org");
+
     while (1) {
         wd.Service();
         svr.Poll();         // non-blocking, but also not deterministic
         Thread::yield();
+        ShowSignOfLife(10);
+        static time_t tLast;
+        time_t tNow = ntp.timelocal();
+        if (tNow != tLast) {
+            printf("time is %s\r\n", ntp.ctime(&tNow));
+            tLast = tNow;
+        }
+        //printf("Mem: %5d, %5d %5d\n", Thread::used_stack(), Thread::max_stack(), Thread::stack_size());
     }
 }