BLE Advertising stops when connected

Posted on
  • Hi,

    i am playing around with the BLE Advertising. It seams to be a little bit unstable.

    First: When connected to the Web IDE, Advertising don´t work at all for me. You need to disconnect to test it. Is this by design or a bug?

    Second: Button Press is not catched precisely.

    i use the following code:

    var pressCount = 0;
    setWatch(function() {
      pressCount++;
      NRF.setAdvertising({
        0xFFFF : [pressCount]
      });
    }, BTN, { edge:"rising", repeat:false, debounce:50 });
    

    Setting repeat to true causes on some pucks to repeatingly advertise the counter, on others to only adverstise the counter when button is pressed.

    Third: Different Intervals

    I set two advertisements within an interval of 3 seconds but the information are advertised in different intervals:

    setInterval(function() {
      NRF.setAdvertising({
        0x2a01 : [String(E.getTemperature())],
        0x2a19 : [String(Puck.getBatteryPercentage())]  
      });
    }, 3000);
    

    Temperature is advertised every 3s but BatteryPercentage every 1-5 seconds (this vary a bit).

    Does anyone has some ideas?

    Kind regards

    solick

  • First: When connected to the Web IDE, Advertising don´t work at all for me.

    This is by design - most BLE devices do this. When it's disconnected then advertising resumes.

    Second: Button Press is not catched precisely.

    Try updating your firmware - this was an issue with the firmware on the first batch of KickStarters. Adding pinMode(BTN,"input_pulldown") should fix it on the old firmware, but I'd recommend updating to the newest firmware.

    Different Intervals

    The advertising itself will be happening every 100ms or so - but the data should be being updated for both every 3 seconds.

    Is it possible that the battery percentage just doesn't change?

    Also - the way you're setting the advertising data really isn't doing what you expect - take a look at the examples: https://www.espruino.com/Reference#l_NRF_setAdvertising

    Puck.js is expecting an array of numbers - trying to cast the values to strings and then put those in arrays seems a bit strange.

    Hope that helps!

  • Hi Gordan,

    I have the latest firmware just performed an update yesterday:

    >process.version
    ="1v94"
    

    No the battery percentage changes nor more precicely it is bouncing aroung a 56 percent

    The examples are not that useful, would you mind to give me a better one so that i can adjust it? For instant i didn´t understand how to perform the multi beacon variant (ibacon and eddison) it looks like we should require the modules within the function and that add some more configuraiton within the get() function but i didn´t found out how exactly the signature of this get function should look like.

    Kind regards

    Lyn

  • I changed now back to advertise without casting to string but than i only get integer temperature values...

    setInterval(function() {
      
      NRF.setAdvertising({
        0x2a01 : [E.getTemperature()],
        0x2a19 : [Puck.getBatteryPercentage()]  
      });
    }, 3000);
    

    advertises:

    /ble/advertise/c1:76:57:2e:39:b7/2a01 : msg.payload : Object
    Objectraw
    0: 0x15
    
  • but than i only get integer temperature values...

    Can you not decode those on your computer? When you use Strings it's very likely that the value itself will be very long (like 56.23435 or similar). When sending advertising data you're limited to around 20 bytes in total, so if you send two of those, there may be too much data and setAdvertising will fail - which might explain the problems you were having.

    For example if the battery is 56.5 in one instance then it might be fine, but if it's 56.23435 the next then it could fail.

    For instant i didn´t understand how to perform the multi beacon variant (ibacon and eddison)

    There are specific pages on iBeacon and Eddystone:

    http://www.espruino.com/Puck.js+Eddystone and http://www.espruino.com/Puck.js+iBeacon

    Did you see those? The configuration you should use it detailed there - the get function is used just the same as if you did the initial require("ble_ibeacon").advertise.

    It even has an example that does exactly what you're asking - I've just copy/pasted in the arguments from advertise for you:

    NRF.setAdvertising([
      require("ble_ibeacon").get({
        uuid : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], // ibeacon uuid
        major : 0x0001, // optional
        minor : 0x0001, // optional
        rssi : -59 // optional RSSI at 1 meter distance in dBm
      }),
      require("ble_eddystone").get("your_url")
      ], {interval:100});
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

BLE Advertising stops when connected

Posted by Avatar for solick @solick

Actions