Resolved: advertising a GATT service (heart rate) does not work but UART does #5981
Replies: 1 comment
-
Posted at 2023-06-01 by @fanoush I just tried to run
on 52840 dongle with recent 2.17 build and it simply works, I see As for the setServices, that worked too
I just tried it without and also with the When connecting via nrfconnect I see "Heart Rate" service and can read the value of 0 bpm Posted at 2023-06-01 by @fanoush And BTW the "more precise way" is something completely different, you can have one or the other or both but they are unrelated, it is not 'more precise' way. Posted at 2023-06-04 by AnotherStranger Hey there I got your example working using following code:
With this code, I could see the heart rate inside the nRF connect app as well as in FitoTrack for Android. However, I got two problems to solve: First, setServices requires a BLE restart. Secondly, if the device is already connected to e.g. gadgetbridge it is not discoverable except when I trigger it within the bluetooth settings. Posted at 2023-06-05 by user155593 @user155613 Thank you for your feedback and signalling potential problems! Posted at 2023-06-05 by user155593 @fanoush Thank you for pointing this out! Posted at 2023-06-05 by @gfwilliams Glad it's sorted! The BLE restart happens automatically if the Bangle is not connected, or as soon as the Bangle becomes disconnected - which I guess should happen in most cases anyway. On Bangle.js 2v18 firmware you can actually use Advertising and request it to keep advertising even while the Bangle is connected, so that could be an option - but Web Bluetooth's handling of scanning for Advertising isn't available on as many platforms as Web Bluetooth connections . Posted at 2023-06-05 by AnotherStranger
Does this mean that calling setAdvertising would suffice on 2v18? Posted at 2023-06-05 by @gfwilliams You need to call http://www.espruino.com/Reference#l_NRF_setAdvertising with I'm not entirely sure what you mean about complex objects - you can advertise multiple services, but there is only so much space available in the packet (it's ~20 bytes). Posted at 2023-06-05 by AnotherStranger Sorry for the confusion! I want to advertise this object in order to comply to the standard:
Posted at 2023-06-05 by @fanoush
which standard? GATT Heart Rate Service documented here You are mixing two relatively unrelated BLE features. Advertising is GAP. Services/characteristics is GATT. GATT works over connections, advertising does not. Posted at 2023-06-05 by @gfwilliams Yes, unfortunately you can't do that and have it magically work with apps that are expecting the HRM Service on a connection. What you can do is advertise Posted at 2023-06-05 by user155593 @AnotherStranger @gfwilliams Sorry to bother you again but the issue pointed out by AnotherStranger is actually not allowing me to properly develop an app. The following code, even though makes the heart rate service available, throws this error in the IDE:
Trying to resolve the issue with the need for restart does not seem to resolve the problem. I have tried this:
I have also tried this (introducing a timeout):
This code still resulted in an error: Is there an established way to do this that I've missed perhaps? Thank you in advance! Posted at 2023-06-05 by @fanoush
You need to disconnect everything including the IDE from the device to let the BLE stack restart automatically, then it will start working. You can wrap the update in try catch block if the exception breaks something. Posted at 2023-06-06 by user155593 Thanks everyone! The problem of the app not continuously advertising the data when deployed as an app and not via Espruino IDE was actually the fact that the program would quit before advertising anything. So I needed to implement a keep alive function. The app is functioning now. Thank you! Posted at 2023-06-06 by @gfwilliams Hi, maybe just try:
No need for the You'll need to connect to the Bangle after you run the app. The Posted at 2023-06-06 by user155593 @gfwilliams Thanks for pointing this out - moving the code outside the init() function does not require setInterval to keep the program alive, as it is done directly by HRM events. Thank you! Just wanted to as you one last thing - for now the app only runs when it is open - as soon as I get back to the main menu, the advertising stops. Is this an intended way to do it or is there a way to run it in the background? I've tried playing with
but it recreates the main screen in an arbitrary way. As soon as I want to interact with the menu (press the side button), the program stops. Posted at 2023-06-09 by @gfwilliams Yes, that's the intended behaviour - basically because code is of varying quality, if we left all apps in charge of cleaning themselves up, many wouldn't and Bangle.js would be very unreliable after a while. So what we do is when loading a new app we tear everything down, and restart it. Some apps like some clock/launchers implement 'fast load' which lets them swap between themselves quickly without that full load but on the whole when launching apps everything gets removed. You can add 'boot code' (a file called So I probably already answered this when it was asked in the PR too :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2023-06-01 by user155593
Hi, I'm struggling with an issue and would really appreciate any help! I'm trying to implement a simple web application that connects to my Bangle.js 2 and visualises the received heart rate data. I would like to advertise heart rate service as as GATT service following all the specifications. I've tried many many versions of the code below (loading it via Espruino IDE for now) but nothing seems to work.. None of the services can be found when using nrFConnect and LightBlue. I've tried both NRF.setAdvertising like so (simplified version):
I've also tried a more precise way using NRF set and update services:
However, when I send my heart rate data using UART (following this tutorial here: http://www.espruino.com/Bangle.js+Data+Streaming#bonus-2-heart-rate-monitoring-graph), it works correctly and I'm able to receive this data on my web app:
I would really appreciate any help regarding this as I'm new to Espruino and Bluetooth in general and struggling to find a solution. Just a quick note: my web app is currently not scanning for the services but I would assume that if advertising works correctly, it should come up on nRFConnect and LightBlue.
Thanks for your help in advance!
Beta Was this translation helpful? Give feedback.
All reactions