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

Companion Error Code - 2 'invalidState' after 15 sec

Hi guys,

 

I am getting communication issues between the companion and the watch in SDK 4.2 and SDK 5.

 

On the simulator, there is no issue. However, on a real device I run into communication problems.

 

When I try and change multiple settings for a watch face, the companion appears to stop communicating with the watch. Initially the watch receives the settings changes. The companion then closes and when it re-opens and I try to change a setting, I get an error code '2 - invalidState'.

 

It appears that the watch loses a connection to the phone after the companion unloads after 15 seconds from first loading.

 

I have to open a watch app such as 'timer', close the 'timer' app and then return to the clock face. This sometimes helps reset the communication, but not always.

 

Any idea what I am doing wrong or how I can fix this?

 

I have added my companion file below.

 

Thanks.

 

Companion - index.js

 

 

 

import { me }               from 'companion';
import { settingsStorage }  from 'settings';
import * as messaging       from 'messaging';

console.log("Companion started...");


// Open connection listener
messaging.peerSocket.addEventListener("open", () => {
  console.log("Communication onOpen called!");
  restoreSettings();  
});


// A user changes settings
settingsStorage.onchange = evt => {
  let data = {
    key: evt.key,
    newValue: evt.newValue
  };
  sendVal(data);
};

// Restore any previously saved settings and send to the device
function restoreSettings() {
  for (let index = 0; index < settingsStorage.length; index++) {
    let key = settingsStorage.key(index);
    if (key) {
      let data = {
        key: key,
        newValue: settingsStorage.getItem(key)
      };
      sendVal(data);
    }
  }
}


// Send data to device
function sendVal(data) {
  if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
    messaging.peerSocket.send(data);
  }
}

// Close event listener
messaging.peerSocket.addEventListener("close", (evt) => {
  console.log("Communication onClose called: " + JSON.stringify(evt));
});

// Error event listener
messaging.peerSocket.addEventListener("error", (err) => {
  console.log("Communication onError called: " + err.code + " - " + err.message);
});

 

 

 

 

Best Answer
9 REPLIES 9

My clockface upgrade to SDK5 was just rejected for exactly the same reason.  I was assuming there was an error in my code (but it is fine in SDK 4.2).  I just tried migrating the SDK Moment example clock to SDK 5 and I get exactly the same problem:  In the simulator it is fine (as is my Clarity clockface), but when it is sideloaded, the 15 second timer kills it.

 

Companion launched by [settingsChanged], unloading in 15.0 seconds... 

 

 

 

 

Best Answer
0 Votes

This is a known issue. In some circumstances, the companion component closes after 15 seconds and doesn't automatically restart.

 

It seems to be intermittent. If you can pin down that exact circumstances that cause it (or don't), that could be helpful.

Peter McLennan
Gondwana Software
Best Answer

Hi Peter,

 

Thanks for the note.

 

OK, good to hear it is a known issue. It makes getting new watches that have any companion settings difficult to pass the review.

 

I have tried it on a physical Versa 3 with several watch faces.

 

I also tested it on some of the sample clock faces,  e.g. Analog Stats from the github repository https://github.com/pmccrthy/fitbit-analog-stats

 

They all break the connection between watch and companion after 15 seconds. Changing any new settings from the companion gets blocked with error code 2 'invalid state'. After the 15 seconds are up, the only way I can get to restore the connection seems to be to open a watch App such as the 'timer' and then return to the clock face. You get another 15 seconds to change the settings before the connection closes.

 

Thanks.

Best Answer

@harpo666Thanks; that's useful info.

You could always try resubmitting your clockface, with a note to the reviewers warning that they might observe unreliable settings due to a firmware bug that you can't address. Since the problem is intermittent, they may not experience it at all.

However, some of your users would experience it, so you'd need to be prepared for some tricky support communications.

Peter McLennan
Gondwana Software
Best Answer

It's even worse: I also get the same problem when using Fitbit's own "Backdated" clock face!  I usually install this one before sideloading my own clockface for testing.  The colour changing on Backdated would not work properly yesterday.  Which is ironic given that they just refused mine since there was a problem changing colours!

Best Answer

hi!I have encountered the same problem recently 🤣

Did you solve it?

Best Answer
0 Votes

Hey Huami,

 

No resolution yet.

 

The only way I can restore the connection is to:

-Open a watch App such as the 'timer' and then return to the clock face.

-You get another 15 seconds to change the settings before the connection closes.

Best Answer
0 Votes

hey harpo,

thanks for reply!

i ran my app just now and it works!i didn't even change my code... it seems that fitbit has fixed this bug😅

Best Answer
0 Votes

I have my clockface loaded privately and indeed it seems better.  I just ran the settings from my iPhone and the first time I did it, it stopped responding after 15 seconds.  I then started teh timer app on my sense and then went back to the clockface.  This time it seems to work perfectly - over several minutes and also running the settings several times.  If it stays like this I will re-submit my clockface for approval.

Best Answer
0 Votes