09-17-2018 09:25 - edited 09-17-2018 12:20
09-17-2018 09:25 - edited 09-17-2018 12:20
I've seen a few apps/clockfaces that show a little bluetooth icon with a connected/not-connected status. I'm assuming this is in regards to being connected to the Fitbit app on the phone/device. I'd like to implement this on my clockface but not sure of the best way to reliability do that.
Essentially, my clockface attempts to connect to my phone every 5 minutes to collect data from various web api feeds via companion/file transfer/json-format and display that data on my clockface. I've noticed a lot of variability and unreliability when it comes to the Fitbit app on my phone maintaining connected state to my watch. I have all the settings enabled for "all day sync", "notification widget",etc... but many times a day I notice that the notification is missing from my notification drawer and my watch stops updating... when I go into Fitbit app and click my versa device, it does a sync and the notification comes back and my watch starts receiving data again... for a while.
So, I guess this post is multifaceted... I'd like to be able to tell from my watch the Bluetooth connected status w my phone and then also improve the connection between my phone and watch such that I reliably get my 5 minute clockface updates. I don't necessarily need the watch and phone to be connected via BT 100% of the time but somehow make sure than when my watch requests the data from my phone, the connection is there, ready to go. If the price is to keep them connected 24/7 via BLE, then I'll do that... but how?
Thanks,
-Royce
Answered! Go to the Best Answer.
09-17-2018 13:18
09-17-2018 13:18
TLDR; Periodically send a message from the device, check that you get a response from the companion.
In theory, if your app is running, its companion should also be running, and the peerSocket should be open. In reality, sometimes the phone OS puts the Fitbit app to sleep, or the companion gets put into a "background" state.
I would assume that apps which show the bluetooth icon are actually just periodically pinging the companion, and checking if they get a response. If the device sends a message to the companion, and the companion is not running, it should be woken.
That's how it should work. I heard that some Android phones have unusual bluetooth stacks, and this can cause some problems.
09-17-2018 13:18
09-17-2018 13:18
TLDR; Periodically send a message from the device, check that you get a response from the companion.
In theory, if your app is running, its companion should also be running, and the peerSocket should be open. In reality, sometimes the phone OS puts the Fitbit app to sleep, or the companion gets put into a "background" state.
I would assume that apps which show the bluetooth icon are actually just periodically pinging the companion, and checking if they get a response. If the device sends a message to the companion, and the companion is not running, it should be woken.
That's how it should work. I heard that some Android phones have unusual bluetooth stacks, and this can cause some problems.
09-17-2018 13:44
09-17-2018 13:44
Ok, this all makes sense. I'll add some side code in line with what you mentioned and see what gives. Thanks.
09-17-2018 13:48
09-17-2018 13:48
@JonFitbit I do send a message to the companion every 5 minutes. Would I up my chances of reliability if I bumped that to say every 2 minutes?
09-17-2018 14:10
09-17-2018 14:10
My ping test app was checking every 5 minutes, and I ran it for an extended period without any unexpected loss. How often are you losing connection? What phone/OS?
09-17-2018 14:16
09-17-2018 14:16
pixel 2 xl... android pie... seemed like pre-pie it was much more reliable. The past few weeks have been seemingly very dodgy at best. I can have 10+ lost connections per day now where the only thing that seems to get the connection back is a manual sync in the phone fitbit app.
09-17-2018 14:19
09-17-2018 14:19
That doesn't sound good. Are you able to capture phone logs using adb? If you could and email me the logs and the project, then I can pass it on to the Android team. I will PM you my email address.
09-17-2018 14:24
09-17-2018 14:24
Ok, I'll get all that to you in the AM (MDT) tomorrow. Thanks!
09-17-2018 15:14 - edited 09-17-2018 15:17
09-17-2018 15:14 - edited 09-17-2018 15:17
@JonFitbit one thing I'm noticing is that when my versa clockface stops receiving data, my android running services shows the phone fitbit app as "not active" with no running services...but then if I manually fire up the phone app and then go to running services i see the main app and a bluetooth service and sometimes a syncservice.... So for some reason on my phone the fitbit app and services are being killed on a frequent basis... And not by me.
09-17-2018 15:16
09-17-2018 15:16
Is it aggressive Android battery saving? Check the settings.
09-17-2018 16:04
09-17-2018 16:04
I have the fitbit app set to not be battery optimized... That doesn't seem to be having any positive effect. I just now turned off the new system wide android pie adaptive battery setting. Will report back results.
09-18-2018 08:44
09-18-2018 08:44
There don't appear to be any battery related settings that affect this behavior. I've tried multiple combos of the "optimized battery" setting as well as the system wide "adaptive battery" setting with no change in behavior one way or the other.
It sure seems like the system is simply killing the fitbit app and related services periodically without any ability on my part to affect that. I currently have all the fitbit app settings enabled for syncing and connection reliability and have the "optimized battery" setting to "off".
Hopefully there is more aggressive things in the app code that the dev team can do to force the app and android system to keep the versa/companion connection more stable.
I'll email the logs asap.
08-21-2019 03:38
08-21-2019 03:38
Any news on how to solve this?
08-22-2019 06:36
08-22-2019 06:36
I am having the same problem with my phone (galaxy s8) running pie. It started doing this bevaviour out of the blue in the last two weeks. Any idea how to fix this?
09-01-2019 07:32
09-01-2019 07:32
I'm seeing similar behavior when writing an app. Most of the time it connects without issue, but sometimes it just hangs and the companion never comes online. The peerSocket.readyState is CLOSED, so I can't send a message without generating an error. I've even tried to periodically reassign the peerSocket.onopen method to no avail.
I've assumed this is an Android issue which means there's likely not a lot I can do. In addition, it would be tough to ask users of the app to change their battery settings in order to use the app. 😕
09-01-2019 11:12
09-01-2019 11:12
This issue has crept back up in the past week or so. Was running ok for a long time. The phone fitbit app has updated a couple times in the last month so I don't know if that is affecting things.
For some reason my versa is not connecting reliably with the phone app... it'll sync/connect (companion) properly for a couple hours then completely stop. The only way I've found to get them to start talking again is to go into the fitbit app on the phone and manually sync several times. Eventually the versa will start updating again... for a few hours.
I've had Android battery optimizations turned off for the fitbit app for over a year now.
09-02-2019 06:44
09-02-2019 06:44
I'm not sure if you're using the "Versa (Classic)" or the "Versa" connection for bluetooth. The former is a real BT connection, the latter is a BTLE connection. The LE version uses less energy but it does this by, effectively, not being actually connected all the time. Use the "Classic" for a traditional (and more energy expensive) connection.
09-02-2019 07:55
09-02-2019 07:55
For my app, it appears that doing a wakeinterval in the companion seems to help.
I do a five min wakeinterval:
Even though the communication between the watchface and companion is supposed to wake it up, this appears to help for whatever reason stopping the android optimization from killing the fitbit task.
09-03-2019 21:32
09-03-2019 21:32
Will give this a try.thx.
09-04-2019 08:39
09-04-2019 08:39
Implemented. Will monitor. I have noticed... before I put in that code that when my watch is no longer fetching from my phone and I can't get it to reconnect... if I forcestop my fitbit app on my phone and then sync, everything works again. This is definitely new since the last couple updates.