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

Having a Problem Messaging the companion

I am currently running code using the Fitbit Ionic, and for some reason, my messaging stopped working; everything was running fine last week, and now all of a sudden, this line below won't work. The connection remains closed. Please provide advice on how to troubleshoot to see why the Fitbit stop communicating with the companion:

 

/messaging.peerSocket.readyState === messaging.peerSocket.OPEN

Best Answer
10 REPLIES 10

Hi @Mike84  -  it's possible that the bridge can get into a corrupted state when performing many tests.

Try logging out and eliminating any duplicate versions and restarting all the components to work with a fresh copy.

Author | ch, passion for improvement.

Best Answer

Hi @Guy_, when you say that the bridge could be in a corrupted state when performing many tests, are you saying that something has happened on the companion side and that I should log out of the Fitbit app on the device or turn the app off on the Fitbit. 

Best Answer

Also, @Guy_, thank you for your response! This code below is how I found out the connection wasn't working. I wondered if it would cause this line down below to execute every time.

 

if (messaging.peerSocket.readyState === messaging.peerSocket.CLOSED) {
console.error("Error: Connection is not open");

}

Best Answer
0 Votes

@Guy_, I tried logging out of the system like you suggested (I believe I interpreted what you said correctly) that didn't seem to work, I also wanted to force it open, but that didn't seem to work either by following the suggested code:

 

https://community.fitbit.com/t5/SDK-Development/PeerSocket-onopen-seems-to-working-only-if-I-launch-...

 

Are there any other steps that I might be able to take?

Best Answer

@Mike84  - it depends how you are using it. There is the OS Simulator, phone developer bridge, watch developer bridge, private link / public link install.

 

It may require restarting watch, phone, simulator to clear an issue or it may be something else.

Author | ch, passion for improvement.

Best Answer

@Guy_ - I tried to restart the watch and phone. I also erased all program instances from the watch, simulator, and phone to clear the bridges. The private link/ public link install is that something that is used in Fitbit studio? I'm not sure if I executed all you mentioned above, but I believe that I have, and it didn't work. I also tried to force the channel open here is the snippet of code that I have been trying to adjust in my code:

 

messaging.peerSocket.onopen = function() {

console.log("connection open for sendMessageHeart")
// Ready to send messages
sendMessageHeart();
}

// Listen for the onerror event
messaging.peerSocket.onerror = function(err) {
// Handle any errors
console.log("Connection error: " + err.code + " - " + err.message);
}
function sendMessageHeart() {


// Sample data
var dataA;
var dataC;
//The actual time sent to thingspeak
if(sentHeart[1]==60)
dataC = [60,sentHeart[0]];
else
dataC = [30,sentHeart];

if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
// Send the data to peer as a message
messaging.peerSocket.send(dataC);
}
else {//trying to open a connection by force to see if this is the problem
messaging.peerSocket.onopen = () => {
console.log("Data sent");
messaging.peerSocket.send(dataC)
}
}
if (messaging.peerSocket.readyState === messaging.peerSocket.CLOSED) {
console.error("Error: Connection is not open");


}
}

Best Answer

@Mike84  - The private link/ public link install is from the Gallery App Manager but you may not have got that far.

 

Seem like you have done everything to clear any residual problem. Maybe @Gondwana has more of an idea and can reply.

Author | ch, passion for improvement.

Best Answer

@Guy_, thanks for the help. @Gondwana  or @JonFitbit, do you have any suggestions for me? I appreciate any help you can provide. 

Best Answer

@Guy_, my phone updated, and now it's starting to work, so I guess that was the problem. I appreciate your help. 

Best Answer

@Mike84  - thanks, had a similar mysterious problem! Good it's ok now.

Author | ch, passion for improvement.

Best Answer