noble / bleno

A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals
MIT License
2.12k stars 447 forks source link

simulate device going out of range? #429

Open fschwiet opened 5 years ago

fschwiet commented 5 years ago

We're using bleno to simulate devices used by our app in automated testing. One scenario we want to test is the device going out of range. We can kind of get there by calling bleno.stopAdvertising() and bleno.disconnect(), but this causes the bluetooth device to tell the server it is disconnecting. We want to test codepaths as if the device were truly out of range with no messages received.

Is there a way we can get the bluetooth device to stop sending messages altogether? Our device is running on raspberry pi.

blamay commented 5 years ago

It seems that bleno.stopAdvertising() and PrimaryService.shutdown() aren't enough to stop sending ble packets all together. The only way I found to accurately simulate a device going out of range was to just shut down the bluetooth adapter with sudo hciconfig hci0 down