You are reading a single comment by @ChristianW and its replies. Click here to read the full conversation.
  • OK.
    Some more tests show that it may have been a memory issue.
    Limiting the stored lap data to 250 records resulted in the test running for about two hours now.

    However, somehow the Transponders stop advertising now somehow after a few hundered iterations being toggled on and off.
    This is the modified code:

    /** =====================================================
     * throw off unknown BLE clients
     * @constructor
     */
    var Firewall = {
      whitelist: {
        '14:7d:da:3f:53:31 public': 'Macbook Work',
        '50:ed:3c:01:69:ab public': 'Macbook Air'
      },
    
      init: function () {
        NRF.on("connect", (addr) => {
          if (!(addr in this.whitelist)) {
            NRF.disconnect();
          }
        });
      },
    }; // Firewall
    
    var id = 0;
    var on = true;
    function toggle() {
      if(id == 0) {
        NRF.wake();
        digitalPulse(LED2, 1, 200);
        id = setInterval(
          ()=>{
            digitalPulse(LED3, 1, 30);
            on = ! on;
            advertise();
          },
         5000
        );
      }
      else {
        digitalPulse(LED1, 1, 500);
        clearInterval(id);
        id = 0;
        NRF.sleep();
      }
    }
    
    var longId = 0;
    
    function longPress(state) {
      if(state) {
        if(0 == longId) {
          longId = setTimeout(
            () => {
              toggle();
              longId = 0;
            },
            2000
          );
        }
      }
      else {
        if(longId > 0) {
          clearTimeout(longId);
          longId = 0;
        }
      }
    }
    
    function advertise() {
      if(on) {
        NRF.setAdvertising(
          {},
          {
            name: "Velo" + NRF.getAddress().substr(-5).replace(":", ""),
            showName: true,
            discoverable: true,
            connectable: true,
            scannable: true,
            interval: 20,
            manufacturer: 0x0590,
            manufacturerData: [Puck.getBatteryPercentage()]
          }
        );
      }
      else {
        NRF.setAdvertising();
      }
    }
    
    function onInit() {
      Firewall.init();
    
      advertise();
      setInterval(advertise, 60000);
    
      toggle();
      setWatch(
        (btn) => longPress(btn.state),
        BTN,
        { repeat:true, edge:"both", debounce: 50 }
      );
    }
    

    The effect is this:
    The blue flashing still occurs, but the change to advertise the manufacturer id doesn't seem to happen, because the Puck is not recognized by the tracker anymore.
    Toggling on/off via button (resutls in NRF.sleep() / NRF.wake()does not help.
    Doing a reboot (power cycle) makes it work again.

    It seems the repeatedly change via NRF.setAdvertising() breaks something over time.

    Very strange, but no issue for the later use case.

About

Avatar for ChristianW @ChristianW started