Set Bluetooth name via Service

Posted on
  • I'm looking for a method of changing the bluetooth interfaces name in a way that persists through power cycling without modifying onInit() or setBootCode()
    I have already used

    NRF.setAdveritising({},{name: "<name>"});
    

    however it does not persist through power cycling and whilst I have found a way to make that happen using the following code:

    E.setBootCode('NRF.setAdvertising({},{na­me: "<name>"});',true);
    

    It is still removable with reset(true).

    I can't use any methods that write to the onInit() function or E.init() handler as existing data there would be erased, so my question was whether writing to the 0X2A00 service (that defines the name), can be done at a lower level either via a puck, the web IDE, or a raspberry pi using the bluepy library.

  • 'E.setBootCode' underpins the Espruino save on send functionality from the IDE, and that has an option to persist/run after reset. I guess there's an argument you can pass, but if not maybe you can use the IDE.

  • The option is called alwaysExec, see http://www.espruino.com/Reference#l_E_se­tBootCode

  • Ah thanks, so in that case, that won't help. Looks like OP is passing true for alwaysExec already. So @user87803 it looks like it will persist beyond reset() but not reset(true) which is going to empty the flash.

  • isn't there a way to set the name characteristic using lower level code?
    I've experimented with python bluepy for the raspberry pi zero w that appears to read and write the 0x2A00 name characteristic, but does not actually write.
    Is there an espruino equivalent?
    I have tried

    NRF.setAdvertising({0x2A00: "<Puck>"},{});
    

    but that doesn't work either (despite the fact that it should if the puck conforms to bluetooth specifications.

  • I'm not quite sure I understand the question... If you do E.setBootCode('NRF.setAdvertising({},{na­me: "<name>"});',true); then the name change will persist through power cycling and calling reset().

    The only thing it won't persist through is reset(true) because that erases everything you wrote to the device.

    If you want it to persist through completely erasing the device's memory then you have 2 options:

    • Build your own firmware with the name changed
    • Replace reset so the user can't fully reset the device's memory:

    (function() {
      var r = reset;
      global.reset=function(){reset()};
    });
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Set Bluetooth name via Service

Posted by Avatar for user87803 @user87803

Actions