Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Here's a minimal example, check it's working for you:
device/index.js
import * as messaging from "messaging";
messaging.peerSocket.onopen = function() {
console.log(`Device OPEN`);
sendMessage();
}
messaging.peerSocket.onerror = function(err) {
console.log(`Device ERROR: ${err.code} ${err.message}`);
}
function sendMessage() {
console.log(`Device SEND`);
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
messaging.peerSocket.send({cmd: "ping!"});
} else {
console.log("Dude, where's my peerSocket?");
}
}
companion/index.js
import * as messaging from "messaging";
messaging.peerSocket.onopen = function() {
console.log(`Companion OPEN`);
}
messaging.peerSocket.onerror = function(err) {
console.log(`Companion ERROR: ${err.code} ${err.message}`);
}
messaging.peerSocket.onmessage = function(evt) {
console.log(`Companion MESSAGE: ${JSON.stringify(evt.data)}`);
}
Best AnswerActually I have the same problem.
When connecting to the simulator, your minimal example works.
However, using my Versa 2, it no longer works. The onopen isn't even called.
Remark to my own post: I solved the issue. 'Solved', since I removed the dev apps, restarted my iPhone and reinstalled the app again. Then it works.
Something to look at for the fitibit devs! 😉
Best Answer