• I'm not 100% sure but I think it's possible that you may be getting two WiFi 'connected' events from the two different WiFi connections. In that case what'd be happening is the EspruinoWiFi would be not only trying to create an HTTP server on the same port twice, but the first time it'd be doing it at the same time as connecting to a WiFi access point.

    Do you think you could try this instead of your existing onInit and see if it helps? I added a few extra delays - they may not all be required but I guess it's possible they would help.

    The main thing though was removing the 'connected' handler and just calling it manually after the second connection was made.

    function connectMQTT() {
      require("http").createServer(pageReq).li­sten(8080);
      setTimeout(function() {
        mqtt = require("MQTT").connect({
          host: "xxx.xxx.xxx.xxx"
        });
        loadData();
        dataInterval();
      }, 2000);
    }
    
    function onInit() {
      SPI1.setup({mosi:A7, miso:A6, sck:A5});
      bme = require("BME280").connectSPI(SPI1, B1);
      
      setTimeout(function() {
        // After 2 seconds, connect
        wifi.startAP('AgilatechESP', { password: 'xxxxxxxx', authMode: 'wpa2' }, (err) => {
          if (err) throw err;
          else wifi.connect("HeartJS", {password : "xxxxxxxxxx"}, (err) => {
            if (err) throw err;
              connectMQTT();
          });
        });
      }, 2000);
    }
    

    While it might make some sense to do stuff on the 'connected' handler (for instance if WiFi dropped out and then reconnected) you'd need to make sure you handle it properly. Right now you'd end up creating a new interval with dataInterval each time you reconnected without properly removing the old one first.

    Hope that's some help!

About

Avatar for Gordon @Gordon started