David Smart / Mbed 2 deprecated SSDP_Server

Dependencies:   mbed mbed-rtos Watchdog SW_HTTPServer SW_String EthernetInterface TimeInterface SSDP

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Sun Jan 12 23:03:03 2020 +0000
Parent:
8:0b1efcef5e50
Commit message:
Minor changes for debug only.

Changed in this revision

SSDP.lib Show annotated file Show diff for this revision Revisions of this file
TimeInterface.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SSDP.lib	Sun Jan 12 03:51:53 2020 +0000
+++ b/SSDP.lib	Sun Jan 12 23:03:03 2020 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/WiredHome/code/SSDP/#b7f8070014d8
+https://os.mbed.com/users/WiredHome/code/SSDP/#f39e21b95f11
--- a/TimeInterface.lib	Sun Jan 12 03:51:53 2020 +0000
+++ b/TimeInterface.lib	Sun Jan 12 23:03:03 2020 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/WiredHome/code/TimeInterface/#9ee3fac64626
+http://mbed.org/users/WiredHome/code/TimeInterface/#3fa154ab6ffd
--- a/main.cpp	Sun Jan 12 03:51:53 2020 +0000
+++ b/main.cpp	Sun Jan 12 23:03:03 2020 +0000
@@ -30,7 +30,7 @@
 //
 const char * BUILD_DATE = __DATE__ " " __TIME__;
 const char * PROG_NAME = "SSDP Server";
-char * My_Name = "MBED SSDP Node";
+const char * My_Name = "MBED SSDP Node";
 const char * My_SerialNum = "0000001";
 int Server_Port = 80;
 // end public information
@@ -64,13 +64,17 @@
     wd.Configure(45);       // very generous, but this is a network appliance, so a bit less deterministic.
 
     int eRes = eth.init(); //Use DHCP
-    printf("eth.init() returned %d\r\n", eRes);
-    if (eRes < 0)
+    if (eRes < 0) {
+        printf("eth.init() returned %d, rebooting in 5 s.\r\n", eRes);
+        wait(5.0);
         mbed_reset();
+    }
     eRes = eth.connect();
-    printf("eth.connect() returned %d\r\n", eRes);
-    if (eRes < 0)
+    if (eRes < 0) {
+        printf("eth.connect() returned %d, rebooting in 5 s.\r\n", eRes);
+        wait(5.0);
         mbed_reset();
+    }
     printf("IP: %s\r\n", eth.getIPAddress());
     //Thread thr(SSDPListener, NULL, osPriorityLow);
     HTTPServer svr(Server_Port, Server_Root, 15, 30, 20, 50, &pc);
@@ -78,21 +82,29 @@
     svr.RegisterHandler("/setup.xml", Setup_xml);
     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");
+    bool setTheClock = true;    // prime it
 
     while (1) {
         wd.Service();
         svr.Poll();         // non-blocking, but also not deterministic
         Thread::yield();
         ShowSignOfLife(10);
+        if (setTheClock) {
+            setTheClock = false;
+            // Could read these from non-volatile
+            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");
+            if (res == 0) {
+                pc.printf("Time was just set\r\n");
+            }
+        }
         static time_t tLast;
         time_t tNow = ntp.timelocal();
         if (tNow != tLast) {
-            //printf("time is %s\r\n", ntp.ctime(&tNow));
+            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());
         }
-        //printf("Mem: %5d, %5d %5d\n", Thread::used_stack(), Thread::max_stack(), Thread::stack_size());
     }
 }