12-12-2023 08:01
12-12-2023 08:01
Hello All,
I'm not sure where I should notify folks about this, but I have a 'bug' for either the 7.2.0-pre.0 sdk or the 1.8.11-pre.11 sdk-cli. I don't know whether the error resides in the sdk or sdk-cli code. If folks can help me determine this, I will write a ticket for the code on github. I am trying to write code for a Sense 2/Versa 4.
I have written the following code for the app...
import * as fs from "fs";
import * as messaging from "messaging";
// #7
function processGPSData(data) {
if (!fs.existsSync("/private/data/fitbit-planets.json")) {
cacheData(data.latitude, data.longitude, 0);
} else {
cacheData(data.latitude, data.longitude, 1);
}
}
// #2
function fetchGPSData() {
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
// Send a command to the companion
console.log("sending request");
messaging.peerSocket.send({
command: 'coordinates'
});
}
}
// #1
messaging.peerSocket.onopen = function() {
console.log("messaging open");
fetchGPSData();
}
// Listen for messages from the companion
// #4
messaging.peerSocket.onmessage = function(evt) {
console.log("received message");
if (evt.data) {
processGPSData(evt.data);
}
}
and this block for the companion...
import * as messaging from "messaging";
import { geolocation } from "geolocation";
function locationSuccess(position) {
const data = {
latitude: position.coords.latitude,
longitude: position.coords.longitude
};
returnGPSCoordinates(data);
}
function locationError(error) {
console.log("Error: " + error.code, "Message: " + error.message);
}
var geoOptions = {
enableHighAccuracy: false,
maximumAge : 0,
timeout : Infinity,
};
// #5
function launchGeoLocation() {
console.log("sending message");
geolocation.getCurrentPosition(locationSuccess, locationError, geoOptions);
}
// Send the GPS data to the device
// #6
function returnGPSCoordinates(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
// #3
messaging.peerSocket.onmessage = function(evt) {
console.log("received request");
if (evt.data && evt.data.command == "coordinates") {
// The device requested GPS data
launchGeoLocation();
}
}
This code runs properly under the Fitbit OS Simulator-stable-0.9.4.exe when running with sdk 6.1.0 and sdk-cli 1.7.3. That is one iteration of message passing occurs and then the app waits.
[7:15:33 PM] App: App Closed
[7:15:34 PM] App: App Started
[7:15:34 PM] App: Launch complete - durations: foregrounding(77ms), first paint(40ms), total(525ms).
[7:15:34 PM] App: messaging open (app/index.js:626,3)
[7:15:34 PM] App: sending request (app/index.js:617,5)
[7:15:34 PM] Companion: received request (companion/index.js:46,4)
[7:15:34 PM] Companion: sending message (companion/index.js:28,4)
[7:15:35 PM] App: received message (app/index.js:633,4)
[7:15:35 PM] App: Cache file doesn't exist (app/index.js:569,5)
[7:15:35 PM] App: latitude = 48.13194 (app/index.js:570,5)
[7:15:35 PM] App: longitude = 11.54944 (app/index.js:571,5)
[7:15:35 PM] App: flag = 0 (app/index.js:572,5)
Under 7.2.0-pre.0 and 1.8.0-pre.11 the code runs twice and then stops, waits for a few seconds and part of the code crashes with a MethodCallTimeout.
[9:40:07 AM] Companion: Loaded and evaluated: file:///android_asset/bootstrap.js (js-engine-bootstrap.html:9,1)
[9:40:07 AM] Companion: Loaded and evaluated: file:///data/user/0/com.fitbit.FitbitMobile/app_companions/4b678716 - 7e8e-4259 - 893d-d4b026e3c4a5/0x064168bee85f0242/companion.js (js-engine-bootstrap.html:9,1)
[9:40:07 AM] Companion: Companion launched by [launchedOnTracker]
[9:40:08 AM] App: messaging open (app/index.js:626,3)
[9:40:08 AM] App: sending request (app/index.js:617,5)
[9:40:08 AM] Companion: received request (companion/index.js:45,1)
[9:40:08 AM] Companion: sending message (companion/index.js:47,8)
[9:40:09 AM] App: received message (app/index.js:633,4)
[9:40:09 AM] App: Cache file doesn't exist (app/index.js:569,5)
[9:40:09 AM] App: latitude = 45.3656782 (app/index.js:570,5)
[9:40:09 AM] App: longitude = -75.7895867 (app/index.js:571,5)
[9:40:09 AM] App: flag = 0 (app/index.js:572,5)
[9:40:09 AM] App: messaging open (app/index.js:626,3)
[9:40:09 AM] App: sending request (app/index.js:617,5)
[9:40:10 AM] Companion: received request (companion/index.js:45,1)
[9:40:10 AM] Companion: sending message (companion/index.js:47,8)
[9:40:10 AM] App: received message (app/index.js:633,4)
[9:40:10 AM] App: Cache file already exists, file data(app/index.js:583,5)
[9:40:10 AM] App: GPSData.latitude = 45.3656782 (app/index.js:584,5)
[9:40:10 AM] App: GPSData.longitude = -75.7895867 (app/index.js:585,5)
[9:40:10 AM] App: flag = 1 (app/index.js:586,5)
[9:40:10 AM] App: No need to update cache file (app/index.js:588,7)
MethodCallTimeout: No response received for RPC call to 'app.launchComponent'
at Timeout.<anonymous> (/home/chris/src/javascript/fitbit-planets/node_modules/@fitbit/jsonrpc-ts/lib/peer.js:197:64)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7)
[9:40:27 AM] App: messaging open (app/index.js:626,3)
[9:40:27 AM] App: sending request (app/index.js:617,5)
[9:40:27 AM] Companion: received request (companion/index.js:45,1)
[9:40:27 AM] Companion: sending message (companion/index.js:47,8)
[9:40:28 AM] App: received message (app/index.js:633,4)
[9:40:28 AM] App: Cache file already exists, file data(app/index.js:583,5)
[9:40:28 AM] App: GPSData.latitude = 45.3656782 (app/index.js:584,5)
[9:40:28 AM] App: GPSData.longitude = -75.7895867 (app/index.js:585,5)
[9:40:28 AM] App: flag = 1 (app/index.js:586,5)
[9:40:28 AM] App: No need to update cache file (app/index.js:588,7)
[9:42:12 AM] Companion: App closed on device, unloading companion in 3 seconds…
[9:42:15 AM] Companion: Unloading companion…
[9:42:17 AM] Companion: Companion unloaded
Any ideas on how to fix this are welcome.
Thanks in advance.
Chris
12-12-2023 10:11
12-12-2023 10:11
HI @chrisjohgorman - there are quite a few things that don't work [crash] on a Sense 2 or Versa 4 as already noted and without any formal documentation you can only guess what may be going wrong.
It is doubtful that reporting issues with undocumented things will get any response from Fitbit. I had no success. Without the formal documentation you are a pioneer!
Author | ch, passion for improvement.
12-12-2023 13:40
12-12-2023 13:40
12-12-2023 13:47
12-12-2023 13:47
Kinda feels like a firmware issue to me. I don't know of any way to report those.
12-12-2023 14:08
12-12-2023 14:08