[ERROR] Controlling Other Pucks

Posted on
Page
of 2
Prev
/ 2
  • Just a quick update on this. It's definitely a memory leak - I'll try and get a fix in soon.

  • Hi @Gordon,

    Yes this is the code of Device2 and Device 1 code can be seen above, which just switch on/off the led and counts the successful invocations.

    All this scenario is simulated because of a real use-case where Device2 have to invoke about 200 times a function on Device1 for a 2 hours and all the time I found Device2 reset and without any data.

    Thank you!

  • Ok, just fixed - turns out there were two issues:

    • A memory leak in NRF.connect - I guess most times people use requestDevice so it hadn't been spotted.
    • A memory leak when an exception is thrown inside a rejected promise.

    If you use one of the latest builds from http://www.espruino.com/binaries/travis/master/ then it should be fixed now.

    I'd modify the final bit of your code though to swap around the console.log and disconnect:

      // ...
        }).catch(function(e) {
          busy=false;      
          console.log("Write value error. ", e);
          if(gatt !== undefined)gatt.disconnect();
        });
    

    Disconnect can cause an error if the bluetooth operation had failed because the device got disconnected - so ideally you'd print the first error or disconnect will throw an exception which will stop the first error getting printed.

  • Hi @Gordon,

    The fix you provided is working fine, thank you!

    Anyway I have a situation where Device2 for some reason hangs, i.e. it cannot be accessed via bluetooth unless it is restarted. Is it possible to get the last exception or failure somehow ?

    Thank you!

  • On recent firmwares you can save any uncaught exceptions like this:

    >process.on('uncaughtException', function(e) { require("Storage").write("error",e); });
    =undefined
    >^*&^*&678^* &^*&
    >print(require("Storage").read("error"))
    {"message":"Got '^' expected EOF","type":"SyntaxError","stack":" at line 1 col 1\n^*&^*&678^* &^*&\n^\n"}
    

    Note that with the uncaughtException handler set, you no longer get exceptions reported to the console!

    However that's not ideal as it's possible you got a message that wasn't an exception... So you can do something like this:

    // Dump the data we had
    function showLog() {
      print("=========================");
      print(require("Storage").read("log"));
      print("=========================");
    }
    // When we get new data from the console, stick it into flash 
    LoopbackB.on('data',function(d) {
      var log = require("Storage").read("log");
      if (log) log+=d; else log=d;
      if (log.length>1000) log=log.substr(-1000);
      require("Storage").write("log",log);  
    });
    /* When we disconnect from Bluetooth, put the console
    onto loopback. It should automatically return next time
    we leave */
    NRF.on('disconnect', function(reason) { 
      LoopbackA.setConsole();
    });
    

    Although be careful with that as it'll write a lot of data to flash every time anything gets printed - so if you have a lot of print statements it'll be really slow and will wear out the flash memory.

    Finally your other option is just to attach wires to the second device: http://www.espruino.com/Puck.js#serial-console

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

[ERROR] Controlling Other Pucks

Posted by Avatar for goliatone @goliatone

Actions