inthehand / 32feet

Personal Area Networking for .NET. Open source and professionally supported
https://inthehand.com/components/32feet/
MIT License
843 stars 208 forks source link

Most advertisements are missed #444

Open ygoe opened 4 days ago

ygoe commented 4 days ago

I'm building a temporary solution to send acquired sensor data to a Windows or Android device via Bluetooth LE. I have two options here: Sending the data in the advertisements, or going on to connect and polling a characteristic for the data. I couldn't manage to do the sender part with BlueZ/D-Bus/.NET on a Raspberry Pi, and even the incomplete advertisements were sent out too slow. But on an ESP32 microcontroller the advertisements are sent out smoothly every 100 miliseconds (that's the interval of the sensor data).

Now on the app side, I want to receive the data. While I can confirm the advertisements interval with the nRF Connect Android app, I see very irregular events in the Windows app. The advertisements are received every 1 to 2 seconds, and sometimes in quick batches, but mostly with long pauses.

Here's the relevant code:

Bluetooth.AdvertisementReceived += Bluetooth_AdvertisementReceived;
var scan = await Bluetooth.RequestLEScanAsync();

I don't understand where the issue is. Does this library limit the number of advertisements, or does Windows 11 drop most of them, or is my PC hardware just bad (mainboard with external WLAN/BT antenna, WLAN disabled)?

I'd also test this on Android but the whole app doesn't work there yet, so I don't know if Android would run better.

ygoe commented 4 days ago

Same on Android. I get 2 advertisements at the same time, then nothing for around a second. Then it repeats.

Considering that nRF Connect can receive every single advertisement on the same device, I believe that this library is causing the issue. This makes using it to receive broadcast data unusable for me. I'll have to invest in the added complexity of actually connecting to the device and poll the data. Let's see if that even works or I'll need something completely different than this.