Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

messaging.peerSocket.onmessage not responding

ANSWERED

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:

app/index.js:8,5[11:06:31 AM]sending request
app/index.js:24,3[11:06:31 AM]device open
companion/index.js:22,1[11:06:35 AM]received request
companion/index.js:6,1[11:06:35 AM]sending message
 
but I never get the "received message" response.  I tried reversing the code in app and companion and the app still refuses to respond when the companion sends a request.  Does anyone know what might be the problem?  Thanks for helping!

 

 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

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.

View best answer in original post

Best Answer
0 Votes
2 REPLIES 2

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.

Best Answer
0 Votes

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.

Best Answer
0 Votes