04-20-2021 07:00
04-20-2021 07:00
So, I am developing a Fitbit app that sends sensor data every second to the companion which sends it a Google cloud server. I am using the setinterval function to send json over to the companion and the companion posts the json to the Google cloud datastore. The app works fine but after 10 seconds or so the sensor values freeze at some value and do not change any more. I do not know where the problem comes from. What is the best place to ask for an experienced Fitbit developer for help with this?
Thanks,
Kamyar
Answered! Go to the Best Answer.
04-20-2021 11:48
04-20-2021 11:48
It sounds like either your watch app or your companion app is being killed for some reason, for the watch app maybe it is crashing due to an unhandled javascript exception or is "out of memory" or maybe you have not set "me.appTimeoutEnabled" to false. For the companion app, it's preferred state is not to be running unless it needs to.
I have managed to successfully log and send heart rate data to a server using the File Transfer API to send data to the companion app which then uses fetch to post the data to the server (using a previously obtained JWT from a login form on the companion)
The File Transfer API is the only reliable way to transmit data to the companion app, the Messaging API (peer sockets) only works while the companion is running, which most of the time means you have to be looking at the companion setting page on the phone and the phone screen is on. You could set an aggressive wake interval on the companion but not recommended as it could impact the phone battery life. Messaging will also fail if the phone is out of bluetooth range with the watch, is in flight mode or bluetooth is off etc.
The File Transfer API queues the outgoing files until the phone is available, but make sure you limit the queue size to say no more than 10 files to avoid memory issues, depending on your file sizes etc.
When logging on the watch, use the sensor provided event handlers such as "onreading" rather than setInterval, interval times are not accurate anyway, best to just grab a timestamp from the Date function inside the event handlers and work it out from there.
Ive managed to log and upload a continuous stream of heart rate readings overnight without issue. I initially had some "out of memory" issues as my app was already consuming most the 64KB of available JS memory before i added the logging functionality.
What kind of sensor data are you wanting to log?
04-20-2021 11:48
04-20-2021 11:48
It sounds like either your watch app or your companion app is being killed for some reason, for the watch app maybe it is crashing due to an unhandled javascript exception or is "out of memory" or maybe you have not set "me.appTimeoutEnabled" to false. For the companion app, it's preferred state is not to be running unless it needs to.
I have managed to successfully log and send heart rate data to a server using the File Transfer API to send data to the companion app which then uses fetch to post the data to the server (using a previously obtained JWT from a login form on the companion)
The File Transfer API is the only reliable way to transmit data to the companion app, the Messaging API (peer sockets) only works while the companion is running, which most of the time means you have to be looking at the companion setting page on the phone and the phone screen is on. You could set an aggressive wake interval on the companion but not recommended as it could impact the phone battery life. Messaging will also fail if the phone is out of bluetooth range with the watch, is in flight mode or bluetooth is off etc.
The File Transfer API queues the outgoing files until the phone is available, but make sure you limit the queue size to say no more than 10 files to avoid memory issues, depending on your file sizes etc.
When logging on the watch, use the sensor provided event handlers such as "onreading" rather than setInterval, interval times are not accurate anyway, best to just grab a timestamp from the Date function inside the event handlers and work it out from there.
Ive managed to log and upload a continuous stream of heart rate readings overnight without issue. I initially had some "out of memory" issues as my app was already consuming most the 64KB of available JS memory before i added the logging functionality.
What kind of sensor data are you wanting to log?
04-20-2021 17:44
04-20-2021 17:44
Thanks so much Chris. This is super helpful. I will switch my entire system from Messaging API to FileTransfer then. I am logging Heart Rate and Acceleration and I need data for that for every second basically which will definitely cause some battery life issues. What do you mean by logging functionality in the last line ... also do you mind sharing a snippet of the code you used to collect data overnight successfully. It will help me out a lot.