• It looks like there is a minor typo for the tutorial http://www.espruino.com/Pixl.js+Wireless¬≠+Temperature+Display

    in this line:

    g.drawString(`${dev.name}: ${d.getUint8(0)}'C (${d.getUint8(0)}% bat)`,0,idx*6);
    

    the battery level is displayed twice...

    looks like that should reference a different element & read:

          g.drawString(`${dev.name}: ${d.getUint8(1)}'C (${d.getUint8(0)}% bat)`,0,idx*6);
    
    

    Also, in this same tutorial, I notice that making a slight adaptation to the puck code:

            console.log("temperature: ", E.getTemperature());
    

    gives a decimal temperature, e.g. "24.5",

    yet the Pixl.js only displays the integer part with this

    ${d.getUint8(1)}'C
    

    any hints for how to extract the entire decimal part?

  • Thanks! I've just updated it so when I next push the website that'll be active. Not sure how I missed that (it's even obvious from the picture of the LCD!).

    If you want better resolution then one easy solution is to reduce the range by multiplying it. By default you're using 8 bits, so 0..255 (or -128 to 127 if you use g.getInt8(1)). For normal outside temperatures -64 to 63.5 would be ok, so you could do:

    // sender
    manufacturerData: [Puck.getBatteryPercentage(), E.getTemperature()*2]
    
    // receiver
    g.drawString(`${dev.name}: ${d.getInt8(1)/2}'C (${d.getUint8(0)}% bat)`,0,idx*6);
    

    But then the temperature reported is actually to 0.25, and multiplying by 4 and restricting to -32 to 31.75 is probably too much.

    In that case you'd want to use two bytes and then you can multiply by a much bigger number. Using DataView on both ends is probably easier to read:

    // sender
      var data = new Uint8Array(3); // 3 bytes
      var d = new DataView(data.buffer);
      d.setUint8(0, Puck.getBatteryPercentage());
      d.setInt16(1, E.getTemperature()*256);
      NRF.setAdvertising({}, {
        manufacturer: 0x590,
        manufacturerData: data
      });
    
    // receiver
    g.drawString(`${dev.name}: ${d.getInt16(1)/256}'C (${d.getUint8(0)}% bat)`,0,idx*6);
    
  • Thanks a ton! That was just enough to get me started. I've now got this example working about as desired, with both Puck and Ruuvitag. Next I'm moving onto the next example (Puck.js and Node-RED with MQTT).

    FWIW - I really appreciate what you've pulled together - this Espruino ecosystem is both clever and solid :) It's a nice mix of high level abstraction with low level control...

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

source code error for tutorial: Pixl.js Wireless Temperature Display

Posted by Avatar for cottjr @cottjr

Actions