• 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).

  • Hey everybody,

    I tried your example but it doesn't work.

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

    After restarting the ruuvi I get this message:

    in function called from system
    Uncaught Error: Field or method "getData" does not already exist, and can't create it on undefined
    at line 1 col 12
    exports.env.getData()

    in function "getEnvData" called from line 5 col 33
    console.log(Ruuvitag.getEnvData());

    What could be the problem?

  • Hmm, that's an interesting problem actually. This should work:

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

    or this should work:

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

    but it's to do with the order of execution on initialisation, where onInit actually gets called before everything else. I'll change that for the next version of the firmware though.

  • Yes it works ;) thank you

  • Hmm, for some reason none of the above are working through the web IDE on firmwares 1v95-1v99. Everytime I get
    ">Uncaught ReferenceError: "dModules" is not defined
    at line 1 col 10
    1dModules.addCached("LIS2DH12","function f(c,a,d){this.r=c;t..."

    What could be wrong?

  • @user93898
    The examples above worked just fine until a few days ago.

    @Gordon Any idea about what could have changed on IDE or backend? Exact same code that worked on exact same tag with the same firmware 2 days ago gives the above error. I've tested the code on IDE 0.70.2, 0.70.3 and Espruino 1.99 today.

  • Looks like there's a post about this particular problem here as well, so to avoid duplication can we discuss it there? http://forum.espruino.com/conversations/325434

  • 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