Puck.js problem to save code

Posted on
of 2
/ 2
  • Hi at all!

    I am working on a project that uses the HID features on BLE. In particular, I want to send a character (volume up) each time a button is pressed. This is my code:

    var controls = require("ble_hid_controls");
    // Clean all previous watches
    NRF.setServices(undefined, {hid: controls.report});
    setWatch(function (ptt) {
      if (ptt.state) {
        NRF.sendHIDReport(32, () => {});
      } else {
        NRF.sendHIDReport(0, () => {});
    }, BTN, {edge: "both", debounce: 50, repeat: true});

    To save the program I follow this step:

    1. In Espruino Web IDE, configure the option Save on send - Direct to flash (execute code at boot).
    2. Upload the code.
    3. Disconnect from the PC
    4. Connect to device and work.

    But when I remove the battery and put it back on (without pressing BTN), the three LEDs start flashing at the same time and the program does not work and any device recognize it (PC or mobile) until I do a Hard reset.

    Can anyone tell me what it means to have the three LEDs blink at the same time?
    What can I do to save my program and not be deleted when I change the battery?

    Thank you very much in advance

  • What you're doing sounds fine, but...

    Have you updated your firmware at all? The 3 LEDs signifies an internal error, but as I recall that hasn't happened in firmwares for a year or more (it was usually to do with the secure bonding that HID devices often get asked to do)

  • Thanks @Gordon for answering so quickly.

    Yesterday I updated my Puck.js to the latest firmware version: 2v03.

    It seems to have to do with the process of bonding to the phone. I have tried with another phone and it works correctly.

    Is there any way to remove the previous bondings before executing the code?


  • And it still crashes even with 2v03?

    Try booting the Puck with the button held down - see http://www.espruino.com/Puck.js#hard-res­et - that should clear out any of the old bonding information that's in there. Perhaps somehow it got corrupted.

  • Also, maybe try to remove bonding/pairing info from your phone. At least windows goes stupid sometimes, maybe phones too.

  • Yes @Gordon, my Puck.js is currently running with version 2v03. It also happened with version 2v02.

    @AkosLukacs, the fault occurs even when the phone has been unbonded. With the unbonded phone, I remove the battery and when I put it back on, the 3 LEDS turn on at the same time ...

    The phone running Android 5.1


  • Did you do the proper hard reset on the Puck as described above? Just updating the firmware won't do it.

  • @Gordon Yes, I do the Hard-reset following the instructions.

    In fact, when the Puck.js is left with the 3 LEDs blinking the only way to reconnect it to the PC (or to any device) is by doing a Hard-Reset.


  • Wow, ok - so I believe it'll be something that particular phone is doing when connecting then. Which phone is it? Can you reproduce the issue with any other phone?

    Would you be able to connect a USB-TTL converter to the Puck that's having the problem as described in http://www.espruino.com/Puck.js#serial-c­onsole ?

    When it does the 3 lights thing it should then output an error message on Serial, and I can use that to try and track down where the error is coming from.

  • Hello @Gordon,

    I am testing with two devices. The first, is a Samsung Galaxy A5 (model 2015, Android 6.0) and with it, the Puck.js works perfectly.

    The second device is a particular device (Walkie-talkie) called TELO 580 built in Android 5.1. This is my production device and with itconnected, when the battery is removed, the error occurs.

    Yesterday I bought an USB-TTL converter and today, when it arrives, I will test the Puck.js and I write the result.

    Thanks for you dedication.

  • Hello @Gordon,

    I have received the USB-TTL converter and I have connected it to the Puck.js

    This is error:

    NRF ERROR 0x3202 at ?:0
    NRF ERROR 0x3202 at ?:0
    NRF ERROR 0x3202 at ?:0
    NRF ERROR 0x3202 at ?:0
    NRF ERROR 0x3202 at ?:0
    NRF ERROR 0x3202 at ?:0
    NRF ERROR 0x3202 at ?:0
    NRF ERROR 0x3202 at ?:0
    NRF ERROR 0x3202 at ?:0
    NRF ERROR 0x3202 at ?:0
    NRF ERROR 0x3202 at ?:0

    I hope you can help me,

  • Are you sure the code posted right at the beginning is the only code running on your device?

    That error corresponds to BLE_ERROR_GAP_INVALID_BLE_ADDR which is described as:

    The upper two bits of the address do not correspond to the specified address type.

    It seems possible that your TELO 580 is reporting itself with an invalid Bluetooth LE MAC address.

    Please could you tell me what the MAC address the nRF Connect app reports the TELO 580 as is?

  • Hi @Gordon,

    Are you sure the code posted right at the beginning is the only code running on your device?

    Yes, I'm sure. I have to do a hard-reset every time the code is loaded, I connect the TELO and the Puck.js is restarted.

    When a hard-reset has been performed, the code that shows me dump() is as follows:

    > dump()

    On the other hand, I have loaded the following code to see the MAC address of the TELO:

    devices = [];
    NRF.on('connect',function(addr) {

    After connecting twice, this is the result ("e4:b3:18:0b:a6:de public" is the MAC of my PC). The other MACs correspond to TELO. It seems that they are random values...


  • I think you may have forgotten to post the result? I don't see any MACs listed...

  • Hi @Gordon,

    Yes, you're right. The rush is not good... (Spanish expression: "Las prisas no son buenas"). Sorry...

    The result of the code above is as follows:

      "e4:b3:18:0b:a6:de public",  <-- PC
      "28:43:68:5e:7a:8a",               <-- TELO580
      "e4:b3:18:0b:a6:de public",  <-- PC
      "28:43:68:5e:7a:8a",               <-- TELO580
      "e4:b3:18:0b:a6:de public",  <-- PC
      "36:35:66:a1:6d:c9",               <--TELO580 (Bluetooth off and then on)
      "e4:b3:18:0b:a6:de public", <-- PC
      "12:ca:65:a3:45:24",               <--TELO580 (Bluetooth off and then on)

    When the TELO bluetooth is turned off and on again, the MAC changes, although none of them is the real one (real MAC of TELO: 7e:eb:46:03:35:1c).


  • There's definitely something a bit odd with the addresses your TELO device is advertising.

    Basically if it's advertising a public or random address, Espruino will say (like it says your PC is public). That means it's either private resolvable or non-resolvable.

    If you look at the answer here https://devzone.nordicsemi.com/f/nordic-­q-a/18877/i-want-to-change-the-ble-addre­ss you'll see the bottom two bits of the LSB in the address (the first one) have to be as in the spec.

    However the LSB of the MAC varies from 28,36,12 in the examples you give. In those cases the last two bits are 00, 10, 10 - so it seems that the device is coming up with a random address, which often happens to be wrong.

    I'm not sure what to suggest really - I'm pretty sure the error comes from Nordic's internal device libraries - so literally any Bluetooth device made by Nordic would have problems connecting to your device.

    You might be able to turn off the randomisation in your TELO device though? In that case you could stick with a standard BLE address that was ok.

  • Hi @Gordon,

    The TELO580 is not a device purchased directly from the factory and I'm not sure the manufacturer will personalize a firmware ...

    A question. Why does the first time connect correctly and the error only occurs when the Puck.js is restarted? Does not the MAC check the first time?


  • If it's Android I doubt you need to personalise the firmware - there may just be a setting somewhere to disable the feature.

    The Nordic libraries have some 'sanity checks' in them. Most likely when loading stored bonding data out of flash the address is checked - when it comes from Nordic's own 'binary blob' (eg direct from Bluetooth) it's not checked.

    It's difficult because this would appear to be something internal to Nordic's code so would require patching their code - I could produce a special binary for you that has full debug info for the error checks in I guess, and then we could see exactly where it got called from to be certain?

  • Hi @Gordon!

    For my part, there's no problem. If you give me a binary to load that gives us more information, I could load it and pass on the data you need.

    Thank you!

  • Hi - please can you try this one and see what it says?

    1 Attachment

  • Hi @Gordon!

    This morning (sorry for the delay!), I have loaded the firmware espruino_2v03.20_puckjs.zip into my Puck.js.

    Erasing saved code.
     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v03.20 (c) 2019 G.Williams

    This is the output with the new version:

    NRF ERROR 0x3202 at targets/nrf5x/bluetooth.c:1957
    NRF ERROR 0x3202 at targets/nrf5x/bluetooth.c:1957
    NRF ERROR 0x3202 at targets/nrf5x/bluetooth.c:1957

    I hope it works.

    Thanks for your support and the inconvenience

  • Thanks for trying it out! So, as expected the error comes from Nordic's internal libraries as I'd said above but the error gets returned as a return code so it's possible for me to handle the error without crashing the device.

    Please can you give the attached firmware a try and see if that solves your issues? It'll still mention the error (and it won't load the saved bonding info) but it shouldn't crash.

    1 Attachment

  • I have uploaded the firmware version in the Puck.js and it has worked!

    Effective, now when the TELO 580 is linked, when removing the battery to the Puck.js and put it back, it no longer gives the internal error (all the LEDs off) although the saved program does not load anymore I do not have to do a hard reset.

    For the Puck.js to work again, I just have to connect to the Web IDE and execute:

    load ();

    Is this firmware compatible with the MDBT42Q module? I have made the prototype with Puck.js but the final version is with the module.

    Thank you!

  • For the Puck.js to work again, I just have to connect to the Web IDE and execute load()

    Are you sure you didn't insert the battery while holding the button down or something like that?

    However it is possible that the error flagged up by the bluetooth stack stops execution of the JavaScript code - in which case I'll need to make a few more changes.

    Is this firmware compatible with the MDBT42Q module?

    That exact firmware isn't, but I made the changes for all boards, so any cutting edge build at http://www.espruino.com/binaries/travis/­master/ will have the changes in, as will 2v04 when it is released.

  • These are the results I have obtained with the new firmware (checked several times):

    With the TELO 580 paired, I remove the battery from the Puck-js until the bluetooth icon of the TELO 580 indicates that no device is connected. I wait about 10 seconds with the Puck-js battery removed. Then I put the battery back (Red LED lights once) but the program does not start.

    In some test, after a few seconds, the program has returned to work without doing anything. However, if I turn off the bluetooth of the TELO 580 and turn it on again, it automatically connects to the Puck.js and the program works again without having to execute the load () in the WebIDE.

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

Puck.js problem to save code

Posted by Avatar for migsanvi @migsanvi