• I would like the puck to store a few numbers per hour, and then read it after a day. What would be the best way to make the data readable by mobile.

    Is there any ready made code available? Not much of a programmer.

    Thanks!

  • This is for the puck, so I cant use an sd card, seen an example of that in the forum.

  • Hi! Yes, no problem at all.

    For something really simple, you can do:

    var data = [];
    
    function storeData() {
      var newData = E.getTemperature(); // for instance...
      data.push(newData);
    }
    
    setInterval(storeData, 10*60*1000); // call every 10 minutes
    

    If you upload that, after 10 minutes you'll have your first data element (the temperature), then another 10 minutes later, the next, etc.

    You can read the data just by typing data and enter on the left-hand side of the IDE. However once you've got quite a bit of data, it'll be too much to fit on a line.

    If you type data.forEach(a=>print(a)) then it'll print all the data items, one per line - which you could copy & paste into a spreadsheet. You could also turn that into a function that you can call:

    function getData() {
      data.forEach(a=>print(a));
    }
    

    To clear out all the old data you can also just write data=[].

    This way's simple but isn't very efficient with memory so you'll only be able to store around 1000 data items (still, that's 150 hours recording every 10 minutes).

    So... to get that on your mobile, you can run the same code on https://www.espruino.com/ide/ on an Android phone (or an iPhone with the WebBLE app).

    Or... you could write your own Web Bluetooth webpage. This one will grab the data and just print it to the page:

    <html>
     <head>
     </head>
     <body>
      <script src="https://www.puck-js.com/puck.js"></­script>
      <script>
        function getData() {
          Puck.eval('data', function(data) { 
            document.write(data.join('<br/>')); 
          });
        }
      </script>
      <button onclick="getData()">Get Data</button>
     </body>
    </html>
    

    There's some more info on using Web Bluetooth pages here: http://www.espruino.com/Puck.js+Web+Blue­tooth

    But once you have it loaded onto the page you could (for instance) display it in some fancier way, allow it to be downloaded, or maybe publish the data to Google Sheets.

  • very good. Storing it in a multidimensional variable will do the trick for me.

    But I am trying to do it without internet and the IDE, so maybe I can cycle the data through one of the BLE services, or advertise it? Just so I can read it 'offline' using only the nRF Connect app or something like that.

  • Could the /ide page work offline? Can it be saved?

  • Yes, the /ide page uses service workers, so should actually work offline as-is. Try disconnecting from the internet and going there (obviously once you've been on it already).

    The code on the Puck itself doesn't have to change. You have a few options:

    • you could actually just use the nRF UART app (Adafruit's bluefruit app should do it too). If you've uploaded the getData function then just type getData(), then newline, then send - and it'll dump all the data for you
    • You could make your own Android app using DroidScript - it's nice and easy and already has Puck.js support built in
    • You could make your own Android/iOS app
    • You could use service workers yourself to make your Web Bluetooth page available offline - there are a bunch of tutorials online about doing that.

    Hope that helps :)

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

What is the best way to make the Puck log data and read it by mobile? Any ready code for that?

Posted by Avatar for user82693 @user82693

Actions