SSDP Server - working version provides SSDP based network discovery, and with a companion web server, may provide other functionalities.
Dependents: X10Svr SSDP_Server
Diff: SSDP.cpp
- Revision:
- 8:e8f0dc2b78c4
- Parent:
- 7:1e8c677e3d28
- Child:
- 9:9b46a499de53
diff -r 1e8c677e3d28 -r e8f0dc2b78c4 SSDP.cpp --- a/SSDP.cpp Mon Nov 19 01:16:59 2018 +0000 +++ b/SSDP.cpp Tue Feb 26 22:48:40 2019 +0000 @@ -8,7 +8,7 @@ #include "EthernetInterface.h" #include "SW_String.h" -#define DEBUG "SSDP" //Debug is disabled by default +//#define DEBUG "SSDP" //Debug is disabled by default #include <cstdio> #if (defined(DEBUG) && !defined(TARGET_LPC11U24)) @@ -22,7 +22,6 @@ #define ERR(x, ...) #define INFO(x, ...) #endif -extern void ShowSignOfLife(int which); static const char* MCAST_GRP = "239.255.255.250"; static const int MCAST_PORT = 1900; static Thread * pThr; @@ -81,21 +80,21 @@ char buffer[256]; while (true) { //INFO("Wait for packet..."); - ShowSignOfLife(2); int n = server.receiveFrom(client, buffer, sizeof(buffer)-1); if (n > 0) { - char * p = buffer; volatile int delay = 0; uint8_t mask = 0x00; // fragments we found in the received packet buffer[n] = '\0'; - INFO("SSDP receiveFrom %d bytes from %s:%d", n, + INFO("SSDP <<<<<<< %d bytes from %s:%d <<<<<<<<<<<", n, client.get_address(), client.get_port()); INFO("SSDP\n%s", buffer); + char * p = buffer; while (*p) { char * e = strstr(p, "\r\n"); if (e && (e - buffer) < n) { *e = '\0'; + INFO("EVAL '%s'", p); if (sw_stristr(p, "M-SEARCH * HTTP/1.1")) { mask |= 0x01; // M-SEARCH * HTTP/1.1 } else if (sw_stristr(p, "MAN:") && sw_stristr(p,"\"ssdp:discover\"")) { @@ -114,6 +113,7 @@ pColon = '\0'; } } + INFO(" mask: %02X", mask); p = e + 1; } p++; @@ -126,11 +126,12 @@ sprintf(out_buffer, SSDP_HTTP, cfg->ipAddr, cfg->port, cfg->ident, cfg->ident); // It would be polite to delay, but the recommendation is from 1 to 2 seconds. // Send the response twice, to improve reliability of node discovery - for (int i=0; i<1; i++) { - INFO("SSDPListener: reply >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + //for (int i=0; i<1; i++) { + INFO("SSDPListener: reply >>>>>>> %s:%d >>>>>>>>>>>", client.get_address(), + client.get_port()); int i = server.sendTo(client, out_buffer, strlen(out_buffer)); INFO(" sendTo %3d: reply <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", i); - } + //} free(out_buffer); INFO("SSDPListener: stack-used: %d, total: %d", pThr->max_stack(), pThr->stack_size()); } else {