09-23-2019 08:17 - edited 09-23-2019 08:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-23-2019 08:17 - edited 09-23-2019 08:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hello Fitbit,
everytime I run this script, the companion index.js logs the data to the console,
but the index.js of the app which reads the file returns an JSON parse error.
When i used utf-8 or cbor it returned 0. But I don't understand why. Please Help me.
My app/index.js:
inbox.onnewfile = () => {
console.log("New file!");
let fileName;
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, "json");
console.log(data);
statusText.text = '"' + data + '"';
console.log(data);
}
} while (fileName);
};
and my companion/index.js:
fetch("<a href="<a href="https://support.oneskyapp.com/hc/en-us/article_attachments/202761627/example_1.json").then(function" target="_blank">https://support.oneskyapp.com/hc/en-us/article_attachments/202761627/example_1.json").then(function</a>" target="_blank"><a href="https://support.oneskyapp.com/hc/en-us/article_attachments/202761627/example_1.json").then(function</a" target="_blank">https://support.oneskyapp.com/hc/en-us/article_attachments/202761627/example_1.json").then(function</a</a>> (response) {
// We need an arrayBuffer of the file contents
//console.log(url_base + url_login);
return response.json();
}).then(function (data) {
// Queue the file for transfer
console.log(data);
outbox.enqueue("test.json", data);
});

09-24-2019 11:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-24-2019 11:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
That's some really strange code you put in your fetch() method, or maybe it's this message board's formatter. Anyway, if you are sure that
outbox.enqueue("test.json", data);
data is json, then you could encode it with
import { encode } from 'cbor';
// ...
outbox.enqueue("test.json", encode(data));
let data = fs.readFileSync(fileName, 'cbor');

09-24-2019 11:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

09-24-2019 11:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thank you for your answer!
(Strange code is the Fitbit website)

