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

sdk 7.2.0-pre.0 or sdk-cli 1.8.0-pre.11 run app and companion code twice and then crash

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

Best Answer
0 Votes
4 REPLIES 4

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.

Best Answer
0 Votes
Thanks @Guy_,

The only reason I am a pioneer is that I have a sense 2 and want to
have my old versa 1 app ported to it. 🙂 It does work well enough for
me to use, and I can sideload it now, so problem solved. Sort of. I
would like to make it available to others, so I try to pitch at the
wind.

I have two bugs to attribute to the fitbit github page, only I don't
know which project the bugs belong to. I think they are both the sdk
and not the sdk-cli, but I'm not sure.

Take care,

Chris
Best Answer
0 Votes

Kinda feels like a firmware issue to me. I don't know of any way to report those.

Peter McLennan
Gondwana Software
Best Answer
0 Votes
Hi @Gondwana,

Thanks for the suggestion, I will keep it in mind. (I just got a
firmware update for my Sense 2, it's now 60.20001.194.86 .) I
believe, however, that the behaviour was the same on the previous
firmware.

Thanks for the help.

Chris
Best Answer
0 Votes