The London Hackspace Bandwidth meter, now works over ethernet.

Dependencies:   EthernetInterface LPD8806 Tiny-HTTPD mbed-rtos mbed BonjourLib

Revision:
2:49025fae1e1f
Parent:
0:0e7057b49904
Child:
3:f4018fcd1ce8
--- a/main.cpp	Fri May 30 03:58:01 2014 +0000
+++ b/main.cpp	Fri May 30 09:07:48 2014 +0000
@@ -4,6 +4,9 @@
 #include "vfd.h"
 #include "LPD8806.h"
 #include "HTTPD.h"
+#include "mDNSResponder.h"
+#include "lwip/inet.h"
+#include "lwip/netif.h"
 
 DigitalOut myled(LED1);
 DigitalOut led2(LED2);
@@ -111,7 +114,20 @@
 
     "</body>"
     "</html>";
- 
+
+const char* const favicon = 
+"\x00\x00\x01\x00\x01\x00\x10\x10\x02\x00\x01\x00\x01\x00\xb0\x00\x00\x00"
+"\x16\x00\x00\x00(\x00\x00\x00\x10\x00\x00\x00 \x00\x00\x00\x01\x00\x01"
+"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\x00\xf0\xf0\x00"
+"\x00\xf0\xf0\x00\x00\xf0\xf0\x00\x00\xf0\xf0\x00\x00\x0f\x0f\x00\x00\x0f"
+"\x0f\x00\x00\x0f\x0f\x00\x00\x0f\x0f\x00\x00\xf0\xf0\x00\x00\xf0\xf0\x00"
+"\x00\xf0\xf0\x00\x00\xf0\xf0\x00\x00\x0f\x0f\x00\x00\x0f\x0f\x00\x00\x0f"
+"\x0f\x00\x00\x0f\x0f\x00\x00\xf0\x0f\x00\x00\xc0\x03\x00\x00\x80\x01\x00"
+"\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+"\x00\x80\x01\x00\x00\x80\x01\x00\x00\xc0\x03\x00\x00\xf0\x0f\x00\x00";
+
 const char* const text_plain = "Content-Type: text/plain\r\n";
 
 void callback_static (int id) {
@@ -122,6 +138,8 @@
  
     if (strcmp(buf, "") == 0 || strcmp(buf, "index.html") == 0) {
         httpd->send(id, index_page, strlen(index_page), "Content-Type: text/html\r\n");
+    } else if (strcmp(buf, "favicon.ico") == 0) {
+        httpd->send(id, favicon, 198, "image/vnd.microsoft.icon\r\n");
     } else {
         httpd->httpdError(id, 404);
     }
@@ -243,7 +261,24 @@
     logo();
 }
 
+mDNSResponder mdns;
+
+void mdns_thread(void const *args) {
+    ip_addr_t ip, *z;
+    z = (ip_addr_t *)args;
+
+    ip.addr = z->addr;
+
+    mdns.announce(ip, "net-o-meter", "_http._tcp", 80, "LHS Bandwidth Meter", 
+    (char *[]) {                // NULL terminated list of KV's = see
+            "path=/",         // http://www.zeroconf.org/Rendezvous/txtrecords.html
+            NULL
+        }
+    );
+}
+
 int main() {
+    ip_addr_t ip;
 
     led3 = 1;
     
@@ -265,6 +300,10 @@
     eth.connect();
     printf("IP Address is %s\n\r", eth.getIPAddress());
 
+    inet_aton(eth.getIPAddress(), &ip);
+    
+    Thread thread(mdns_thread, &ip);
+
     httpd = new HTTPD;
 
     led2 = 1;