• Got some odd behaviour trying to advertise some environmental data from a Ruuvi tag using Espruino. In a nut shell, flashing via web IDE and outputting env data works perfectly fine however as soon as I persist the firmware on the board the readings seem to skew and not change.

    Can be reproduced with very minimum code e.g.

    var Ruuvitag = require('ruuvitag');
    Ruuvitag.setEnvOn(true);
    setInterval(function() {
      console.log(Ruuvitag.getEnvData());
    }, 5000);
    

    Any ideas what's going on?

  • Hi,

    It's because the sensors on the Ruuvitag need to be initialised at power on - and basically your code is initialising them once (at upload).

    If you do:

    var Ruuvitag = require('ruuvitag');
    function onInit() {
      Ruuvitag.setEnvOn(true);
      setInterval(function() {
        console.log(Ruuvitag.getEnvData());
      }, 5000);
    }
    

    Then the onInit function gets called at startup, and initialises the Ruuvitag's sensor then.

    (also, just moved this to the 'other boards' section)

  • Hi Gordon,

    Thanks for the reply (and apologies for not putting this in the right place, wasn't sure where the best place to put it was).

    Well I did find this thread and as a result I actually already tried the approach you've suggested but to no avail. The only difference in the other thread is they've got pretty much all the code in onInit as opposed to including Ruuvitag outside i.e.

    function onInit() {
          var Ruuvitag = require('ruuvitag');
          Ruuvitag.setEnvOn(true);
          setInterval(function() {
            console.log(Ruuvitag.getEnvData());
          }, 5000);
    }
    

    I will try with exactly the sample you've suggested if you think it would make the difference, however, failing that do you have any other ideas? From the looks of the other thread it seems like it's a limitation from the Ruuvi side?

  • I don't think the two styles should make too much difference.

    You're right though - I just looked at the module, and I made a mistake when making it in the first place, which means that the initialisation occurs at upload time in each case!

    I've just modified it, so if you upload again hopefully it'll work now (not with your first code, but with the second one). Please can you try and let me know? I also updated the documentation to mention it.

  • @Gordon brilliant :) I'll give it a try tonight and let you know how I get on. Thanks

  • @Gordon worked a treat, thanks! I'm intrigued, how did you apply the fix without me having to update Espruino 🤔 When the tag is flashed are the libs downloaded in the fly?

  • Yes - the Espruino firmware's got some libraries built in, but if you use require and that library isn't part of the firmware then it's pulled in by the IDE each time you upload (it's why sometimes if you use a library you have to upload something that uses it on the right-hand side before you can use the command prompt on the left-hand side).

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Environmental data not working after flashing Ruuvitag

Posted by Avatar for jamesh @jamesh

Actions