07-20-2018 09:11 - edited 07-20-2018 10:50
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-20-2018 09:11 - edited 07-20-2018 10:50
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Edit: I'm having some trouble formatting this post so bear with me.
It seems like my Versa has become incapable of receiving messages from the companion. I'm running a simplified version of the Weather code shown on the Message Guide: https://dev.fitbit.com/build/guides/communications/messaging/
Instead of printing the weather, it just prints "The data is hello" to the console.
Here is an excerpt of the code in app:
function fetchWeather() {
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
// Send a command to the companion
console.log("sending request");
messaging.peerSocket.send({
command: 'weather'
});
}
}
// Display the weather data received from the companion
function processWeatherData(data) {
console.log("The data is: " + data);
}
// Listen for the onopen event
messaging.peerSocket.onopen = function() {
// Fetch weather when the connection opens
fetchWeather();
console.log("device open");
}
// Listen for messages from the companion
messaging.peerSocket.onmessage = function(evt) {
console.log("received message");
if (evt.data) {
processWeatherData(evt.data);
}
}
And here is some code from the companion:
function queryOpenWeather() {
console.log("sending message");
returnWeatherData("hello");
}
// Send the weather data to the device
function returnWeatherData(data) {
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
// Send a command to the device
messaging.peerSocket.send(data);
} else {
console.log("Error: Connection is not open");
}
}
// Listen for messages from the device
messaging.peerSocket.onmessage = function(evt) {
console.log("received request");
if (evt.data && evt.data.command == "weather") {
// The device requested weather data
queryOpenWeather();
}
}
I'm getting the console printouts:
Answered! Go to the Best Answer.

Accepted Solutions
07-21-2018 10:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-21-2018 10:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Bluetooth messaging has always been a bit unreliable: though with the latest firmware things are much better than what originally shipped with Ionic, the initial handshake between app launching and the companion fails fairly often. Have you tried killing and relaunching your app again?
If it's more consistent than that (i.e. always does this) you might have found an actual bug.

07-21-2018 10:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-21-2018 10:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Bluetooth messaging has always been a bit unreliable: though with the latest firmware things are much better than what originally shipped with Ionic, the initial handshake between app launching and the companion fails fairly often. Have you tried killing and relaunching your app again?
If it's more consistent than that (i.e. always does this) you might have found an actual bug.

07-21-2018 12:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-21-2018 12:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I tried a few things: exiting and relaunching the app, resetting the FitBit, restarting FitBit Studio and reinstalling the app, and deleting and reinstalling the app.

