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

Clockface Settings changes not exchanged with device

Hi all,

I noticed strange behaviour on my clock face: https://gallery.fitbit.com/details/3925af38-b12d-42b0-a611-554c91d73397

After the installation, my Settings are working perfectly, but after for ex. 1 hour, whatever I change in settings it's not reflected on the watch.

I guess this has something to do with the companion, but I really need some kind of event to be fired when settings are opened and the companion to be awakened.

 

Users are complaining that can change the colours and the stats toggle only the first time.

 

Here is my code in companion:

import * as messaging from "messaging";
import { settingsStorage } from "settings";
import * as util from "../../common/utils";
import { me as companion } from "companion";

export function initialize() {
  settingsStorage.addEventListener("change", evt => {
    if (evt.oldValue !== evt.newValue) {
      sendValue(evt.key, evt.newValue);
    }
  });
}

function sendValue(key, val) {
  if (val) {
    sendSettingData({
      key: key,
      value: JSON.parse(val)
    });
  }
}

function sendSettingData(data) {
  if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
    messaging.peerSocket.send(data);
  } else {
    console.log("No peerSocket connection");
  }
}

 

Thanks

Best Answer
0 Votes
7 REPLIES 7

Sockets don't always open immediately, I believe. If the connection isn't available when you need it, you're just throwing away the data at the moment. Using file transfer, rather than messaging, may be more robust.

Peter McLennan
Gondwana Software
Best Answer

Totally agree, but is there any way to put a loader screen/gif on the Settings screen for the user, or just display a counter for a few seconds until the socket is opened?

Best Answer
0 Votes

Yes, but that would be harder.

Peter McLennan
Gondwana Software
Best Answer

Ok, maybe another approach, is there a way to trigger an event for opening the socket immediately when the Settings section is opened?

Best Answer
0 Votes

No. The availability of the socket depends on the watch. It takes time for the OS to establish the connection. Sometimes it can't be done at all.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

You could try waiting for socket onopen event, but I still think you risk losing data compared to file transfer.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

I would like to implement the file transfer in the following way:

function sendSettingData(data) {
  if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
    messaging.peerSocket.send(data);
  } else if (messaging.peerSocket.readyState === messaging.peerSocket.CLOSED) {
    //Disable messaging
    //File transfer 
  }
  else {
    console.log("No peerSocket connection");
  }
}

but there is a risk in the meantime the socket to be opened and rewrite the users' choices, so is there a way to disable messaging once I decide to transfer the settings data via file?

Best Answer
0 Votes