Can't enter bootloader, plus other mysteries

Posted on
  • I'm working with an Espruino WiFi.

    The board seems be working correctly when I run code in the left panel.

    However, require('EspruinoWiFi') throws

    ERROR: SD card must be setup with E.connectSDCard first
    WARNING: Module "EspruinoWiFi" not found
    

    And same result with MQTT. So I try to clear flash.

    >reset()
    =undefined
    >save()
    =undefined
    Erasing Flash...
    Writing.......
    Compressed 114368 bytes to 4278
    Checking...
    Done!
    ERROR: SD card must be setup with E.connectSDCard first
    WARNING: Module "MQTT" not found
    ERROR: SD card must be setup with E.connectSDCard first
    WARNING: Module "EspruinoWiFi" not found
    Uncaught Error: Field or method "create" does not already exist, and can't create it on undefined
     at line 11 col 18
    var client = mqtt.create(MQTT_HOST);
    

    The last line, var client = mqtt.create(MQTT_HOST); is some code from my project. I'm not able to clear it from flash.

    Also tried E.setBootCode(), then save, same result. Also tried E.setBootCode(), reset, save, still no luck.

    Decided to try a fresh update. Holding down BTN1, plug in power, see yellow LED for 2s, see red LED flash, then no LED's lit. Can't get into bootloader mode it seems. Also not finding documentation for yellow LED.

  • I think I fixed it!

    Reading other threads, learned about dump().

    >dump()
    // Code saved with E.setBootCode
    var WIFI_NAME = "XXXXXX";
    var WIFI_PASS = "XXXXXX";
    var MQTT_HOST = "192.168.1.145";
    if (typeof __non_webpack_require__ == 'undefined') {
      var __non_webpack_require__ = require;
    }
    var mqtt = __non_webpack_require__("MQTT");
    var wifi = __non_webpack_require__("EspruinoWiFi");
    var client = mqtt.create(MQTT_HOST);
    client.on('connected', function() {
      client.subscribe("root/branch");
    });
    client.on('publish', function(pub) {
      console.log("topic: "+pub.topic);
      console.log("message: "+pub.message);
    });
    wifi.connect(WIFI_NAME, { password: WIFI_PASS }, function(err) {
      if (err) {
        console.log("Connection error: "+err);
        return;
      }
      console.log("Connected!");
      client.connect();
    });
    =undefined
    

    That's my project code! And a clue! // Code saved with E.setBootCode.

    Let's try this then...

    >E.setBootCode('')
    Erasing Flash...
    Writing...
    Compressed 114368 bytes to 8
    Checking...
    Done!
    =undefined
    >dump()
    =undefined
    > 
    

    Hooray! Right?

    >var wifi = require('EspruinoWiFi')
    ERROR: SD card must be setup with E.connectSDCard first
    WARNING: Module "EspruinoWiFi" not found
    =undefined
    >
    

    fml

  • Ooohhhhhh, it works. I understand now.

    Instead of typing require("EspruinoWiFi") in the left pane, it has to go in the right pane:

    var wifi = require("EspruinoWiFi");
    

    Press Send to Espruino

    dump() // left pane
    var wifi = {
      "connect": function (a,b,c) {var f="";void 0!==b.password&&(f=b.password);m(1,function(b){if(b)return c(b);d.cmd("AT+CWJAP="+JSON.stringify(a)+","+JSON.stringify(f)+"\r\n",2E4,function x(a){if(0<=["WIFI DISCONNECT","WIFI CONNECTED","WIFI GOT IP","+CWJAP:1"].indexOf(a))return x;"OK"!=a?setTimeout(c,0,"WiFi connect failed: "+(a?a:"Timeout")):setTimeout(c,0,null)})})},
      "disconnect": function () {r(1)},
      "getIP": function (a) {var b={};d.cmd("AT+CIFSR\r\n",1E3,function f(d){if(void 0===d)a("Timeout");else{if("+CIFSR:STAIP"==d.substr(0,12))b.ip=d.slice(14,-1);else if("+CIFSR:STAMAC"==d.substr(0,13))b.mac=d.slice(15,-1);else if("OK"==d){a(null,b);return}return f}})},
      "startAP": function (a,b,c) {
      b=b||{};if(!b.password||8>b.password.length)throw Error("Password must be at least 8 characters");var f=b.password?"3":"0";if(b.authMode&&(f={open:0,wpa:2,wpa2:3,wpa_wpa2:4}[b.authMode],void 0===f))throw Error("Unknown authMode "+
    b.authMode);void 0===b.channel&&(b.channel=5);m(2,function(e){if(e)return c(e);d.cmd("AT+CWSAP="+JSON.stringify(a)+","+JSON.stringify(b.password)+","+b.channel+","+f+"\r\n",5E3,function(a){"OK"!=a?c("CWSAP failed: "+(a?a:"Timeout")):c(null)})})
    },
      "stopAP": function () {r(2)},
      "scan": function (a) {
      var b=[];m(1,function(c){if(c)return a(c);d.cmdReg("AT+CWLAP\r\n",5E3,"+CWLAP:",function(a){a=a.slice(8,-1).split(",");b.push({ssid:JSON.parse(a[1]),authMode:w[a[0]],rssi:parseInt(a[2]),mac:JSON.parse(a[3]),
    channel:JSON.parse(a[4])})},function(c){a(null,b)})})
    }
     };
    =undefined
    

    So if I upload code that isn't messed up (trying to support __non_webpack_require__ causes issues) I think this will work once again.

    Getting into bootloader probably not working still :(

  • To get into the bootloader you just power the board up with the button held down - does that not work?

    For modules that have to be loaded off the internet you have to use the right-hand side of the IDE so the IDE can detect their use and load them automatically. The left-hand side goes direct to the Espruino Board, so if it doesn't know about a module it's unable to load it.

    It'd be worth going through the quick start and a few of the Espruino Pico tutorials - I think a lot of this stuff is covered already there - it might save you some time :)

  • To get into the bootloader you just power the board up with the button held down - does that not work?

    It does not appear to be working. What does the yellow LED mean?

    For modules that have to be loaded off the internet you have to use the right-hand side of the IDE so the IDE can detect their use and load them automatically. The left-hand side goes direct to the Espruino Board, so if it doesn't know about a module it's unable to load it.

    Ya, see how it works now.

    It'd be worth going through the quick start and a few of the Espruino Pico tutorials - I think a lot of this stuff is covered already there - it might save you some time :)

    I did when I got my first board. I saw the section about save and onInit at the time, but I didn't try it out, and I forgot those features existed. I don't learn well by reading, I learn by doing, which is apparently uncommon among developers. FWIW, the Lodash project documentation is really easy to work with. Would be super if Espruino could have similar documentation at some point in the future.

  • What does the yellow LED mean?

    There is no yellow LED? If both red and green LEDs are on it's in bootloader mode, but hasn't got an active connection to USB (they pulse when it's connected).

    If that's the case it could be the USB cable, or maybe a driver issue on your PC? If you try it on another computer it'll probably work fine.

    lodash

    Like this? https://lodash.com/docs#now

    Espruino has this - which apart from some CSS is pretty similar: http://www.espruino.com/Reference

    I've been trying to add more examples (and eventually I'll add an index down the left-hand side) - but it's not that bad. There's just a lot of it.

  • My bad. I've used that before, I think it's quite good, and I see these functions are there too. I'm really sleep deprived, that will be my excuse. Sorry for being a nuisance :). Thanks as always.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Can't enter bootloader, plus other mysteries

Posted by Avatar for CriscoCrusader @CriscoCrusader

Actions