06-02-2019 12:34
06-02-2019 12:34
Hi,
I'm developing an app on the Versa that continuously collects sensor data. This data is transferred through the messaging protocol to the smartphone Companion app which later on transfers it to a server with fetch() over https. All of this is working fine already!
My only problem is that the Companion app closes after a while or when bluetooth connection is lost. Losing the connection from the watch to the smartphone doesn't matter, because I buffer data locally on the watch and Companion app until a connection can be established.
My problem however is, that the Companion app never comes back alive. The messaging protocol on the smartwatch app never reconnects and I also haven't found a way to force the Companion app to wake up. I've already tried the wakeInterval decribed here without any luck: https://dev.fitbit.com/build/guides/companion/
The debugging output of Fitbit studio says that the Companion app lost connection and closes. Any idea how I can enforce the Companion app to wake up from time to time? Also thanks in advance! 🙂
All the best,
Thomy
Answered! Go to the Best Answer.
06-04-2019 11:54
06-04-2019 11:54
Thanks! I'll rely on the fact that if the phone is close the messaging protocol will reconnect at some point. Is there any info on how long it could take? I've already implemented something similar like fitbit-asap myself.
I rely on the flag on my Fitbit app:
messaging.peerSocket.readyState === messaging.peerSocket.OPEN
Would it be better (as in fitbit-asap) to just send within a try-catch block?
try { peerSocket.send(message) } catch (error) { debug && console.log(error) }
Thanks a lot for the info so far!
06-03-2019 16:13
06-03-2019 16:13
Some mobile devices can be quite aggressive with their memory management. Can you check that it's not being suspended, or on iOS that it has background permission?
06-04-2019 00:42
06-04-2019 00:42
The smartphone I'm using is an Honor 10 Lite with Android 9.0. I don't think the app is closed, because waking up the phone immediately shows the app without a loading screen or anything.
I am getting somewhat of undefined behavior from the Companion app, which makes it really difficult to connect and exchange data with the Fitbit watch:
[9:09:44 AM]Sideload successful! [9:09:46 AM]App Started [9:09:47 AM]Loaded and evaluated: file:///android_asset/bootstrap.js [9:09:47 AM]Loaded and evaluated: file:///data/user/0/com.fitbit.FitbitMobile/app_companions/dbf77543-e231-422a-a051-59d9ce1bb19c/0x08251cce1db1464b/companion.js [9:09:47 AM]Companion launched by [launchedOnTracker] [9:09:48 AM]err: Couldn't find file: _settings [9:09:48 AM]Companion Socket Opened [9:11:59 AM]App closed on device, unloading companion in 3 seconds… [9:12:02 AM]Unloading companion… [9:12:04 AM]Companion unloaded [9:15:33 AM]Loaded and evaluated: file:///android_asset/bootstrap.js [9:15:33 AM]Companion woken up. [9:15:34 AM]Loaded and evaluated: file:///data/user/0/com.fitbit.FitbitMobile/app_companions/dbf77543-e231-422a-a051-59d9ce1bb19c/0x08251cce1db1464b/companion.js [9:15:34 AM]Companion launched by [wakeUp], unloading companion in 15 seconds… [9:15:49 AM]Unloading companion… [9:15:51 AM]Companion unloaded [9:17:25 AM]Loaded and evaluated: file:///android_asset/bootstrap.js [9:17:25 AM]Loaded and evaluated: file:///data/user/0/com.fitbit.FitbitMobile/app_companions/dbf77543-e231-422a-a051-59d9ce1bb19c/0x08251cce1db1464b/companion.js [9:17:25 AM]Companion launched by [launchedOnTracker] [9:17:25 AM]Companion Socket Opened [9:20:30 AM]App closed on device, unloading companion in 3 seconds… [9:20:33 AM]Unloading companion… [9:20:35 AM]Companion unloaded [9:23:39 AM]Loaded and evaluated: file:///android_asset/bootstrap.js [9:23:39 AM]Companion woken up. [9:23:39 AM]Loaded and evaluated: file:///data/user/0/com.fitbit.FitbitMobile/app_companions/dbf77543-e231-422a-a051-59d9ce1bb19c/0x08251cce1db1464b/companion.js [9:23:39 AM]Companion launched by [wakeUp], unloading companion in 15 seconds… [9:23:54 AM]Unloading companion… [9:23:56 AM]Companion unloaded [9:29:56 AM]Loaded and evaluated: file:///android_asset/bootstrap.js [9:29:56 AM]Companion woken up. [9:29:56 AM]Loaded and evaluated: file:///data/user/0/com.fitbit.FitbitMobile/app_companions/dbf77543-e231-422a-a051-59d9ce1bb19c/0x08251cce1db1464b/companion.js [9:29:56 AM]Companion launched by [wakeUp], unloading companion in 15 seconds… [9:30:11 AM]Unloading companion… [9:30:13 AM]Companion unloadedWhenever "App closed on device..." appears I've temporarily switched off bluetooth on my smartphone. I do this to test reconnecting the Companion app. The very first time at 9:15 it will reconnect shortly after. However it does not open and use the Messaging protocol. So no data transfer can happen. At 9:17 the Companion app seems to start itself because of a [launchedOnTracker] event (I haven't touched the watch) and starts data transfer. 3 minutes later I switch off blue tooth again to try get the same behavior but it doesn't happen anymore. The companion app is woken up every few minutes but is unable to do any data transfer.
06-04-2019 09:44
06-04-2019 09:44
In theory, if your app is running, then your companion should also be running. In reality, the companion does get suspended, but should be woken when you send messages from the device. The peersocket connect will only happen once, so you shouldn't need to check the state after that point, just send messages and they should get through.
This is a really handy package which may make your life easier https://www.npmjs.com/package/fitbit-asap
wakeInterval does open the companion, but it will be suspended again after 15 seconds I think.
06-04-2019 11:54
06-04-2019 11:54
Thanks! I'll rely on the fact that if the phone is close the messaging protocol will reconnect at some point. Is there any info on how long it could take? I've already implemented something similar like fitbit-asap myself.
I rely on the flag on my Fitbit app:
messaging.peerSocket.readyState === messaging.peerSocket.OPEN
Would it be better (as in fitbit-asap) to just send within a try-catch block?
try { peerSocket.send(message) } catch (error) { debug && console.log(error) }
Thanks a lot for the info so far!