• My results are far from scientific. This exercise has involved a lot of trial-and-error, some shotgun approaches, finger-crossing, and several desperate prayers to Binarius, the Greek god of bits.

    But upon the very valid request to know which commands were causing the issue, I've pared the code down, and removed most of the delays, and got it reliably working. In my rigorous testing (by that I mean 6 times), I found that I only needed to delay starting the WiFi AP and Station a second after the SPI device.

    This makes the relevant code now look like this:

    function onInit() {
    
      SPI1.setup({mosi:A7, miso:A6, sck:A5});
      bme = require("BME280").connectSPI(SPI1, B1);
    
      setTimeout(startApAndStation, 1000);
    
      wifi.on('disconnected', () => {
        clearInterval(timer);
      });
    
      wifi.on('connected', () => {
        require("http").createServer(pageReq).listen(8080);
        mqtt = require("MQTT").connect({host: "xxx.xxx.xxx.xxx"});
        dataInterval();
      });
    }
    
    function startApAndStation() {
      wifi.startAP('AgilatechESP', { password: 'xxxxxxxx', authMode: 'wpa2' }, (err) => {
        if (err) throw err;
        else wifi.setAPIP({ip:"10.0.132.1", gw:"10.0.132.1", netmask:"255.255.255.0"}, (err) => {
          if (err) throw err;
          else wifi.connect("HeartJS", {password : "xxxxxxxxxx"}, (err) => {
            if (err) throw err;
          });
        });
      });
    }
    

    Why? I dunno, but without the delay on the 'startApAndStation' I get the Uncaught CWMODE failed: Timeout error nearly every time.

About

Avatar for ScottyMT @ScottyMT started