Avatar for Thinkscape

Thinkscape

Member since May 2017 • Last active Jun 2017
  • 2 conversations
  • 8 comments

Most recent activity

  • in Puck.js
    Avatar for Thinkscape

    Thanks mate! Works like a charm.
    I'll update the docs, maybe it'll be useful for others as well.

  • in Puck.js
    Avatar for Thinkscape

    I'm not 100% sure the docs you found are for the UUID 0x1809 that's being used though

    GATT docs list that as:

    Health Thermometer  org.bluetooth.service.health_thermometer­    0x1809
    

    It matches your example in docs. From what I can tell 0x2A1C is a code for "temperature measurement", while 0x1809 is the code for the "health thermometer" service as a whole. Not sure if the NRF library we're using even has a notion of those formats, or is it up for us to provide an implementation.

    The issue is with the EspruinoHub's decoding. It's doing something pretty simple right now - 8 bit is interpreted as-is, and 16 bit is the temperature x100

    Hmm... it seems that you're bitshifting the second value ((((a[1]<<8)+a[0])/100)), which makes it hard for me to reverse it.

    How would you encode a 16 bit float to this that would work on puck (i'm assuming its BE)?

    function encodeFloat(num) {
      const dec = Math.round(n);
      const fractional = Math.round(n % 1 * 100);
      return [ dec, fractional >> 8 ]; // ???
    }
    
  • in Puck.js
    Avatar for Thinkscape

    Hey there!
    I'm using NRF.setAdvertising() to advertise temperature readings from Puck.js.
    The examples in docs sadly only mention byte arrays, integers and string fragments as supported data:

    // straight from official docs
    setInterval(function() {
      NRF.setAdvertising({
        0x1809 : [Math.round(E.getTemperature())]
      });
    }, 30000);
    

    What I'm trying to do is advertise the floating point temperature without rounding. Puck currently reports temperature with 0.25 accuracy, but I'm struggling with how to encode it in a way, that would make EspruinoHub understand it.

    The official BLE GATT spec for thermometer actually supports extra flags in the first byte and temp. reading (default is Celsius) as a Float32.

    The node on puck doesn't sadly provide Buffer so I tried encoding with TypedArrays like so:

    setInterval(function() {
      NRF.setAdvertising({
        0x1809 : temperatureAsArray()
      });
    }, 30000);
    
    function temperatureAsArray() {
      const a = new Float32Array(1);
      a[0] = E.getTemperature();
      const b = new Uint8Array(a.buffer);
      const c = new Uint8Array(5);
      c[0] = 0;    // the first byte set to 0 means a single celsius measurement without timestamp
     // I've also tried without this byte, didn't change anything
      c.set(b, 1);
      const result = [];
      
      for (let x = 0; x < c.length; x ++) {
        result[x] = c[x];
      }
    
      return result;
    }
    

    The resulting array is something like: [0, 0, 0, 236, 65] for temperature of around 21 deg, or [0, 0, 236, 65] if you don't include the "flags" byte and just have BE 32-bit float.

    However, when I receive it in EspruinoHUB, the debug shows me:

    d1:bf:fb:93:39:bf - Puck.js (RSSI -57)
      1809 => {"temp":0}
    

    It seems to struggle to decode those Float32 byte arrays.
    When I sent something like [236, 65] (without the GATT flags and trimmed to just 2 bytes) then it shows me:

    d1:bf:fb:93:39:bf - Puck.js (RSSI -57)
      1809 => {"temp":168.76}
    

    I have no idea how it got 168.75 from those bytes.

    Any idea what EspruinoHub/Noble/bleno expect as a format for floats?

    Have anyone succeeded in encoding floats for BLE Adv. ?

  • in Puck.js
    Avatar for Thinkscape

    Maybe not as sexy as some other projects, but here it goes

    I'm working on a better way to heat my apartment using electric oil heaters, pucks and Wemo plugs.

    1. I'm using Puck.js as temperature sensors, attached to ceiling or walls to measure and average temperature across rooms.
    2. Pucks advertise the temperature via BLE (low-energy, super-long adv. period, very rare temperature reads every few minutes to maximise battery life).
    3. A running instance of EspruinoHUB serves as BLE -> MQTT bridge.
    4. Node-red instance reacts to MQTT messages.
    5. I'm implementing logic which will guarantee temperatures in a set range, in specific rooms, at different days of the week.
    6. Node-red talks via uPnP to Belkin Wemo Insight power switches, turning oil heaters on and off to maintain the temperature.
    • 26 comments
    • 494 views
  • in Pico / Wifi / Original Espruino
    Avatar for Thinkscape

    Thanks for the explanation.

    It'll be my first IoT board purchase, i'm new to all that.

    As a side question, you've mentioned 500mA being too little to power it. I was under the impression that the SoC and Wifi would be much less power-hungry and could operate on something for months on a 2000mAh cell - my use case will be a temperature sensor: thermistor + resistor + Erduino WiFi, probing the temperature every 60s, posting a handful of small packets via HTTP via WiFi.

    What is your experience with ESP8266 and power draw?

  • in Pico / Wifi / Original Espruino
    Avatar for Thinkscape

    After http://www.espruino.com/Battery

    I'm confused... "the original" has a JST connector built in, the Pico has instructions on how to solder on a JST connector, but there's no mention of "Wifi" model.

    How can I power it?
    Does it support soldering on a JST connector like Pico?
    Am I supposed to only power it via USB connector?

    Thanks.

Actions