-
• #2
var getData = require('Storage').read('rawData.csv\1');
This only reads chunk 1 of the Storage file, see here for an explanation about those.
You probably want something like this:
var dataFile = require('Storage').readopen('rawData.csv', 'r'); var line = dataFile.readLine(); while (line != undefined) { Bluetooth.println(`<data>\n${line}\n</data>`); line = dataFile.readLine(); } dataFile.erase();
Also:
var memory = require("Storage").getStats();
Shouldn't this be
var memory = require("Storage").getFree();
? -
• #3
Thank you very much.
I will try it today and update youAlso
var memory = require("Storage").getFree();
is a very good idea. -
• #4
Looks like @rigrig's got you sorted.
Just some notes though:
getStats
gives you a bunch of other info, not just free space.getStats/getFree
can be slow since it scans all of storage to work out how much data there is - maybe think about just calling it every minute, or even better call it once at startup to work out how much free there is, and keep track of how much you're writing. It won't be exact because there can be some overheads but since you're leaving 0.75MB of leeway you'll be fine- It's worth doing as few calls to
.write
as possible to make it a bit faster - so try and dorawData.write([....].map((o)=>parseInt(o*1000)/1000).join(",")+"\n");
So maybe more like:
var memory = require("Storage").getFree(); Bangle.on('HRM-raw', function(hrm) { // ... var line = [Math.floor(Date.now()),a.x,a.y,a.z,c.x,c.y,c.z,c.dx,c.dy,c.dz,hrm.raw,hrm.filt,hrm.bpm,hrm.confidence].map((o)=>parseInt(o*1000)/1000).join(",")+"\n"; memory -= line.length; rawData.write(line);
-
• #6
Thank you very much.
It is working :-) -
• #7
do you think my approach of using Date.now()-timePast>100 for sampling rate is efficient or you recommend any other way?
That'll be ok but it wouldn't give exactly 10Hz since you're sampling only when the delay is 100ms or more - but the HRM by default runs at 25Hz, so you might get steadier readings by just averaging two readings. It'd give you 12.5Hz but it'd be better to stay at that than to drop samples and get 10ish Hz.
Hello,
I am a student who is to new JS and recently got my hands on to bangleJS2. As part of our student project we are planning to acquire motion and heartrate data from bangleJS2.
The goal of the following code is to save outputs of accelerometer, magnetometer and heartrate sensor into a csv file. Due to storage limitation we are stopping it to record data when Flash is less than 0.75MB.
We want to record at least two days worth of data.
When we are trying to call the data we are only retrieving only 550 rows of data, even though the csv is having more data, we aren't able to get more values
We are using the following code in our script to read data
Is there a way to read all the rows from the csv file to array and send using ''Bluetooth.print''?
Apologies for my clumsy code.
Thank you in advance.