05-11-2020 00:11
05-11-2020 00:11
this is my code
var accelData = [];
if (Accelerometer) {
const accel = new Accelerometer({ frequency: 1 });
accel.addEventListener("reading", () => {
accelData.text = JSON.stringify({
x: accel.x ? accel.x.toFixed(1) : 0,
y: accel.y ? accel.y.toFixed(1) : 0,
z: accel.z ? accel.z.toFixed(1) : 0
});
});
sensors.push(accel);
accel.start();
} else {
accelLabel.style.display = "none";
accelData.style.display = "none";
}
var timer = setInterval(function(){
file = fs.openSync("utf8.txt" , "w+");
fs.writeSync(file , accelData.text) ;
let utf8_read = fs.readFileSync("utf8.txt", "utf-8");
console.log("UTF-8 Data: " + utf8_read);
fs.closeSync(file)
},5000)
I want is to save the sensor data in text every 5 seconds and see the size of the text file.
but ...
If you use writeFileSync, it is said that if there is no file, it is created. Why is there no file?
And if you don't open and write the file like that, the text file will be created normally.
Could anyone please tell me this?
Answered! Go to the Best Answer.
05-12-2020 12:49
05-12-2020 12:49
I'd recommend reading the filesystem guide here https://dev.fitbit.com/build/guides/file-system/
You were missing var, let or const here:
05-12-2020 12:49
05-12-2020 12:49
I'd recommend reading the filesystem guide here https://dev.fitbit.com/build/guides/file-system/
You were missing var, let or const here: