10-12-2017 05:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-12-2017 05:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
It appears often that the companion app is not ready to receive a message request and nothing is returned when queried. I understand that it will happen again at a later time due to my setInterval checking the weather every half hour, but is it possible to keep trying to get a response from the companion app? That is, using a loop until it returns something? Otherwise, my app starts and nothing is returned for the weather, then the user will have to wait half an hour before getting the weather info. Or will the continual running the function and messaging queries use too much resources?
I have console log files for the watch app along with the companion app. At times, I see logged "Sending query to companion app" and nothing happens (companion app is not ready yet?).

10-13-2017 19:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-13-2017 19:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
It seems my problem may be due to messaging.peerSocket.onopen often not executing. If I keep reinstalling the app from Studio > RUN, eventually it works.

10-13-2017 20:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-13-2017 20:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
My experience is that the first time I run, it works.
Then it progressively gets bad, and I have to run it 2, then 3, then 4.5.6 times.
Until I decide to close the project, reopen it, reconnect everything and again we go...

10-13-2017 20:33
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-13-2017 20:33
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Yeah. It's a bit annoying during dev, but so long as this is not the final user experience, I'm okay to keep retrying. I have an idea that once it's worked once it'll keep going, but if it doesn't work the first time it never will.
I have my code set up to retry the connection test every 10 seconds but the socket is never ready if it isn't the first time.

10-14-2017 03:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-14-2017 03:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
A few things:
- Can you let us know if you're OS/Model/Version phone you're using?
- Version number of the Fitbit mobile app?
If you're coding a clock face, switch it to an app in package.json, then when you install, if the companion doesn't start, try exiting the app on the device, then launch it again. Does the companion start then?
Thanks!

10-14-2017 03:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-14-2017 03:45
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Android 7.0/Galaxy S8
Fitbit app: v 2.59 (2193184)
Will try the App thing and get back to you.

10-14-2017 04:12 - edited 10-14-2017 04:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-14-2017 04:12 - edited 10-14-2017 04:14
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I now get "Error installing app". "Build failed" and in Build Messages "Wipe color must be a valid hex color".
Never mind. Found where to set that.

10-14-2017 04:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-14-2017 04:36
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I am on a google pixel with Oreo (8.0.0)
Fitbit app: v 2.59 (2193184)
I am developing as an App. As described before, first time is perfect, then it deteriorates the messaging behavior. The companion starts, opens the connection, but it won't send the message through. I close the app on the watch, and run it again. Sometime it takes a few tries. As a watch face seems to work better.
I coded using the code on the messaging guide.

10-14-2017 05:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-14-2017 05:03
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I have a lot of console logging going.
Here's the sequence I should see:
App Started (studio log)
Sending WEATHER command to companion app
Sent it
Weather request received in companion app
Querying openweather...
Received data from Companion app
Temperature is 18C
> Then it sets that onscreen
Second time I reinstalled the code as an App instead of Clockface:
App started
Socket not ready!
Sending WEATHER command to companion app
Sent it!
In the next 14 minutes, I did not see "Sending WEATHER command to companion app". This log appears in this function:
// Listen for messages from the device messaging.peerSocket.onmessage = function(evt) { if (evt.data && evt.data.command == "weather") { // The device requested weather data console.log("Weather request received in companion app"); queryOpenWeather(); } }
So, the companion app doesn't seem to receive the command.
I've never seen messaging.peerSocket.onerror function execute.
I added extra logging to test with now.
Next test, it worked after a 10 second retry gap.
Next test, it worked after a 10 second retry gap.
Next test:
App started!
Socket not ready!
- [22:26:40]Loaded and evaluated: file:///android_asset/bootstrap.js[HOST]
- [22:26:40]Loaded and evaluated: file:///data/user/0/com.fitbit.FitbitMobile/app_companions/5ba2f384-49f5-413b-a0a1-f23a5d36c350/0x06b2f61e51837d1a/companion.js
Sending WEATHER command to companion app
Sent it!
Weather request received in companion app
Querying openweather...
Received data from companion app
Switching to clockface app.
App started
Socket not ready!
Sending WEATHER command to companion app
Sent it!
No log of "Weather request received in companion app" happened at all. Gave up waiting after 12 minutes.
Installed again as app. Worked immediately.
[22:33:32]App Started[HOST] [22:33:32]Loaded and evaluated: file:///android_asset/bootstrap.js[HOST] [22:33:32]Loaded and evaluated: file:///data/user/0/com.fitbit.FitbitMobile/app_companions/5ba2f384-49f5-413b-a0a1-f23a5d36c350/0x0bb996420db45379/companion.js[HOST] [22:33:32]Socket not ready!common/weather.js:21 [22:33:37]Sending WEATHER command to companion appcommon/weather.js:15 [22:33:37]Sent it! :Dcommon/weather.js:19 [22:33:38]Weather request received in companion appcompanion/index.js:64 [22:33:39]Latitude: -31.901818 Longitude: 152.4449007companion/index.js:16 [22:33:39]Querying openweather...companion/index.js:21 [22:33:39]MAINTEMP=291.15companion/index.js:33 [22:33:41]Received data from Companion appcommon/weather.js:38 [22:33:40]The temperature is: 291.15common/weather.js:28 [22:33:40]UNITS.temp= C : UNITS= 18
Hope that helps!

10-14-2017 05:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-14-2017 05:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
This log may help as well:
[23:14:56]App Started[HOST]
[23:14:57]Socket not ready!common/weather.js:21
[23:15:02]Socket not ready!common/weather.js:21
[23:15:08]Socket not ready!common/weather.js:21
[23:15:12]Socket not ready!common/weather.js:21
[23:15:17]Socket not ready!common/weather.js:21
[23:15:19]Loaded and evaluated: file:///android_asset/bootstrap.js[HOST]
[23:15:19]Loaded and evaluated: file:///data/user/0/com.fitbit.FitbitMobile/app_companions/5ba2f384-49f5-413b-a0a1-f23a5d36c350/0x0c9102c280738c10/companion.js[HOST]
[23:15:23]Sending WEATHER command to companion appcommon/weather.js:15
[23:15:23]Sent it! 😄common/weather.js:19
[23:15:23]Weather request received in companion appcompanion/index.js:64
[23:15:24]Latitude: -31.9018439 Longitude: 152.4449236companion/index.js:16
[23:15:24]Querying openweather...companion/index.js:21
[23:15:25]Cond=803companion/index.js:33
[23:15:26]Received data from Companion appcommon/weather.js:55
[23:15:26]The temperature is: 291.15common/weather.js:28
[23:15:26]Conditions=601common/weather.js:32
[23:15:43]App Closed

10-28-2017 03:55
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-28-2017 03:55
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I can't get it to detect the peer socket open at all any more. None of my apps can communicate with their companion app. It's very frustrating.
Currently testing by having it retry every 5 seconds but it never opens so the command can never be sent:
// Request weather data from the companion export function fetchWeather() { console.log("Fetching weather"); if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) { // Send a command to the companion messaging.peerSocket.send({ command: 'weather' }); } else { console.log("Peer Socket closed *sigh*") setTimeout(fetchWeather, 5 * 1000) } }
[21:49:55]App Started[HOST] [21:49:55]Fetching weathercommon/weather.js:8 [21:49:55]Peer Socket closed *sigh*common/weather.js:14 [21:50:00]Fetching weathercommon/weather.js:8 [21:50:00]Peer Socket closed *sigh*common/weather.js:14 [21:50:06]Fetching weathercommon/weather.js:8 [21:50:06]Peer Socket closed *sigh*common/weather.js:14 [21:50:10]Fetching weathercommon/weather.js:8 [21:50:10]Peer Socket closed *sigh*common/weather.js:14 [21:50:15]Fetching weathercommon/weather.js:8 [21:50:16]Peer Socket closed *sigh*common/weather.js:14 [21:50:21]Fetching weathercommon/weather.js:8 [21:50:21]Peer Socket closed *sigh*

10-28-2017 03:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-28-2017 03:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
The companion app Status is always either Inactive or Unavailable. What causes this? It may be the issue.

12-05-2017 22:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


12-05-2017 22:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I'm suffering this problem too. Firmware 27.30.5.16, Android Fitbit app 2.62.1.
It almost seems as though a pool of connections is getting exhausted because individual connections are not being closed when they're no longer required. This would explain the gradual but inconsistent deterioration.
Gondwana Software

12-06-2017 04:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

12-06-2017 04:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
My companion seems to never refresh data. I have three apps doing the same thing (with the same code) and they all are showing inconsistent behavior

