This topic is dedicated to comments and conversations about the following RuuviLab tutorial:
If you don’t see any comments yet, don’t be afraid to be the first one to contribute!
This topic is dedicated to comments and conversations about the following RuuviLab tutorial:
If you don’t see any comments yet, don’t be afraid to be the first one to contribute!
Just completed the code that stores temperature readings with date-time stamps using an array with FIFO operations. Here is the script:
const period = 30 *60*1000; // milliseconds (every 30 minutes)
const length = 3 *24*60*60*1000 /period; // number of records (for 3 days)
var ruuvi = require("Ruuvitag");
var records = [];
function log() {
ruuvi.setEnvOn(true);
if (records.unshift({time:Date(),temp:ruuvi.getEnvData().temp}) > length){
records.pop();
}
ruuvi.setEnvOn(false);
}
function onInit() {
E.setTimeZone(8);
setInterval(log, period);
setDeepSleep(true);
}
function getData() {
records.forEach( function(d,i) {
console.log(i+"\t"+ d.temp +"\t"+ Date(d.time.ms).toString());
});
}
Nice!
I made a few adjustments:
const period = 30*60*1000; // milliseconds (every 30 minutes)
const length = 200; // number of records (for 100 hours / 4 days)
var ruuvi = require("Ruuvitag");
var records = [];
function log() {
ruuvi.setEnvOn(true);
if (records.unshift({time:getTime(),temp:ruuvi.getEnvData().temp}) > length){
records.pop();
}
ruuvi.setEnvOn(false);
}
function getData() {
records.forEach( function(d,i) {
console.log(i+"\t"+ d.temp +"\t"+ (getTime()-d.time));
});
}
ruuvi.setAccelOn(true);
setInterval(log, period);
Usage:
@cw Please contact @henri (Private Message) for your shipping details so we can send your reward.
Thanks for the edit, makes for good learning. I have trying to figure out if there is a simple way to determine when memory is running low before popping out records from the array. So that there would not be a need to pre-determine the length of the total records, i.e. use the max memory available. Any advice?
I haven’t found a reliable way to measure amount of memory available in Espruino, right now I just allocate more objects until I get error.
Please let me know if you find a method
Javascript try and catch mechanism is unable to catch the memory overflow error; I tried it earlier today.
This morning, I actually did what you just suggested, here are the details:
length
to a very large number, i.e. 10000period
= 1console.log( records.length )
to obtain the max lengthlength
to less than (4) and reset period
to desire valueand we are good to go.
Im complete noob testing this on our wholesale market.
Could someone with more info tell me how many data´points can you store before unit runs out of memory.
How do you set up unit so that it doesnt overwrite data and just stops recording when it reaches full memory.
How do I set up unit so that it starts recording lets say after 4 hours when I set it up.
I have very basic knowledge about python coding I mean very basic.
I would consider setting up a gateway which would the send all of the data to a backend on the cloud. This way you can monitor the tags in real time and get alerts, as well as store as many data points as you need.
Thanks Otso. Im concidering trying to to use this to log cold chain when we send temperature sensitive products to our customers.
You might be interested in Corvus GPS application: https://lab.ruuvi.com/corvus/
Hey there. I have been messing with this code and it’s really cool. I’m wondering though. Is there a way to store smaller values so I can fit more data points in the memory? If I could cut off a bunch of digits after the decimal point I think it would save a lot of space and allow me to run the program a lot longer without starting to lose data. Any thoughts?
Good job!!!
how can I access temperature data getData() without Espruino IDE?