You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • 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-c­onsole

About

Avatar for Gordon @Gordon started