Hey, I'm not sure if this is the right place to ask but I'm having a problem combining two Espruino/JavaScript concepts on my RuuviTag sensor beacon and I was wondering if anyone here had any insight into the matter.
Basically, I'm trying to use a variation of the program on this web page: [https://lab.ruuvi.com/temp-logger/]
But I'm trying to modify it so that I can store a lot more values by lowering the precision and storing values that take up less space in the RuuviTag memory.
For that purpose I found this Espruino method which supposedly lets you store sensor reading as 8 bit integers instead of 32 or 64 bit floats: [https://www.espruino.com/Data+Collection]
Here is what I have right now:
const period = 1000; // milliseconds (every 30 minutes)
const length = 10; // number of records (for 100 hours / 4 days)
var ruuvi = require("Ruuvitag");
var records = new Int8Array(length);
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);
When I upload and run this code it says this over and over:
in function called from system
Uncaught Error: Function "unshift" not found!
at line 2 col 15
if (records.unshift({time:getTime(),temp:ruuvi.getEnvData(...
^
And when I type the getData() command into the left side while the program is running I get this:
in function called from system
>getData()
0 undefined NaN
1 undefined NaN
2 undefined NaN
3 undefined NaN
4 undefined NaN
5 undefined NaN
6 undefined NaN
7 undefined NaN
8 undefined NaN
9 undefined NaN
=undefined
Am I missing something about the code? Or is it harder than I think it is to log values that take up less space in the memory? I don't see any reason why the unshift function would not be found. If unshift won't work for this type of operation, is there something else that will?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hey, I'm not sure if this is the right place to ask but I'm having a problem combining two Espruino/JavaScript concepts on my RuuviTag sensor beacon and I was wondering if anyone here had any insight into the matter.
Basically, I'm trying to use a variation of the program on this web page: [https://lab.ruuvi.com/temp-logger/]
But I'm trying to modify it so that I can store a lot more values by lowering the precision and storing values that take up less space in the RuuviTag memory.
For that purpose I found this Espruino method which supposedly lets you store sensor reading as 8 bit integers instead of 32 or 64 bit floats: [https://www.espruino.com/Data+Collection]
Here is what I have right now:
When I upload and run this code it says this over and over:
And when I type the getData() command into the left side while the program is running I get this:
Am I missing something about the code? Or is it harder than I think it is to log values that take up less space in the memory? I don't see any reason why the unshift function would not be found. If unshift won't work for this type of operation, is there something else that will?