BLE connection closes after a few minutes #4273
Replies: 1 comment
-
Posted at 2024-02-19 by @fanoush every I would try to
if it starts to slow down it can be issue on both sides, on puck side the data may be generated faster than can be sent or some idle mode kicks in. Ther is such mode for BLE connection (see setConnectionInterval linked above) but if data is sent all the time it should not be triggered, not sure if there is something for accelerometer too - possibly not, you can just set sensible rate here https://www.espruino.com/Reference#l_Puck_accelOn BTW if the flow of data is steady and relatively fast the connection is indeed better than simple advertising Posted at 2024-02-19 by @fanoush One more comment - If it gets stuck and disconnects I would guess the most probable case is that data is generated faster then it can be sent via BLE. Posted at 2024-02-19 by @gfwilliams Hi! Using the bluetooth UART to send data like you're doing is usually pretty good as it can buffer up writes and send them at once, but as @fanoush says you need to be careful that you actually can send the data faster than you're sending it. I'd suggest:
But the slowing down and disconnecting is a bit of a surprise - there is actually a possibility that you just have a flat battery? Going 'full tilt' reading the accelerometer and sending data can draw a lot more power than just being idle (~10mA vs 0.03mA). It'd last for ~20 hours on a fresh battery but even so if that battery is old it may well end up flattening, then rebooting after? For advertising if you did go that way, you can specify Posted at 2024-02-19 by @fanoush
just checked and we are sending only one packet per connection interval (?) here Posted at 2024-02-20 by DrewS Thanks so much for this great feedback. There's a lot for me to try here, but real quick on the battery - that seems to be good. It's at 75%. I'll start trying these wonderful suggestions and report back. Thx again for the super quick in depth responses! Posted at 2024-02-20 by @fanoush You're welcome. If it is still not enough then you may also add your own characteristic. since you already use custom code like
then keeping standard console away from this and using same start_notify code just with your own one instead of UUID_NORDIC_RX (or even one of standardized ones for this) could make it a faster and you'd have it more under control as then from accelerometer event you would simply update the characteristics value directly with no nordic uart buffering or limitations. Posted at 2024-02-20 by @gfwilliams
That's interesting! Thanks for the spot, I'd totally forgotten about that - maybe it was something that was pulled out for Nordic's gateway, when other stuff can handle it fine. I could maybe add a Posted at 2024-02-22 by DrewS Ok - i made some progress here. I switched things over to use But then I started looking into ble advertising because for my use case, one direction communication is fine and if I could get 20 ms between accelerometer updates that would be awesome. I found some sample code in the puck.js documentation, and modified it like so:
Yes, those are intentionally very fast intervals. I was just banging my head against it trying to get it to update quickly. on macOS, here is my python script:
This doesn't correctly parse my "presses" int, but for now i'm just looking at how fast it updates. This is what my script prints out:
Ok - so that's mostly good. But here's the weird part. In mac OS terminal, I visually see the updates coming in roughly once a second, even though delta time is a fraction of that. Sooooo now i'm wondering if my mac BLE service is just buffering stuff up or something? If this is a dead end, I can go back to a direct blue tooth connection which definitely seems to be much faster. But wow it'd be cool if i could do this with advertising. :). Thanks! Posted at 2024-02-22 by @fanoush ios may cache it too but the Posted at 2024-02-22 by DrewS Ahh - ok so I had two bugs. The first was leaving off the So now my puck js code:
and fixing my dumb python bug, gives me this output:
And those numbers actually match what I see in terminal. I think at this point I'll pursue a direct connection instead of advertising (but if you have any other suggestions for that I'll happily give them a shot). Thx again for all the quick responses. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2024-02-19 by DrewS
I have a hobby project where my puck.js sends accel data:
Then I have a python script that uses bleak to connect to the puck, and listen for that console output, which I then pass along to another toy program.
This all works fine for a while, but i've noticed that after a few minutes the speed of the accel data i'm getting starts to slow down, and eventually the connection drops.
Any suggestions on what might be happening? I looked into trying to do this by purely advertising the IMU data and not making an actual two way connection, but it doesn't look like I get a very high frequency signal that way. Just a few updates per second, and I need closer to 10 updates per second.
Thanks! p.s. i'm new to BLE so might be doing this a bit backwards.
Beta Was this translation helpful? Give feedback.
All reactions