• What is mDNS?
    It gives a name to your ESP8266 server that the Apple Bonjour browser add in can use to access your server.
    https://www.youtube.com/watch?v=G_gCfi3M­doU

    In this example code I named the server “bob”.
    I downloaded and installed Bonjour from this site and installed it on my Windows 7 system.
    http://download.cnet.com/Bonjour-for-Win­dows/3000-18507_4-93550.html
    On the IE browser command line I enter
    “bob.local”
    Or
    http://bob.local:8080/

    //MDNS_HTTPserver1.js
    //5 OCT 2016
    
    //espruino board with ESP8266
    //PICO  with ESP8266
    
    //var Hardware=0; //Espruino board
    var Hardware =1; //PICO
    
    var SSID="ssid";
    var key= "router passcode";
    
    var Serial;
    var Wifi;
    
    // "bob" is the server name
    // in IE browser with Bonjour installed
    //  bob.local
    //  http://bob.local:8080/
    
    var mDNS="AT+MDNS=1,\"bob\",\"http\",8080\r\­n";
    
    function mysend(a){
      Wifi.at.cmd(a, 1000, function(d){console.log(d+"xxx");});
    }
    
    //var ddata="";
    function test(){
    if(Hardware===1)Serial=Serial2;
    if(Hardware===0)Serial=Serial4;
    
    if(Hardware===1){
     digitalWrite(B9,1); // enable on Pico Shim V2
     Serial.setup(115200, { rx: A3, tx : A2 }); //Pico
    }
    if(Hardware===0)Serial.setup(115200, { rx: C11, tx : C10 }); 
    //espruino board
    
    console.log("Start connection process");
    var wifi = require("ESP8266WiFi_0v25").connect(Seri­al, function(err) {
      if (err)return 1;// throw err;
      Wifi=wifi;
    console.log("Reset the ESP8266");
      wifi.reset(function(err) {
        if (err)return 1;// throw err;
    Wifi.at.cmd("AT+CWMODE_CUR=3\r\n", 1000, function(d){console.log(d+"xx1");});
    Wifi.at.cmd("AT+CIPMUX=1\r\n", 1000, function(d){console.log(d+"xx2");});
     console.log("Connecting to WiFi");
     wifi.connect(SSID,key, function(err) {
      if (err)return 1;//throw err;
      wifi.getIP(function(l,ip){
       console.log("IP= ",ip,"\n\r");
       console.log("WiFi Connected ");
       mysend(mDNS);
    
    //HTTP or Network Server goes here
    serveHTML();
    ////////////////////////////////////////­////////////////////
         });//end wifi.getIP
        });//end wifi.connectSSID
      });//end wifi.reset
    });//end wifi.connect
    }//end test
    
    
    function serveHTML(){
    var http=require("http").createServer(onPage­Request).listen(8080);
    }//end serveFile
    
    
    function onPageRequest(req, res) { 
    //console.log("Req= ",req);
    //console.log("Header",req.headers);
    if (req.method=="POST") {
      console.log("Post");
      doPost(req,res);
    }else{
      doGet(req,res);
    }//endif
    }//end on PageRequest
    
    var pdata="";
    function doPost(req,res){
    //todo
    }//end doPost
    
    
    //Simple Web Page
    var KMtext="<html><body style=\"text-align:center;margin-left:au­to;margin-right:auto;\"> \r\n<h1>mDNS Demo. bob</h1>\r\n</body> \r\n</html>  \r\n";
    
    function doGet(req,res){
      var a = url.parse(req.url, true);
      console.log("Get");
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.write(KMtext);
        res.end("");
    }
    
    var x;
    console.log("Start");
    x=test();
    if(x!==0)console.log("Try again");//error seen
    
    if(x===0) console.log("Exit Seen");
    
    
    >echo(0);
    Start
    Start connection process
    Try again
    =undefined
    Reset the ESP8266
    Connecting to WiFi
    OKxx1
    OKxx2
    IP=  192.168.1.3
    WiFi Connected
    OKxxx
    Get
    >
    

    https://en.wikipedia.org/wiki/Multicast_­DNS
    Problems with older ESP8266 SDKs
    http://internetofhomethings.com/homethin­gs/?p=426

    Update: The issues I had with the ESP8266 SDK Version 1.0 have been fixed with the Version 1.0.1 release dated 24 April 2015. And now, Version 1.1.1 has been released with even more enhancements.


    1 Attachment

About