mDNS is working with Bonjour

Posted on
  • 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

  • Oh wow, nice - so there's an AT+MDNS command? Is that in the standard 0.40 firmware?

    That could be rolled into the existing AT command drivers for Espruino really easily.

    1. AT+MDNS – Set MDNS function
      ESP8266 softAP mode can not support MDNS. Do not contain special characters (for example, "."
      character), or use a protocol name (for example, "http"), when defining "host_name" and
      "server_name" for MDNS.
      AT+WPS – Set WPS function
      Example
      AT+CWMODE=1
      AT+WPS=1
      Command AT+WPS=
      Response OK or ERROR
      Parameter

      1 : start WPS function
      0 : stop WPS function
      AT+MDNS – Set MDNS function
      Example AT+MDNS=1, "espressif", "iot", 8080
      Command AT+MDNS=, , ,
      Response OK or ERROR
      Parameter

      1 : enable MDNS function
      0 : disable MDNS function
      MDNS host name
      MDNS server name
      MDNS server port

    http://bbs.espressif.com/viewtopic.php?t­=1714
    https://cdn.sparkfun.com/assets/learn_tu­torials/4/0/3/4A-ESP8266AT_Instruction_SetEN_v0.30.pdf
    https://espressif.com/en/support/downloa­d/sdks-demos
    https://espressif.com/en/support/downloa­d/overview?keys=&field_type_tid%5B%5D=14­
    http://bbs.espressif.com/

  • Using AT+GMR my ESP8266 reports the following:

    AT version:0.60.0.0(Jan 29 2016 15:10:17)
    SDK version:1.5.2(7eee54f4)

  • Ahh, nice! Looks like an addition in 0.60.

    Shame, as the Espruino WiFi boards currently ship with 0.40, and while it's possible to update firmware, it's a bit of a pain.

  • Latest AT document 2.0
    https://espressif.com/sites/default/file­s/documentation/4a-esp8266_at_instructio­n_set_en.pdf

    37. AT+MDNS – Set MDNS function
    ESP8266 softAP mode cannot support MDNS. Please do not use special characters (for example, "."
    character), or use a protocol name (for example, "http"), when defining "host_name" and
    "server_name" for MDNS.
    AT+WPS – Set WPS function
    Example
    AT+CWMODE=1
    AT+WPS=1
    Command AT+WPS=<enable>
    Response OK
    Parameter
    <enable>
    1 : start WPS function
    0 : stop WPS function
    AT+MDNS – Set MDNS function
    Example AT+MDNS=1, "espressif", "iot", 8080
    Command AT+MDNS=<enable>, <hostname>, <server_name>, <server_port>
    Response OK
    Parameter
    <enable>
    1 : enable MDNS function
    0 : disable MDNS function
    <hostname> MDNS host name
    <server_name> MDNS server name
    <server_port> MDNS server port
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

mDNS is working with Bonjour

Posted by Avatar for ClearMemory041063 @ClearMemory041063

Actions