Controlling Access to Serial Service on NRF

Posted on
  • I'd like to secure the serial service so that it's only available to connect to within a minute or so of powering on Espruino. The idea is to secure the javascript if someone doesn't have access to power cycling the device or pressing a physical button. Is it possible to disable this service or possibly change the device to non-connectable after a minute of powering on?

  • you mean the bluetooth console? there are several ways, check
    Also I have somewhere a variant of code mentioned there that dynamically creates whitelist of allowed devices. You basically need to hold button first time you connect to allow connection from new device and adding to whitelist for next time otherwise it will refuse the connection. Will search for it and post it.

  • @fanoush thanks for the link. Lots of good options there, somehow missed that in the documentation. Will probably go with the changing the connectable option to false after a minute of pressing a button or powering up.

  • Here is snippet of code I use

    NRF.on('connect',function(addr) {
      if (!NRF.whitelist.includes(addr)){
        if ({ // add to whitelist when button is held while connecting
        } else
      NRF.connection = { addr: addr };
    NRF.on('disconnect',function(reason) {
      NRF.connection = {};
      NRF.lastReason=reason; // google BLE hci status codes

    It also vibrates on connection (my custom code) and maintains active connection with rssi value as extra NRF object properties, also on disconnect it keeps the reason. This code is not needed for this simple whitelisting and can be removed.

  • Thanks, this is great!

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

Controlling Access to Serial Service on NRF

Posted by Avatar for noahneibaron @noahneibaron