c# - Bluetooth LE device as proximity sensor, BluetoothLEAdvertisementWatcher cyclically stops listening for advertisements -


in way of learning ble programming using c#, i'm trying write winform application should detec ble devices , use them proximity sensors. purpose i've applied bluetoothadvertisementwatcher class, filtering advertisements provided signal strength. problem detection seems quite crappy... device @ no distance pc, listener returns rssi value of -127, wich stands "no detection" i've understood. i've tried setting outofrangetimeout 10 seconds and, if things better, problems still heavy. major issue detection can flows without interruption bunch of seconds, debugger signals me thread exiting code 0, , listener can't receive new advertisements (with device ever aside pc) 30-40 seconds, restarts , loops. know if how intended work or if missing something? there way, eventually, intercept interruption , restart listener?

this how initialize watcher:

public blescanner(short maxdbrange, timespan outofrangetimeout) {          this.inrange = maxdbrange;         this.outofrange = (short)(this.inrange + blescanner.buffer_range);         this.outofrangetimeout = outofrangetimeout;          this.watcher = new bluetoothleadvertisementwatcher();         this.watcher.signalstrengthfilter.inrangethresholdindbm = this.inrange;         this.watcher.signalstrengthfilter.outofrangethresholdindbm = this.outofrange;         this.watcher.signalstrengthfilter.outofrangetimeout = this.outofrangetimeout;         this.watcher.signalstrengthfilter.samplinginterval = timespan.fromseconds(1);         this.watcher.scanningmode = bluetoothlescanningmode.active;     } 

while event handler:

private async void onadvertisementreceived(bluetoothleadvertisementwatcher watcher, bluetoothleadvertisementreceivedeventargs eventargs) {          var deviceaddress = eventargs.bluetoothaddress;         bluetoothledevice device = await bluetoothledevice.frombluetoothaddressasync(deviceaddress);          updateuidelegate update = new updateuidelegate(             (dev, args) => {                 if (eventargs.rawsignalstrengthindbm == -127) {                     this.form.spylabel.backcolor = system.drawing.color.red;                     this.form.namelabel.text = "(none)";                     this.form.addresslabel.text = "(none)";                     this.form.rssilabel.text = "(none)";                     this.form.connectedlabel.text = device.connectionstatus.tostring();                 } else {                     this.form.spylabel.backcolor = system.drawing.color.green;                     this.form.namelabel.text = device.name;                     this.form.addresslabel.text = device.bluetoothaddress.tostring();                     this.form.rssilabel.text = eventargs.rawsignalstrengthindbm.tostring();                     this.form.connectedlabel.text = device.connectionstatus.tostring();                 }             });         this.form.invoke(update, device, eventargs);          console.write(eventargs.rawsignalstrengthindbm + " ");     } 

any appreciated!


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -