I'm trying to persistently connect to 2 BLE devices: a Core temperature sensor and a generic HRM. In addition, I need to read advertising (as manufacturer data) from 2 pucks set up to read thermistors. And do sleep measurement similar to sleeplog. All of the temperature data plus heartrate will also be advertised as manufacturer data from the Bangle.
The problem I'm having is with the Core sensors. They frequently disconnect and I can't figure out why. I am still able to connect to them with nRF Connect when this happens. Sometimes they are good for an hour or so, but more often than not they disconnect several times an hour/minute and may take several minutes to reconnect. I have tried several cores with the same result. I have also (separately) tried using the Bangle coretemp app with recorder set to a 10 second log rate and run for over 14 hours without seeing any loss of core data. This is only a single connection though.
The HRM has no such issues. If the connection there is lost while the HRM is still powered and in range, the connection is generally remade on the first try.
The general idea is first the program connects to the HRM, then the Core, then it starts scanning for advertisements and checking both connections every 10 seconds to ensure they're still up. I've prioritized reconnecting to the HRM first, mainly because it's typically much more reliable. I have tried to ensure that each device locks the other out of connecting while it's trying to, and that I am not scanning for ads during this time. My code is attached, apologies in advance for the length. I have also included a snippet of the data that I've collected including some errors I was able to log. On very rare occasion I've also seen uncaught errors such as "Uncaught InternalError: BLE task completed that wasn't scheduled (SERVICE/NONE)".
Hmm, that's a pain. Are you staying connected to the Bangle as well during this?
If so it might be there's just too much BLE traffic (the UART connection will be in high speed mode so 7.5ms) - you could try NRF.setConnectionInterval(100) which will slow down the BLE communication speed, which might give a bit more room for other things.
I checked those disconnected codes, and:
Which is what it's saying when connecting I guess too - the connection timeout usually happens when the Bangle doesn't see a few bluetooth packets from the device, and then it decides it's lost the connection.
I have just pushed a new update, so if you try the cutting edge firmware now, does it work any better? I increased the 'slave latency' which as I understand it is the number of missing Bluetooth events Bangle.js is willing to put up with.
I also notice you're doing:
which definitely makes sense to try and reduce the amount of connection events per second that need to be handled, but I guess it might be causing connection issues if the sensor isn't happy doing exactly 100ms. You could try:
and see if that helps?
BLE task completed that wasn't scheduled (SERVICE/NONE)
BLE task completed that wasn't scheduled (SERVICE/NONE)
I wouldn't be too concerned about this unless it's happening a lot - it's probably related to the connection dropping out while you're trying to connect.
Maybe also try NRF.setTXPower(8) which should boost the Bangle's transmit power and might make connections more reliable. You could also maybe try checking the RSSI (signal strength) I guess in case it's abnormally low
Finally, what core temp sensor are you using? Have you tried others, or do you think it's possible that it's just this one model of sensor that is causing problems?
It happens when I'm connected via the IDE and without - doesn't seem to make a difference. I had already tried various connection intervals, but the Core says it wants between 7.5 and 100 ms, and also longer intervals just seemed to make it ultimately take even longer to reconnect because I found I had to adjust the checkConnectivity interval up to account for the longer timeouts. I have tried a couple 2021-Q1's and a 2022-Q4 Core. It doesn't seem to make a difference.
But I did notice that the 2022-Q4 Cores support multiple connections. So I tried the following with 2 Bangles: I set one up with the latest firmware and standard power (0 presumably), and the other was using 2v19.10 (the version I'd been using before) and TxPower 8. Both connected to the same HRM and Core. I ran it a few nights and the higher power one was noticeably better overall. The new fw might have helped a bit too, but it's difficult to tell with the data I've collected so far. I will make both changes going forward, though. I wouldn't have thought the power level would make that much difference, the range is less than 1 meter at all times since I'm wearing both devices. The pucks were in another room and still read pretty well. So thanks for the suggestion!
Great! Glad it's had some effect - the signal strength is a tricky one - I guess if lots of bluetooth devices are broadcasting that could cause a lot of interference.
2.4GHz is really bad at going through people too (it's basically microwave frequency, which just gets absorbed by water), so it does seem odd that it has any effect at 1m distance, but I guess if you end up in a situation where the signal has to go through your arm and your body, and there's interference, maybe that's just enough to push it over the edge sometimes.
I think with radio there will always be occasional cases where the connection drops out, but it should always be able to reconnect - it was really odd that it just kept failing for you before.
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
For a full reference visit the Markdown syntax.
© Espruino, powered by microcosm.
Report a problem