• @Gordon

    var   client = require("MQTT").create('IP ADDRESS', options /*optional*/);
    ....
    function setup () {
             wifi = require("ESP8266WiFi_0v25").connect(Seri­al2, function(err) {
    
            // reset the n/w before the connection
            wifi.reset(function(err) {
                throwError(err);
                // SSID, Access Point PWD, Email id, Token Details, Session Token
                var apSSID = typeof f.read(0) !== 'undefined' ? E.toString(f.read(0)) : '',
                    apPWD = typeof f.read(1) !== 'undefined' ? E.toString(f.read(1)) : '';
            
                if (apSSID) {
                    wifi.connect(apSSID, apPWD, function(err) {
                        console.log('Device is successfully connected to the WiFi.');
    
                        // MQTT starts here
                        client.connect();
                        ....
               } else {
                        // creating the AP, running the HTTP server code
                        // after getting the WiFi creds and saving that to the ROM, 
                        apServer.close();
                        setup();
               }
    }
    

    If you notice, whenever there is a cold start, i instantiate the ESP8266WiFi_0v25 twice in the flow and that is the case where it does not work.

    Every time after the cold start, it instantiates the ESP8266WiFi_0v25 once and it works fine.
    Does it give any clue?
    Does it need to do anything with the AP or Station mode of the Wifi module?

About

Avatar for sureshkm @sureshkm started