10-02-2020 12:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-02-2020 12:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I want to get the real time Heart Rate on my android app. As per my understanding this is what is needed.
1. Develop a fitbit device app and make use of Excercise API (since I am making a workout app)
2. Develop a companion app
3. Establish commication between DeviceApp with companion app.
4. Make Android app as a websocket and get data from Companion app to the Android app.
Is my understanding correct?
Also, this will work in Versa, Ionic and sense?
Can I get an example of this entire implementation anywhere? It would be of great help.
Answered! Go to the Best Answer.
Accepted Solutions
10-02-2020 14:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-02-2020 14:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Yes, that will work. Since heart-rate data isn't too frequent and you won't need bidirectional communication, you could get away with fetch() instead of websocket, but websocket is probably better.
Presumably the Fitbit companion code (running in Fitbit app) will be on the same device as your Android app. That will mean you can get away with http (ws) rather than https (wss).
Yes, it will work for Versa, Ionic, Sense.
Gondwana Software

10-02-2020 14:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-02-2020 14:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Yes, that will work. Since heart-rate data isn't too frequent and you won't need bidirectional communication, you could get away with fetch() instead of websocket, but websocket is probably better.
Presumably the Fitbit companion code (running in Fitbit app) will be on the same device as your Android app. That will mean you can get away with http (ws) rather than https (wss).
Yes, it will work for Versa, Ionic, Sense.
Gondwana Software

10-02-2020 14:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-02-2020 14:38
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks for your reply @Gondwana !
Yes, Fitbit companion code and Android app will be on the same device.
Can I get to a bit more explanation about fetch() and websocket? Both are the part of Companion api, so the websocket would be on the Android app. What can be the URL in order to setup the socket connection? Or else how can I make use of fetch(), can you point me to samples of examples? If possible.

10-02-2020 15:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-02-2020 15:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I don't know of any Fitbit-specific examples.
For a websocket, I used ws://127.0.0.1:8080. Obviously what will work for you depends on your setup. Note that there's only a small number of URLs that work without wss.
For fetch(), I used http://127.0.0.1:3000.
Gondwana Software

10-05-2020 11:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-05-2020 11:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks for your reply again @Gondwana !
Can you clear my last doubt? Should the code base for Fitbit device (Fitbit app) and companion app different or it should be included in the same code base? I have created a device app with HR, I am not sure how does the companion app works with the communication part with the fitbit device.

10-05-2020 12:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-05-2020 12:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I don't understand the question. Companion code and clockface code goes in one project.
Gondwana Software

10-06-2020 21:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-06-2020 21:12
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
That's what I wanted to know.
@Gondwana This is what I am doing now.
1. I have a fitbit, companion and setting app developed and running on fitbit OS Simulator.
2. I have a websocket running on Android Simulator on "http://localhost:38302/"
This is what my code looks like on Fitbit Companion app.
const HOST = "http://localhost:38301/"
export function ServerAPI() { };
function sendToServer(uri, data) {
console.log("Sending to server : ",data)
return new Promise((resolve, reject) => {
fetch(uri, {
method: "POST",
body: JSON.stringify(data)
})
.then(res => res.json())
.then(data => resolve(data))
.catch(err => reject (err))
})
}
function getFromServer(uri) {
return new Promise((resolve, reject) => {
fetch(uri, {
method: "GET"
})
.then(res => res.json())
.then(res => resolve(data))
.catch(err => reject (err))
})
}
ServerAPI.prototype.sendHeartRateData = data => {
console.log("Data in sendHeartRateData : ", data);
console.log("HOST in sendHeartRateData : ", HOST);
sendToServer(HOST, data)
.then(res => console.log('Successful posted!', JSON.stringify(res)))
.catch(err => console.log('Error at post a heartrate data', err.message))
}
in console log I get this "Error at post a heartrate data Failed to fetch"
I am only concerned about sendToServer and getting the correct json in the
console.log("Sending to server : ",data)
the data is
{ timestamp: '2020-10-07T04:10:24.964Z', heartRate: 106 }
What am I missing here?

10-06-2020 21:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-06-2020 21:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Dunno. Instead of 'localhost', try using one of allowed IPs.
I'm also not sure that fetch() needs to be wrapped in a new Promise, since it already returns a promise. But that shouldn't be a deal-breaker.
Gondwana Software

10-06-2020 22:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-06-2020 22:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Ok. I have also tried on 10.0.0.140:38301 it was still the same.
I also want to know how can I install the fitbit app and companion app on the a real physical device, in that case both companion app and my Android app would be running on the same device.
Can you point me to a resource where I can find about this? @Gondwana

10-06-2020 23:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-06-2020 23:11
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
That's not one of the allowed IPs. Unless you can use https, you'll have to stick with one of these. There was talk about broadening the list, but I don't think that's happened yet.
Therefore, you'll almost certainly have to run the companion app on the same device as your Android app (which presumably means your phone). Have you tried that?
Gondwana Software

10-07-2020 10:04 - edited 10-08-2020 16:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-07-2020 10:04 - edited 10-08-2020 16:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
@Gondwana Thanks for pointing that out.

05-30-2021 03:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-30-2021 03:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Hmm, the url is the address of the host that is running the emulation so that port is used by the debugger. You need to use the port number of the websocket in your android app.
05-30-2021 06:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-30-2021 06:30
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Well, if you have solved this problem in the mean time, I would really appreciate that you share some code.
I am a (butoh) dancer, and I would like to have an Open Source Flutter app that shares live FitBit data in OSC format (Open Sound Control) which makes it possible to control synthesizers, light effects, etc, etc with your heartbeat, steps, acceleration, gyroscope, and more
so [FitBit]--->[Flutter App]---> Open Sound Control --->>
* Processing,
* Open-CV,
* Pure Data,
* Interactive Artworks,
* Synths,
* Super Collider,
* Lights,
* ...
It will be a great toy for the creative community, any advice and help is appreciated creating this...

04-13-2024 17:54
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-13-2024 17:54
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Do you have sample code for android app to receive this data? I am looking exactly for something similar to this and the watch is sending this data to firebase. Now, I want to make a server on android to receive this data. Let me know if you have any sample code for android.

