You are reading a single comment by @parasquid and its replies. Click here to read the full conversation.
  • Sure, here it is 😊:

    // ************************************************************
    // *** IMPORTS
    // ************************************************************
    const wifi = require("Wifi");
    
    wifi.enableMDNS = function (hostname, serviceType, port, callback) {
        let mdns = "AT+MDNS=1," + JSON.stringify(hostname) + "," + JSON.stringify(serviceType) + "," + JSON.stringify(port) + "\r\n";
        this.at.cmd(mdns, 500, function (d) {
            callback(d);
        });
    };
    
    // ************************************************************
    // *** MAIN
    // ************************************************************
    
    /*
     * Called on boot
     */
    function onInit() {
    
        wifi.startAP("EspruinoAP", { password: "0123456789", authMode: "wpa2" }, function (err) {
            if (err) throw err;
    
            console.log("AP created!");
            wifi.enableMDNS("abcd", "iot", 80, function (result) {
                console.log("enableMDNS result: " + result);
            });
    
        });
    
    }
    
    

    That was my guess as well, but replacing this with wifi gives me exactly the same error 🤔.

    ```
    2v06 (c) 2019 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate

    WARNING: Scan stop failed
    WARNING: set rssi scan not implemeted yet
    Running onInit()...
    AP created!
    Uncaught Error: Cannot read property 'cmd' of undefined
    at line 2 col 12

    wifi.at.cmd(mdns, 500, function (d) {
           ^
    

    in function "enableMDNS" called from line 6 col 10

        });
         ^
    

    in function called from system```

  • In the original post:

    console.log("Start connection process");
    var wifi = require("ESP8266WiFi_0v25").connect(Serial, function(err) {
      if (err)return 1;// throw err;
      Wifi=wifi;
    

    Wifi is set to the result of the connect() function. In your case, wifi is set to the actual library.

  • Ah, I see 🙂. I used the access point feature only, so never really had to call connect, I updated the example, still getting the same error I'm afraid 🤔.

    // ************************************************************
    // *** IMPORTS / CONSTANTS
    // ************************************************************
    const ssid = "<ACCESS_POINT_SSID>";
    const password = "<PASSWORD>";
    
    const wifi = require("Wifi");
    let Wifi;
    
    wifi.enableMDNS = function (hostname, serviceType, port, callback) {   // <-- Also tried fat-arrow syntax
        let mdns = "AT+MDNS=1," + JSON.stringify(hostname) + "," + JSON.stringify(serviceType) + "," + JSON.stringify(port) + "\r\n";
        Wifi.at.cmd(mdns, 500, function (d) {
            callback(d);
        });
    };
    
    // ************************************************************
    // *** MAIN
    // ************************************************************
    
    /*
     * Called on boot
     */
    function onInit() {
    
        const w = wifi.connect(ssid, { password: password }, function () {
            console.log("Connected");
            Wifi = w;
            
            wifi.enableMDNS("abcd", "iot", 80, function (result) {
                console.log("enableMDNS result: " + result);
            });
        });
    
    }
    
About

Avatar for parasquid @parasquid started