• Hi +Gordon,

    I am doing some tests on BLE UART using the ble_simple_uart module from the guide at http://www.espruino.com/Puck.js+BLE+UART­

    Using the guide, I am able to program a Puck to "forward" the commands sent from the PC (Web Bluetooth IDE) In this case, I am able to turn on the LED of a second Puck without prior programming on that Puck.

    The code that I am using is:

    NRF.requestDevice({ filters: [{ namePrefix: 'Puck.js' }] }).then(function(device) {
      require("ble_simple_uart").write(device,­ "digitalPulse(LED3,1,1000)\n", function() {
        print('Done!');
      });
    });
    

    However, I have some questions:

    1. When I upload the code I sometimes get the error Uncaught Error: Unhandled promise rejection: undefined, it seems to be pretty random as I am able to get it to work after reuploading the code a few times. Why does this happen? (My Pucks are on 1v88)
    2. When I try to send a Eddystone broadcast command using this method e.g. require("ble_eddystone").advertise("goo.­gl/B3J0Oc"); I am unable to detect the Eddystone broadcast using Beacon Tools app on my phone. Disconnecting and reconnecting the second Puck ends up with a Connection error. In the end I am forced to reset the second Puck by pulling out the battery. Is it possible that the UART connection will interfere with the Eddystone broadcast?
    3. Currently I am only testing on two Pucks, but is there an efficient way to make the code "recursive", such that if I add more Pucks and they are only in range of the second Puck, I can make the second Puck search for other Pucks nearby, then send the command again? I know that one way to do it is to put the whole code in the "commands to be sent field" i.e.

      
      NRF.requestDevice({ filters: [{ namePrefix: 'Puck.js' }] }).then(function(device) {
      require("ble_simple_uart").write(device,­
      "NRF.requestDevice({ filters: [{ namePrefix: 'Puck.js' }] }).then(function(device) {\n
        require('ble_simple_uart').write(device,­ 'digitalPulse(LED3,1,1000)\n', function() {\n
          print('Done!');\n
        });\n
      });\n", function() {
      print('Done!');
      });
      });
      
      

    But this will only make the command broadcast 2 times in total which does not help if the number of Pucks increase. It would be great if the command becomes recursive so that each Puck that receives the broadcast can turn on the LED + search for other Pucks nearby and send them the command. Does the Puck have some functions to do this?

    #4. What is the maximum command length that the require("ble_simple_uart").write() function supports?

    Thanks.

  • Looks like a nice idea!

    When I upload the code I sometimes get the error... Why does this happen? My Pucks are on 1v88

    Because your Pucks are on 1v88? Try 1v92! There are a huge amount of issues (including the lack of decent error messages) that have been fixed since the release.

    When I try to send a Eddystone broadcast command using this method e.g. require("ble_eddystone").advertise("goo.­gl/B3J0Oc"); I am unable to detect the Eddystone broadcast

    Puck.js won't advertise until you disconnect BLE from the device. I think it's a pretty standard BLE thing.

    Reconnection should still be possible while broadcasting Eddystone - I just tried it here. Best to try again when 1v92 is installed though as it might have been an issue with 1v88.

    is there an efficient way to ... make the second Puck search for other Pucks nearby

    There's nothing built in, but why not pre-load each Puck with a function that does the recursive send. For example if you can it exec then you can just send the command "exec(\"digitalPulse(LED3,1,1000)\\n\")\­n".

    You'd need to be a bit clever though - you don't want Puck A sending a command to Puck B, but Puck B then sending it back to Puck A. I guess you'd want a 'transaction ID' sent along with the command so Pucks knew to ignore a command if they'd seen it before.

    What is the maximum command length that the require("ble_simple_uart").write() function supports?

    There is no maximum length - it's just what will fit in RAM. The longer it is the longer it'll take to send though!

  • Thanks +Gordon for your replies. I will update the Puck tomorrow and hopefully it will fix the issues at the start.

    Also I was wondering where is the code that I uploaded stored in the Puck? Is it in the RAM or the flash memory?
    Cause I noticed that everything that I have uploaded seems to be lost once I take the battery out/do reset(). So does the Puck not retain any previous uploaded code once the power is lost/resetted?
    If I use the require("ble_simple_uart").write() function above to write new commands to another Puck, what happens to the code previously stored? (e.g. I declared an exec() function like you mentioned) Is it overwritten or appended to the end?

    Thanks for your help again :)

  • where is the code that I uploaded stored in the Puck?

    RAM, unless you type save() on the left-hand side, or choose save on send in the IDE.

    Cause I noticed that everything that I have uploaded seems to be lost once I take the battery out

    Yes, just type save() on the left-hand side and it'll resume in the same state at power on. Create a function called onInit() first if you want something to be called at boot.

    function ... Is it overwritten or appended to the end?

    If you send function foo() {...} it'll overwrite any existing function with that name, or will create a new function if one didn't exist. If you send normal commands like digitalPulse then they'll be executed and then forgotten.

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

Recursive BLE UART Broadcast? (Questions regarding Bluetooth "Mesh")

Posted by Avatar for intern @intern

Actions