• Here is snippet of code I use

    NRF.whitelist=[];
    NRF.on('connect',function(addr) {
      if (!NRF.whitelist.includes(addr)){
        if (BTN1.read()){ // add to whitelist when button is held while connecting
          NRF.whitelist.push(addr);
          vibrate(1,1,100,0);
        } else
            NRF.disconnect();
      }
      NRF.connection = { addr: addr };
      NRF.connected=true;
      NRF.setRSSIHandler((rssi)=>{NRF.connecti­on.RSSI=rssi;});
    });
    
    NRF.on('disconnect',function(reason) {
      NRF.connected=false;
      NRF.connection = {};
      NRF.lastReason=reason; // google BLE hci status codes
    });
    

    It also vibrates on connection (my custom code) and maintains active connection with rssi value as extra NRF object properties, also on disconnect it keeps the reason. This code is not needed for this simple whitelisting and can be removed.

About

Avatar for fanoush @fanoush started