• I want to monitor the temperature one of my pucks. It is now installed in my freezer.
    Initially I wanted to do this monitoring from a RaspberryPi v3 running Jessie which is about 4m behind the freezer through a wall but I would prefer the temp to be broadcast via BLE so that this sensor is readable by tools such as gatttool on the RaspberryPi and other devices that support BLE eg my Android phone.

    So far I can (1) connect to it from my Raspberrypi using CLI....

    pi@raspberrypi:~ $ espruino -p f2:91:92:05:xx:xx
    Espruino Command-line Tool 0.0.26
    
    Connecting to 'f2:91:92:05:39:ce'
    Connected
    
    

    and (2) read the temperature using the built in function E.getTemperature()

    >console.log("Temp is "+E.getTemperature()+"°C");
    Temp is -26.5°C
    =undefined
    >
    

    Now that I know the radio transmission path is OK and the sensor is working the next challenge is to get this puck broadcasting the temp. To maximise battery life I don't want to connect to the puck each time I want a temperature reading; instead I would like to receive data over BLE like a beacon.

    Has anyone cracked sensor readings from the puck using the BLE broadcast features?

    TIA

  • Sample that uses NRF.setServices and NRF.updateServices on Puck.js to publish temperature

    var C = {
      set : "SET",
      update : "UPDATE",
      every_30_sec : 30000
    };
    
    function publishTemp(cmd) {
      //digitalPulse(LED2, 1, 200);
      if (cmd == C.set) 
        NRF.setServices({
          0x1809 : { // Health Thermometer
            0x2A6E: { 
              readable: true,
              broadcast: true,
              value : [E.getTemperature().toFixed(2)]
        }}});
      if (cmd == C.update)
        NRF.updateServices({
          0x1809 : { // Health Thermometer
            0x2A6E: {
              readable: true,
              broadcast: true,
              value : [E.getTemperature().toFixed(2)]
        }}});
    }
    
    // first time
    publishTemp(C.set);
    // every 30 sec
    setInterval(publishTemp,C.every_30_sec,C.update);
    
    

    check https://www.bluetooth.com/specifications/gatt for further details on GATT Characteristics, Declarations, Descriptors, Services

  • or a shorter one

    // test  temperature
    
    var C = {
      every_30_sec : 30000,
      setTemp : NRF.setServices,
      updateTemp : NRF.updateServices,
    };
    
    function publishTemp(fn) {
      digitalPulse(LED2, 1, 200);
        fn({
          0x1809 : { // Health Thermometer
            0x2A6E: {
              readable: true,
              broadcast: true,
              value : [E.getTemperature().toFixed(2)]
        }}});
    }
    
    // first time
    publishTemp(C.setTemp);
    // every 30 sec
    setInterval(publishTemp,C.every_30_sec,C.updateTemp);
    
    
  • @MaBe, thanks for the code, looks interesting! However it does not work for me, I tried for example the nRFToolbox on an iPhone. That does not display the data. Can you tell which application you used to read the data?

    Also, my understanding is that to read that data you would have to connect. I am probably misunderstanding this but as a beacon I would use setAdvertise. Something like this:

    setInterval(function() {
      NRF.setAdvertising({
        0x1809 : [Math.round(E.getTemperature())]
      });
    }, 1000);
    

    (directly from the tutorial). Then I can see the data directly in nRF Connect without even connecting.

    Thanks!

  • @stevie4711 I am using Bluefruit to connect and read the raw data


    1 Attachment

    • FullSizeRender 2.jpg
  • Okay, thanks, that works for me as well. At least on one Puck, on the other it does not work at all.

    But it seems that Puck is damaged, somehow...

  • @MaBe, many thanks for those examples. Really helpful. Worked second time of asking. Weirdly copy / pasting into nano and uploading via CLI on Raspberry resulted in the error below which seen before but luckily the example was easy to retype.

    I don't have access to bluefruit but was then able to test the code using the bluez command gatttool to query the characteristic 0x2A6E which responded with '31 39 2e 32 35' which is 19.25 in ascii. The puck was in the warm so it is a sensible result. (This puck stopped working after it got to a temperature of -32 degrees in my freezer but has now recovered)

    This is gatttool in action:

    pi@raspberrypi:~/puck $ gatttool -I -b F2:91:92:05:39:CE -t random
    [F2:91:92:05:39:CE][LE]> connect
    Attempting to connect to F2:91:92:05:39:CE
    Connection successful
    [F2:91:92:05:39:CE][LE]> char-read-uuid 0x2A6E
    handle: 0x0013 	 value: 31 39 2e 32 35 
    [F2:91:92:05:39:CE][LE]> disconnect
    
    

    Here is the error encounted after cut/pasting the code.

    Connected
    Acorn parse for plugins/compiler.js failed.<br/>Check the editor window for syntax errors
    undefined:44
        utf8.encode(c).split('').forEach(function(c) {
        ^
    
    ReferenceError: utf8 is not defined
        at escapeChar (eval at loadJS (/usr/lib/node_modules/espruino/index.js:10:10), <anonymous>:44:5)
    .....
    
  • Strange error - can you post an issue on https://github.com/espruino/EspruinoTools with the exact contents of the file that wouldn't upload?

    But I'd say the setAdvertising method you'd used is best for low power since it doesn't need a connection. This might be a good way of getting the data into your Pi: http://www.espruino.com/Puck.js+Node-RED

    And most likely it'll be the battery that won't take freezing temperatures, rather than the Puck - you might be able to find a special CR2032 meant for low temperatures I guess

  • Tnx. Will create an issue for that error when I get home.

  • Hello!
    Tell me who to write if I found a bug in the module?
    Module http://www.espruino.com/modules/DHT11.js
    and http://www.espruino.com/modules/DHT11.min.js
    Line 37 column 10.
    Replace t: parseInt (d.substr (18,8), 2)
    on temp: parseInt (d.substr (18,8), 2)
    Line 39 column 10. Delete cb (o);

  • I'm not sure if Puck is freezer safe / savy... for sure the battery will not enjoy much life in −18 °C, respective 0 °F (temperature assumed in food safety / expiration date definition). Having a remote sensor (inside) or a remote battery (outside) could help here...

  • @Mark thanks - it's all updated now!

  • I would use the ds18s20 - 3.3v, gnd and one data pin on the puck:

    Unique 1-Wire® Interface Requires Only One Port Pin for Communication. Maximize System Accuracy in Broad Range of Thermal Management Applications. Measures Temperatures from -55°C to +125°C (-67°F to +257°F)

  • I am reading temps using gatttool but because I have to connect to do this I suspect a purist would point out that this is not Low Energy yet. For that I plan to explore use of Node Red over the holiday but in the meantime, has anyone got broadcasts working? If so, what mobile app or tools are you using to view the advertising? Are you able to post a screenshot?

  • I have tried broadcasting ('advertising') using example code from this thread and it works great.

    setInterval(function() {
      NRF.setAdvertising({
        0x1809 : [Math.round(E.getTemperature())]
      });
    }, 1000);
    

    on the monitoring end the EspruinoHub software works well on the RPi. The temperature in this case gets published by the hub to the local mosquitto MQTT broker where it can be subscribed to by any MQTT client. For example the client on the RPi (change the MAC address to yours)

    mosquitto_sub -v -t /ble/advertise/c7:6e:71:dd:ee:ff/temp
    

    or

    mosquitto_sub -v -t /ble/advertise/# | grep temp
    

    Note that the hub only publishes when the temp value has changed, or every 60 seconds.

    This is what the EspruinoHub displays while it is running in the foreground and while the Puck is advertising the temperature

    Config loaded
    MQTT Connected
    <HTTPProxy> Bleno State poweredOn
    <HTTPProxy> Bleno.startAdvertising Success
    <HTTPProxy> Bleno.setServices Success
    Scanning started...
    
    Thu Dec 22 2016 09:30:53 GMT-0500 (EST)
    
    eb:83:4c:dd:ee:ff - Puck.js eeff (RSSI -63)
      1809 => {"temp":19}
    
    
  • Great example!

  • Anyone know of any useful Android or OSX apps/utilities that could be used to receive/view the puck notifications?

  • If you mean notifications via MQTT on Android I use MyMQTT. For iOS there's and app called MQTT Tester that I haven't tried. If you mean notification directly from the puck via BLE there's nRF Connect for Android that works. For iOS it's called nRF Toolbox but I haven't tried it. My iPad is too old. For OSX I have no idea.

  • Did anyone ever find out how well the CR2032 works in the freezer? I was hoping to do a similar thing to the original poster.

  • I think it might be more or less ok - the Energizer CR2032 datasheet mentions they work down to -30 degrees C: https://data.energizer.com/pdfs/cr2032.pdf

    A cheaper one mentions -20 (http://www.farnell.com/datasheets/1496885.pdf) but I'd have thought it'd be ok. I guess if you do hit issues you might need to find a better battery but it definitely seems to be within sensible temperatures for a freezer.

  • Thanks. I think I saw that datasheet for the -20 one, but not the Energizer one. I'll give it a go with the ones I've got and see what happens.

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

Project to use Puck.js as a Remote Temp Sensor (Eg To monitor fridge/ freezer)

Posted by Avatar for JamesS @JamesS

Actions