setAdvertising options

Posted on
  • Hi @Gordon,

    Could you explain setAdvertising interval option ?
    I would like to save battery and decided to advertise data providing {interval:10000} the maximum possible, but in that time the device disappars and appears in the WebIDE, should I provide discoverable: true in order to be able always visible and connect to it?

    Which is the default value for the interval option? When should I prefer the minimum and maximum values ?

  • interval is the the number of milliseconds between the advertising packets getting sent. The default is 375ms.

    Basically in order to do anything with a Bluetooth LE device, you have to get an advertising packet. The device sends a packet and the listens for a very short time after that - and if there's a connection attempt it needs to be sent during that time.

    The advertising packets are sent on 3 different frequencies in rotation. If a device is listening for connection then in usually only listens on 1 frequency - so even at 375ms the advertisement will probably only be received once a second. Most computers will only wait around 2 seconds to get a connection, so higher intervals get progressively more hit and miss for establishing connections.

    If I could have set it any lower and got reliable connections, I would have (in fact early Pucks shipped advertising slightly less often and I had to change it).

    Basically:

    • minimum: I wouldn't ever use - but more advertising packets means a higher chance that one will get through = higher range (unless there are loads of devices doing it)
    • maximum: You'll never be able to connect with this, however if you have something that is reporting a value that doesn't change often (eg. room temperature) and have no need to connect then it's a great way to save battery.
    • If you want to connect reliably, use the default of 375. You might get away with 1000 on some hardware, but I wouldn't bank on it.

    If you really want to save battery more then you can lower the advertising interval and then have code that raises it back up to 375 when there's a button press.

  • Hi @Gordon,

    My usecase is to broadcast data which is pretty static and change slowly, once per hour. When we lower the interval, i.e. approaching maximum value, does it mean that we achieve lower range, the opposite what you say when we approaching the minimum value ?

    If I understand you correctly if I set:

    • {interval:200} close to the minimum will achieve higher range with will have higher battery consumption, and higher chance to connect to the device.
    • {interval:8000} close to the maximum will achiveve lower range with lower battery consumption, and lower chance to connect to the device.
    • {interval:375} is a balance between range and battery consumption and chance to connect to the device
  • Yes, that's correct (but beyond a 1s interval your chances of connecting are very low indeed).

    The range itself is less clear-cut. If only 10% of packets get through to the receiver then sending more packets will increase the chances of one getting through - but if you're so far away than 0% of packets get through then that wont help you!

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

setAdvertising options

Posted by Avatar for user73560 @user73560

Actions