Wrong Environment data

Hi All,

i have been playing around with the RuuviTag using the Espruino firmware. After saving a script into flash memory, the tag started to report odd Data, ( Ruuvitag.getEnvData()
={ “temp”: -138.56340314587, “pressure”: 1197.21111857997, “humidity”: 0 }
)
Initially, i was able to reset the tag by re-upoading the firmware, but the same data was sent again after a few more script tests. Assuming an error in the Espruino firmware, i proceeded to flash the Weatherstation firmware back on to the tag, but now all i get is #BDwWAMc4n as encoded data, which decodes to Temp 0, humidity NaN, Pressure 0A50000 when i decode it myself, while the Ruuvi page delivers results of 22/72 degrees, 30% humidity and 1010 hPa pressure.

Interestingly enough, the JS code i uploaded to the tag survives reflashing the firmware. This leaves me with a few questions :

  • Did i manage to break the tag by saving garbage to the flash memory ? If not,
  • How do i clear the JS code from the device ?
  • How do i reset the Tag so that the Weatherstation will report correct data again ?

Thank you for your help.

A

Hello,

The Espruino saves javascript to flash, and the Weather Station firmware does not erase the Espruino data files by default. However, the weather station does not use any Espruino code.

My best guess is that the environmental sensor BME280 is somehow misconfigured. As the BME280 retains the configuration as long as power is on, you could try removing the battery, waiting a few seconds and reconnecting the battery.

Please let me know if this helps

Hello,

thank you for the quick response. Unfortunately, powering down does not change anything. I left the tag without battery over the weekend but still had the same situation this morning.

A

Thank you for the details. Could you please paste here or PM me the Espruino code you used? I’ll try to replicate the problem and see if I can find a fix for it.

Attached is the JS code i tried to use. Note that it runs without problems, but saving it to flash has created the issue.

A.

var ScanIntervalInSeconds = 60; // 2 Minuten;
var NumberOfValuesStored = 880; // reicht für 1 tag 1 Wert/ 2 Minuten
var MaxRead = 880;

var  Ruuvitag = require("Ruuvitag");
var  DataArray = new Array(NumberOfValuesStored);
var Idx = 0;
var DataIdx = 0;
var Interval;
var MinTemp;
var MaxTemp;
var PrevTemp = 0;
var CntReads = 0;
function ReadRuuvidata()
{
  var temp = Ruuvitag.getEnvData().temp;
  console.log("read ", temp);
  CntReads++;
  if (Math.abs(PrevTemp-temp)<0.5) return;
  PrevTemp = temp;
  console.log("readindex ",CntReads, "stored at ", DataIdx);
  DataArray[DataIdx] = CntReads;
  DataArray[DataIdx+1] = temp;
  if (MaxTemp < temp) MaxTemp = temp;
  if (MinTemp > temp) MinTemp = temp;
  CntReads++;
  Idx+=2;
  DataIdx = Idx % NumberOfValuesStored;
  if (Idx > MaxRead)
  {
    clearInterval(Interval);
    Ruuvitag.setEnvOn(false);
    console.log("reading done");
    return;
  }
}

function onInit()
{
  Idx = 0;
  DataIdx = 0;
  DataArray.fill(-100);
  MinTemp = 100;
  MaxTemp = -100;
  Ruuvitag.setEnvOn(true);
  ReadRuuvidata();
  Interval = setInterval(ReadRuuvidata, 1000*ScanIntervalInSeconds);
  console.log("Interval i set: ", Interval);
  return 1;
}


function DumpData()
{
  for (var i = 0;i < NumberOfValuesStored-1; i+=2)
  {
    if (DataArray[i] < -99) return;
       console.log(DataArray[i] + ":" + DataArray[i+1]);
  }
}

Hello,

Good news is: BME280 is not broken, the error is in configuration.

I found a few issues in your code.

the character “ü” prevents Espruino from sending new code into tag. Please use “u” instead.

For some reason, saved code calling onInit() does not configure the code correctly.

Here is calling onInit() manually (without save)

1v92 Copyright 2016 G.Williams
Espruino is Open Source. Our work is supported
only by sales of official boards and donations:
http://espruino.com/Donate

=undefined

onInit();
{ “temp”: 23.83772651125, “pressure”: 1006.48934815127, “humidity”: 24.203125 }
read 23.83772651125
=1
read 23.83772651125
read 23.82759651369

and here is the same code with save() in the end:


| |_ ___ ___ _ ||___ ___
| | -| . | _| | | | | . |
|
|| || |||||_|
|
| http://espruino.com
1v92 Copyright 2016 G.Williams
Espruino is Open Source. Our work is supported
only by sales of official boards and donations:
http://espruino.com/Donate

=undefined
Erasing Flash…
Writing…
Compressed 32000 bytes to 12118
Checking…
Done!
Running onInit()…
read -142.76961693686
read -142.76961693686
read -142.76961693686
read -142.76961693686
read -142.76961693686
read -142.76961693686

My best guess is that this is caused by initializing "Var Ruuvitag = require("RuuviTag) in the start, which does not get called in onInit(). However this is just a guess. I hope this helps.

thank you very much for the help. I have been caught in the “german special letter” trap, it seems. I never checked the comments, just the code for odd issues but didn’t find a thing.

A

I am afraid the issue is still there.

I have tried a number of things. Unfortunately all without success. Here is what i have tried:

  • If i upload code and run it without saving, it works (correct data)
  • If i upload code and save it, it does not work right away, (incorrect data) and state remains that way until i upload new code. Interestingly enough, if i flash the original weather station code back onto the tag, the data is still wrong.
  • i tried to move the require(“Ruuvitag”) into the onInit function - no change.
  • i moved the initialisation into a function which is called with a 20 second delay to stave off any init timing issues - no change.
  • I stripped the code to a bare minimum (see below) - still, wrong read after save.
  • If i upload an empty program (literally no single line of code) using the Espruino IDE and then save it, the error disappears and i can at least use the weatherstation firmware on the tag.

This has me both puzzled (as to why the tag keeps reporting wrong data even after reflashing the original weather station firmware), and in a bind - i want to use the tag as stand alone data logger which i can on demand query via Bluetooth. As it stands now, i am convinced that JS (Espruino) is not a good way to go but i am also not certain how to develop a working firmware which provides the desired functionality.

Do you have any suggestion which way to go / which compiler / set of libraries to use to get there ?

A.

Stripped down code :

function ReadRuuvidata(tag)
{
  var temp = tag.getEnvData().temp;
  console.log("read ", temp);
}

function onInit()
{
  var  Ruuvitag = require("Ruuvitag");
  Ruuvitag.setEnvOn(true);
  Interval = setInterval(ReadRuuvidata, 1000, Ruuvitag);
  console.log("Interval set: ", Interval);
  return 1;
}

Logging data and querying it over bluetooth is a common need and we’re working towards it, however it will take some time (months) before we have an example application ready.

Some options for you:

Arduino is working on Arduino Primo Core, which runs on nRF52, and Arduino drivers for BME280 exists. We’ll support Arduino on RuuviTag if possible.

If you’re comfortable with C, you could fork https://github.com/ojousima/ruuvitag_fw/tree/feature-webble/ruuvi_examples/web-bluetooth and do following things: Implement environment_callback() in application.c which would store the measured values and call the callback in BME280 driver timer task when new sample is ready. To send the data out of device you’ll need to fill the ble_ess_s (defined in ble_ess.h) handles with stored values and call the “send”-functions in ble_ess.h with the filled struct as a paramter. You’d also need to implement something to subscribe to the notfications sent by tag.

If you can have a raspberrry pi / other logger nearby at all times, you could use one of the logger libraries presented on the forum.

Again thank you very much for your help. I will take a closer look at the web-bluetooth example and see where i get with that.
Having a logger nearby is no option due to size and Geometry limitations. I assume that i will need the nRF52 SDK to compile the firmware. Do i also need to get wired access to the tag, or can all this be done over Bluetooth ?

A.

Development board is not required for developing RuuviTag firmware, although it helps.
You can compile the code with ARM-GCC by running “make” in $project_folder/ruuvitag_b3/s132/armgcc

You can also create your own DFU packages for flashing with mobile phone, more detailed instructions are on github readme.