• Hi
    I am trying to do a smart power meter pulse counter with the puck.
    It all kind of works, until the values get over a certain level. Then it throws all kind of errors and stops sending any data.
    This is the setAdvertising code I use:

      NRF.setAdvertising([{
        0x2a03 : [String(power)], 
        0x2a04 : [String(pulseHour)],
        0x2a05 : [String(pulseDay)],
        0x180f : [Puck.getBatteryPercentage()]}],
        {interval: 600,
        name: "PM \xE2\x9A\xA1"} 
      );
      
    

    All of the service data values are integers. Power is instantaneous power which can go to like 5000 and pulseHour and pulseDay can go well over 1000. I tried not using the string, but then it does not store the full value. Not sure where it breaks

  • so far I have found that I can only send numbers 0-255 (is that 2 bytes?)
    How do I overcome the limitation? Is there a tool to see how many bytes in total are getting sent, so that I know when I am approaching the limit? Also read about using short UUID and not using the name to save on the data.
    I guess one option is to rotate the information sending, instead of sending all at once. I saw an example before, but cannot find it

  • Sorry for the delay...

    so far I have found that I can only send numbers 0-255 (is that 2 bytes?)

    0-255 is 1 byte. Something like 0x2a03 : [String(power)], will convert the value to a string of characters which will easily allow more data, but which will use far more space.

    How do I overcome the limitation?

    The easiest way is to use shifting to explicitly create 2 bytes. For example instead of 0x2a03 : [String(power)], do 0x2a03 : [power>>8, power], - you can now send up to 65535.

    0x2a03 : [power>>16,power>>8, power], will allow up to 16 million.

    Is there a tool to see how many bytes in total are getting sent, so that I know when I am approaching the limit?

    Yep - just use NRF.getAdvertisingData: http://www.espruino.com/Reference#l_NRF_getAdvertisingData

    Use it the same as setAdvertising but it gives you an array of the final data, and you can check the length of that array.

    Also read about using short UUID and not using the name to save on the data.

    Short UUID is what you're currently doing. You could just pack everything into one UUID though? That would save space:

    0xabcd : [power>>8, power,pulseHour>>8,pulseHour, etc], 
    

    I guess one option is to rotate the information sending, instead of sending all at once. I saw an example before, but cannot find it

    http://www.espruino.com/Reference#l_NRF_setAdvertising - about halfway down

    NRF.setAdvertising([
      {0x180F : [Puck.getBatteryPercentage()]}, // normal advertising, with battery %
      require("ble_ibeacon").get(...), // iBeacon
      require("ble_eddystone").get(...), // eddystone
    ], {interval:300});
    

    In your case:

    NRF.setAdvertising([
     { 0x2a03 : [String(power)],  0x2a04 : [String(pulseHour)] },
     { 0x2a05 : [String(pulseDay)], 0x180f : [Puck.getBatteryPercentage()]}] }
    ], {interval: 600,
        name: "PM \xE2\x9A\xA1"} 
    );
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Need help to identify limitations of NRF.setAdvertising

Posted by Avatar for user130485 @user130485

Actions