Bonjour/Zerconf library

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 #include "EthernetNetIf.h"
00004 #include "HTTPServer.h"
00005 
00006 // mDNS response to announce oneselve
00007 #include "services/mDNS/mDNSResponder.h"
00008 
00009 DigitalOut myled(LED1);
00010 EthernetNetIf eth;
00011 HTTPServer srv;
00012 mDNSResponder mdns; // make sure LWIP_IGMP is set in netCfg.h !
00013 
00014 int main() {
00015     EthernetErr ethErr = eth.setup();
00016     if (ethErr) {
00017         printf("Error %d in setup on DHCP.\r\n", ethErr);
00018         return -1;
00019     }
00020     srv.addHandler<SimpleHandler>("/"); // Something.
00021     srv.addHandler<SimpleHandler>("/sample"); // Something too
00022     srv.bind(80);
00023         
00024     IpAddr ip = eth.getIp();
00025     printf("mbed IP Address is %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]);
00026 
00027     // Announce above web server - and keep doing that every minute or so.
00028     //
00029     mdns.announce(
00030         ip,                         // (My) IP address - where announced service runs.
00031         "propername",               // DNS name server or service
00032         "_http._tcp",               // protocol
00033         80,                         // Port number
00034         "May the blood run free",   // User interface name service
00035         (char *[]) {                // NULL terminated list of KV's = see                                     // http://www.zeroconf.org/Rendezvous/txtrecords.html
00036             "path=/sample",         // http://www.zeroconf.org/Rendezvous/txtrecords.html
00037 //          "key2=someval", 
00038 //          "and=more",
00039             NULL
00040         }
00041     );
00042     
00043     // So that clicking on 'May the blood run free' will jump to:
00044     //
00045     //   http://propername.local.:80/sample (or http://propername/sample in the bar)
00046 
00047     printf("Entering while loop Net::poll()ing\r\n");
00048     while (1) {
00049         Net::poll();
00050     }
00051 }