09-10-2024 08:56
09-10-2024 08:56
Hello,
I have made a real time type 1 diabetes simulation as a nodeJS backend application. The frontend allows to customize the virtual patient, follow their CGM curves, and of course administer meals and insulin. Finally, I made it possible for my users to authenticate using Fitbit Oauth2 API, allowing my backend to retrieve their intraDay steps and heart rate at regular intervals. This also affects the simulated blood glucose curves. https://cgmsim.com
Now some of the simulation users are not allowed to wear activity trackers at work (mostly healthcare providers, nurses, medical students, residents...) so for them I'd like to use the step counts from their cell phone. I made a little app for that too, that can retrieve the step counts from the cell phone and upload them to my API. I made it using React Native and Expo, I don't know Swift / Kotlin.
Apple's Healthkit can be queried in the background, but regularly uploading the stepcounts to my backend's API has proven to be difficult. A backgroundFetch is throttled by the OS, and is unlikely to happen if the screen remains locked for a long time, or the iOS app isn't openend very often, or if the battery is low, etc... In Android, Health Connect cannot be queried in the background (... for now, but things are going to change this year probably).
I tried sending silent push notifications from the backend to my mobile app, triggering the Health queries and uploads. This works most of the time, but is also subject to the supreme ruling of the OS. Silent push notifications cannot trigger a background task in Android by design. The task is executed only when the user brings the app to the foreground.
So I am wondering what kind of sorcery is the Fitbit app using in order to upload its data to the Fitbit servers every 15 minutes or so ?
Clever Use of System Events: taking advantage of various system events (like network changes, location updates, or time changes) to trigger brief wake-ups and data syncs ?
A Privileged Partner Status ? Large companies like might have special arrangements with Apple and Google to get more lenient background execution policies.
A combination of all solutions above ? Any hint or idea is welcome at this point. I am about to give up.
09-10-2024 20:31
09-10-2024 20:31
Hi @lsandini - good project, have you looked at Macrodroid on Android, this can do many useful things.
For iOS have a look at some of the Fitbit help articles, for notifications and sync, to get the necessary phone settings correct. This may improve things.
If users can't wear watches on a wrist but can carry phones, they may be allowed to use watches on an arm band or chest strap.
Author | ch, passion for improvement.