• Hi @Gordon and others,
    I've used Espruino Pico with ESP8266 on it. My device is trying to connect to the internet the similar way that the Amazon Echo or Google Home connects.

    I collect the WiFi credentials using a web form that is served from the HTTP server that runs on Espruino Pico,

    apServer = require("http").createServer(hsRouter).l­isten(80);
    

    After collecting the WiFi credentials and storing them in the ROM, i close the server, connect to the internet and then finally connect to my MQTT broker that runs on Digital Ocean.

    var client = require("MQTT").create(server, options /*optional*/);
    ....  // some code
    apServer.close()
    ....  // some code
    client.connect();
    
    

    I get the error message from MQTT client saying that the connection is closed.

    in function called from system
    Uncaught Error: This socket is closed.
     at line 1 col 56
    ...ite(b(a.DISCONNECT<<4)+'\0'),this.cli­ent.end(),this.client=!...
                                  ^
    in function "disconnect" called from line 1 col 52
    c.ctimo=void 0,c.emit('disconnected'),c.disconnect();­
                                                       ^
    

    But the MQTT broker is running fine and i get to see that MQTT client could reach the broker server. Instead of MQTT client call, if i make the following call, it works,

    require("http").get("http://pur3.co.uk/h­ello.txt", function(res) {
      res.on('data', function(data) {
        console.log("HTTP> "+data);
      });
      res.on('close', function(data) {
        console.log("Connection closed");
      });
    });
    

    I believe that there is something happening only after i run the HTTP server and close. Because if i retrieve the WiFi credentials from the memory instead of running the HTTP server and I'm able to connect to the MQTT broker successfully.

    Please help me.. thanks.

About

Avatar for sureshkm @sureshkm started