NRF.setAdvertising 'name' and 'iBeacon'

Posted on
  • var ibeacon = require("ble_ibeacon");
    var uuid = "2F3E43C7-8400-44B5-B385-1E6BB411A3BE";
    
    function uuidStringToArray(uuid) {
      uuid = uuid.replace(/-/g, ""); // remove dashes
      let uuidArray = [];
      for (let i = 0; i < uuid.length; i += 2) {
        uuidArray.push(parseInt(uuid.substring(i, i + 2), 16));
      }
      return uuidArray;
    }
    
    NRF.setAdvertising([
      ibeacon.get({
        uuid : uuidStringToArray(uuid),
        major : 2,
        minor : 1,
        rssi : -59
      }),
      {name: "PuckHub"}
    ], {interval:200});
    
    

    I'm having trouble advertising a custom name and iBeacon information on my puck.js. do you have any suggestions for me? the iBeacon information works but the name does not change...

  • It's a bit counter-intuitive, but you need the name in the second argument, so:

    NRF.setAdvertising([
      ibeacon.get({
        uuid : uuidStringToArray(uuid),
        major : 2,
        minor : 1,
        rssi : -59
      }),
      {}
    ], {interval:200,name: "PuckHub"});
    
  • Thank you!

  • Excuse me for waking this up ... I would like to name my Puck, but this doesn't seem to work:

    NRF.setAdvertising(adv, {interval:2000,name:"Bunny",showName:true});
    

    What's wrong with it?
    "adv" is an array of values similar to the one used by OpenHaystack.

  • Ah, I see it sometimes takes very long for scanning apps to recognise the change of the name. The IDE is fastest mostly. Even when I restart Puck (battery out). Is that an issue of the scanning app (device) or am I missing something?

  • When you specify an array of numbers to advertise, that's the actual data that gets sent out, so even though you set the name it won't show.

    You can see in my reply above though I do NRF.setAdvertising([ binary_data, {} ], { name:"Hello", ... })

    The important thing there is the {} as it says to Espruino that you want to advertise two packets, interleaving them. One is the binary data, the other is what Espruino makes based on name - so in that case it should show up

  • Thank you for the hint ... so I have changed it to

    const adv = [ 0x1e, 0xff, 0x4c, 0x00, 0x12, 0x19, 0x00, key[6], key[7], key[8], key[9], key[10], key[11], key[12], key[13], key[14], key[15], key[16], key[17], key[18], key[19], key[20], key[21], key[22], key[23], key[24], key[25], key[26], key[27], key[0] >> 6, 0x00, {}];
    NRF.setAdvertising(adv, {interval:1500,name:ble_name,showName:true,discoverable:true,connectable:false,scannable:true});
    

    Although there is no error or message the device seems to fall back so I can connect via IDE ... it does not advertise like I want it to. I am a little out of ideas now.

  • Aha – I think I have found a solution, at least it looks better now. I set the name first and adv after it. They don't seem to overwrite eachother:

    NRF.setAdvertising({}, {interval:1500,name:ble_name,showName:true,discoverable:true,connectable:false,scannable:true});
    NRF.setAdvertising(adv, {});
    
  • The issue was you'd got the brackets a bit wrong, You had:

    const adv = [ 0x1e, 0xff, 0x4c, 0x00, 0x12, 0x19, 0x00, key[6], key[7], key[8], key[9], key[10], key[11], key[12], key[13], key[14], key[15], key[16], key[17], key[18], key[19], key[20], key[21], key[22], key[23], key[24], key[25], key[26], key[27], key[0] >> 6, 0x00, {}];
    

    But you needed:

    const adv = [[ 0x1e, 0xff, 0x4c, 0x00, 0x12, 0x19, 0x00, key[6], key[7], key[8], key[9], key[10], key[11], key[12], key[13], key[14], key[15], key[16], key[17], key[18], key[19], key[20], key[21], key[22], key[23], key[24], key[25], key[26], key[27], key[0] >> 6], 0x00, {}];
    

    Or probably more readable, you just want to do:

    const adv = [ 0x1e, 0xff, 0x4c, 0x00, 0x12, 0x19, 0x00, key[6], key[7], key[8], key[9], key[10], key[11], key[12], key[13], key[14], key[15], key[16], key[17], key[18], key[19], key[20], key[21], key[22], key[23], key[24], key[25], key[26], key[27], key[0] >> 6, 0x00];
    NRF.setAdvertising([ adv, {} ], {interval:1500,name:ble_name,showName:true,discoverable:true,connectable:false,scannable:true});
    
  • Yes, my twice-setting of advertising didn't work, somehow it looked like it would.

  • Thank you Gordon, looks good now. Some device scanner just don't seem to update their data correctly, even if restarted. "nRF Connect" works best.

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

NRF.setAdvertising 'name' and 'iBeacon'

Posted by Avatar for user149221 @user149221

Actions