• Hi Ollie,
    thanks for your reply. So this is my new code:

    var http = require('http');
    var wifi = require('Wifi');
    var mqtt = require("tinyMQTT").create("............­.",{username:"owntracks",password:".....­.........",port:1883});
    
    var server = function(ssid, password){
          wifi.connect("Newbiz",{password: "pwdinewbiz"}, function(err) {
                  if (err) throw err;
                  wifi.save();
    
                  console.log(wifi.getIP());
    
                  console.log(wifi.getDetails());
    
                  wifi.startAP("NewbizCentral",{authMode:"­wpa", password:"pwdinewbiz",channel:5},functio­n(a){console.log("AP created");});
    
                  setTimeout(function(){      
                    console.log(wifi.getAPIP());
                    http.createServer(
    
                      function (req, res) {
                                var a = url.parse(req.url, true);
                                if(req.url.length>15){
                                  var wifiSetterPageContent = "<h3>Credendiali AP settate. Staccare dalla presa il dispositivo e riattaccarlo dopo qualche secondo<h3>";
                                  res.writeHead(200, {'Content-Type': 'text/html'});
                                  res.end(wifiSetterPageContent);
                                  var pressid = req.url.replace("/setWifiCredentials/?",­ "");
                                  var UsrPwd = pressid.split("&");
                                  ssid = UsrPwd[0];
                                  password = UsrPwd[1];
                                  console.log("from onPageRequest " + ssid + " " + password);
                                  message =  message + " ssid is: "+ssid + " password is: "+ password;
                                  connectWifi(ssid, password);
                                }
                                else{
                                  var pageContent = "<h1>Newbiz s.r.l.<h1><h2>Seleziona le credenziali del tuo Access Point<h2><p>Nome Wifi</p> <input type='text' name='wifiid' id='wifiid'> <p>Password</p> <input type='text' name='passwd' id='passwd'></br></br> <button onclick='setWifiCredentials()'>Setta le credenziali e riavvia</button> <script> function setWifiCredentials(){location.href = '../setWifiCredentials/?'+document.getEl­ementById('wifiid').value+'&'+document.g­etElementById('passwd').value;} </script>";
                                  res.writeHead(200, {'Content-Type': 'text/html'});
                                  res.end(pageContent);
                                }
                      }
    
                    ).listen(8080);
    
                    setTimeout(function(){
                        var message = JSON.stringify(wifi.getIP()) + JSON.stringify(wifi.getDHCPHostname()) + JSON.stringify(wifi.getHostname());
                        mqtt.on("connected", function(){
                          mqtt.subscribe("owntracks");
                          var topic = "owntracks";
                          mqtt.publish(topic, message);
                        });
    
                        mqtt.on("message", function(msg){
                          console.log(msg.topic);
                          console.log(msg.message);
                        });
    
                        mqtt.on("published", function(){
                          console.log("message sent");
                        });
    
                        mqtt.on("disconnected", function(){
                          console.log("disconnected");
                        });
    
                        mqtt.connect();
                    }, 5000);
    
                  },5000);
          });
    };
    
    E.on("init", server);
    
    
    

    everything is perfectly working before saving...
    This is the correct and expected reponse:

    { "ip": "192.168.1.54", "netmask": "255.255.255.0", "gw":
    "192.168.1.1", "mac": "5c:cf:7f:19:e0:c7" } { "status":
    "connected", "ssid": "Newbiz", "password": "pwdinewbiz", "rssi":
    -71, "savedSsid": null } AP created { "ip": "192.168.4.1", "netmask": "255.255.255.0", "gw": "192.168.4.1", "mac":
    "5e:cf:7f:19:e0:c7" } message sent

    as soon as i save() on the console, unplug and replug usb i see this in the console:

    { "ip": "192.168.1.54", "netmask": "255.255.255.0", "gw":
    "192.168.1.1", "mac": "5c:cf:7f:19:e0:c7" } { "status":
    "connected", "ssid": "Newbiz", "password": "pwdinewbiz", "rssi":
    -71, "savedSsid": null } AP created { "ip": "192.168.4.1", "netmask": "255.255.255.0", "gw": "192.168.4.1", "mac":
    "5e:cf:7f:19:e0:c7" }

    You can notice that everything is working but not the last "message sent".
    The other strange thing that happends is that while you would think that message has not been sent(and usually on another mqtt client when message is published the client get immediately updated) if from another mqtt client i unsubscribe and subscribe again i get that message there.

    so qhat can it be??!!

About