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

seems not may fire newfile event at companion.

Hello 

 

I'm developing an app on the Versa2 collects sensor data. This data is stored in file for every 10min & transfer through File Transfer API. When companion app get file from device app, it try to send the data to server, if it success to do, companion notice device app through File Transfer API.

Basically it can work, but when app keep to run for some day, may become not to work. Device app can send data to companion, it seems don't fire newfile event at companion and can't process after that. Is there any way to solve it? I use iPhone, I could understand if restart iOS fitbit app, I can solve that problem.

 

//device app
function outboxBodyDataFile(fileName) {
outbox
  .enqueueFile("/private/data/" + fileName)
  .then((ft) => {
        console.log(`it keep to call anytime`);
  })
  .catch((error) => {
    console.log(`Failed to schedule transfer: ${error}`);
  });
}

function processAllFiles() {
  let fileName;
  while (fileName = inbox.nextFile()) {
    console.log(`it will call after companion send data to server. but suddenly become not to call `);
  }
}
inbox.addEventListener("newfile", processAllFiles);

 

// companion app
async function processAllFiles() {
  let file;
  while ((file = await inbox.pop())) {
    fetch(url)
    .then(function (response){
      noticeDeviceviaFileAPI();
    })
    .catch(function(error){
      noticeDeviceviaFileAPI();
    });
  })
}
inbox.addEventListener("newfile", processAllFiles);

 

Best Answer
0 Votes
2 REPLIES 2

Tricky. I'm guessing that the Fitbit app isn't running the companion component reliably. Ensure you're asking for run_background permission, and use companion wakeInterval.

 

Also ensure that the Fitbit app itself is running all the time, and has all permissions enabled when running in the background.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thank you for reply, Gondwana.

Sorry my entry is not enough. I set background permission on my iphone & use companion wakeinterval, so basically my app can work as expected.

 

I think companion keep to run because device app always success to transfer data to companion through File Transfer API & call promise.then. But don't fire newfile event on

companion.

Best Answer
0 Votes