04-18-2019 18:27
04-18-2019 18:27
I have a JSON object full of weather data that I am trying to send from the companion to the device using file transfer. The outbox.enqueue appears to be successful on the companion, and is the inbox.nextFile also appears to work. But when I then try to read the file using the fs (file system) the file (which is there) is either empty or not formatted as expected.
Again the objective is to take a large JSON object with weather data at the companion and get it to a JSON object on the device with the same weather data. Any hints on how to do that properly?
Answered! Go to the Best Answer.
05-02-2019 15:13
05-02-2019 15:13
You can encode the data as CBOR, the open the file on the device in CBOR format. Like this:
// companion
import { encode } from "cbor"; import { outbox } from "file-transfer";
outbox
.enqueue(YOUR_FILENAME, encode(YOUR_JSON_OBJECT))
.catch((err) => {
throw new Error(`Failed to queue ${filename}. Error: ${err}`);
});
//device
import { readFileSync } from "fs";
let YOUR_JSON_OBJECT = readFileSync(YOUR_FILENAME, "cbor");
05-02-2019 15:13
05-02-2019 15:13
You can encode the data as CBOR, the open the file on the device in CBOR format. Like this:
// companion
import { encode } from "cbor"; import { outbox } from "file-transfer";
outbox
.enqueue(YOUR_FILENAME, encode(YOUR_JSON_OBJECT))
.catch((err) => {
throw new Error(`Failed to queue ${filename}. Error: ${err}`);
});
//device
import { readFileSync } from "fs";
let YOUR_JSON_OBJECT = readFileSync(YOUR_FILENAME, "cbor");
05-17-2019 07:19
05-17-2019 07:19
Thanks! This is working for me.