08-29-2022 17:10
08-29-2022 17:10
I have an app that sends a file to companion app which then eventually sends the data to my server. However I started to notice that sometimes data does not appear from some users.
Currently, I have my users keep the Fitbit app open in the background and in the morning, they also sync the watch with the phone. I do this all the time and my data goes through.
Here is the code snippet I use with my apps:
Watch:
function transferFile(filename){
outbox
.enqueueFile(`${filename}.json`)
.then((ft) => {
console.log(`Transfer of ${ft.name} successfully queued.`);
})
.catch((error) => {
console.log(`Failed to schedule transfer: ${error}`);
})
}
Companion:
async function processAllFiles() {
var transferred = false;
while ((file = await inbox.pop())) {
try{
payload = await file.json();
filename = payload.sessionDate;
sendData();
}
catch(error){
console.log(error)
}
}
}
function sendData(){
// files will be saved as Dxx_Byyy/sessionDate.json
fetch(`urladdress${payload.uid}/${filename}.json`, {
method: 'POST', // or 'PUT'
headers: {
'Authorization': 'authcode',
//'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
})
.then(response => response.text())
.then(data => {
console.log('Success:', data);
sent = true;
})
.catch((error) => {
console.error('Error:', error);
sent = false;
});
}
Is this problem related to the code , phone or user related? How can I make sure the data gets sent? Right now I'm testing a button to send the data but I wish I don't have to use it
thanks in advance!
08-29-2022 22:51
08-29-2022 22:51
@ac_devel- see https://community.fitbit.com/t5/SDK-Development/Ensure-Companion-starts/m-p/5047563
Is it possible that the app is running but the companion not? [if the phone is not connected.
You can see this using the SimpleCheckUp app which makes a distinction between last synced and connectable.
Author | ch, passion for improvement.
08-30-2022 10:14
08-30-2022 10:14
Thanls @Guy_ . I downloaded your app and it shows that all works well.
I still don't get though why the companion app seems to stop working.
08-30-2022 10:25
08-30-2022 10:25
@ac_devel - as a test, turn Bluetooth off, st SimpleCheckUp and it wil fail the connection test
Turn Bluetooth on and run the test again and it will still fail the connection test.
Restart the app and it will work.
What it seems to mean is the companion never gets started if there is a link problem between watch and phone, even after it is resolved.
Author | ch, passion for improvement.
08-30-2022 10:38
08-30-2022 10:38
Thanks! That's interesting. Is there any work around to this problem that you know of? It's hard to figure out when it happens and why.
08-30-2022 10:42
08-30-2022 10:51
08-30-2022 10:51
A bit bummer because I do rely on this functionality to retrieve my data remotely. I have a work around where I use a button to send a saved file but I just have proof it does not work well since as you pointed out, if there is a problem somewhere then I can't get the companion app started again and even if use the button, nothing happens. the button works only if the "bridge" is open.
08-30-2022 10:54
08-30-2022 11:11
08-30-2022 11:11
Is there a place to report such issue?
08-30-2022 17:20
08-30-2022 17:20
Just an update to this and maybe it's not file transfer related: I have two files A and B. File A was created last night and was supposed to be transferred last night. Assumed to be about 20Kb. File B is created today, 3KB and transferred correctly.
Now with my button workaround, I can send File B no issue so this means companion is responsive. However I cannot transfer File A in the same session(with companion already connected to phone) or any other session.
Any suggestion on why this happens?