• I am still a bit confused about the differences between setadvertising interval vs setinterval vs timeout.
    Is my understanding of each of these examples correct?

    A: This will send out a single, one shot blast of BLE advertisement of the battery, lasting only of 375 ms

    NRF.setAdvertising({
      0x180F : E.getBattery()
    },{interval: 375 });
    

    B: This will continuously send out a BLE advertisement of the battery once a minute, forever or until the Interval is cleared

    setInterval(function () {
      NRF.setAdvertising({
        0x180F : E.getBattery()
      }) 
    }, 1 * 60 * 1000);
    

    C. This, with the press of BTN1, this will send out 5 sets of BLE battery advertising once a minute. Each of those five sets of BLE advertising blasts will last 375 ms. In this case I am not sure if I need XX and YY (see code). This is where I get confused.

    setWatch(function() {
      updateBLE();
    }, BTN1, { repeat:true, edge:"rising", debounce: 25 });
    
    function updateBLE(presses) {
      let x = 0;  
      const intervalID = setInterval(() => {  
        if (++x === 5) {  
          global.clearInterval(intervalID);  
        }  
        
        NRF.setAdvertising({
          0x180F : E.getBattery()
       },{interval: 375 });   //XX
    }, 1 * 60 * 1000);        //YY
    }
    

    Thanks

  • advertising is core feature of BLE, you cannot connect to device if it is not advertising so it basically runs all the time with some interval between packets unless bluetooth is off or device is connected. so '5 sets of advertising once a minute' is not how advertising and BLE works.

    NRF.setAdvertising is used to change advertising packet data, if you don't call it again, same data packet is advertised repeatedly with preset interval.

    setInterval is standard javascript method to call something repeatedly, setTimeout is same but runs only once

  • ah ha - makes sense. Thanks.
    What I was trying to do was make sure the advertising got through, which isn't always the case. So I was trying to always advertise the battery, except when the button is pushed in which case I wanted to run a count.

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

setadvertising interval vs setinterval vs timeout - still a bit confused

Posted by Avatar for kab @kab

Actions