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

Odd companion behaviour

ANSWERED

Can anyone explain this weird repetitive behaviour?

 

1) Companion code

 

console.log("I'm in the companion");
setTimeout(sendFile, 2000);

 

function sendFile() {
console.log("Companion Sending file...");
let data = new Uint8Array(26);
for (let counter = 0; counter < data.length; counter++) {
data[counter] = "a".charCodeAt(0) + counter;
}
outbox.enqueue("alphabits.txt", data);
}

 

inbox.onnewfile = () => {
console.log("companion New file!");
let fileName = null;
do {
// If there is a file, move it from staging into the application folder
fileName = inbox.nextFile();
if (fileName) {
console.log(`Received File: <${fileName}>`);
let data = fs.readFileSync(fileName, "ascii");
statusText.text = `Received: ${data}`;
}
} while (fileName);
};
console.log("I'm out of the companion");

 

2) Output:::

 

[18:29:50]Launch complete - durations: foregrounding(440ms), first paint(51ms), total(560ms). companion/index.js:4,1
[18:29:51]I'm in the companion companion/index.js:4,1
[18:29:51]I'm in the companion companion/index.js:4,1
[18:29:51]I'm in the companion companion/index.js:4,1
[18:29:51]I'm in the companion companion/index.js:4,1
[18:29:51]I'm in the companion companion/index.js:4,1
[18:29:51]I'm in the companion companion/index.js:4,1
[18:29:51]I'm in the companion companion/index.js:4,1
[18:29:51]I'm in the companion companion/index.js:33,1
[18:29:51]I'm out of the companion companion/index.js:33,1
[18:29:51]I'm out of the companion companion/index.js:33,1
[18:29:51]I'm out of the companion companion/index.js:33,1
[18:29:51]I'm out of the companion companion/index.js:33,1
[18:29:51]I'm out of the companion companion/index.js:33,1
[18:29:51]I'm out of the companion companion/index.js:33,1
[18:29:51]I'm out of the companion companion/index.js:33,1
[18:29:51]I'm out of the companion companion/index.js:8,3
[18:29:53]Companion Sending file... companion/index.js:8,3
[18:29:53]Companion Sending file... companion/index.js:8,3
[18:29:53]Companion Sending file... companion/index.js:8,3
[18:29:53]Companion Sending file... companion/index.js:8,3
[18:29:53]Companion Sending file... companion/index.js:8,3
[18:29:53]Companion Sending file... companion/index.js:8,3
[18:29:53]Companion Sending file... companion/index.js:8,3
[18:29:53]Companion Sending file... app/index.js:75,3
[18:29:56]New file! app/index.js:81,7
[18:29:56]Received File: <alphabits.txt>

 

 

 

 

Author | ch, passion for improvement.

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Possibly. I've seen rare cases where the Fitbit mobile app can start multiple instances of the companion code (only one of which is 'connected' to the device app). This can make for some VERY strange bugs.

Restarting something makes it go away.

 

An alternative is that you may have multiple instances of the sim running. That also shouldn't be possible, but can happen. Close all visible sim windows, then check running processes to see if any sim stuff remains.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
0 Votes
3 REPLIES 3

Possibly. I've seen rare cases where the Fitbit mobile app can start multiple instances of the companion code (only one of which is 'connected' to the device app). This can make for some VERY strange bugs.

Restarting something makes it go away.

 

An alternative is that you may have multiple instances of the sim running. That also shouldn't be possible, but can happen. Close all visible sim windows, then check running processes to see if any sim stuff remains.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Shutdown the Simulator  and restarted

 

Result!

[20:50:15]Launch complete - durations: foregrounding(386ms), first paint(45ms), total(571ms).companion/index.js:4,1
[20:50:16]I'm in the companion companion/index.js:29,1
[20:50:16]I'm out of the companion companion/index.js:8,3
[20:50:18]Companion Sending file... app/index.js:75,3
[20:50:21]New file! app/index.js:81,7
[20:50:21]Received File: <alphabits.txt> app/index.js:81,7

 

Author | ch, passion for improvement.

Best Answer

That looks a wee bit better! 🙂

Peter McLennan
Gondwana Software
Best Answer