shelly-script-examples icon indicating copy to clipboard operation
shelly-script-examples copied to clipboard

ble-pasv-mqtt-gw.js not correctly reporting negative temperatures for xiaomi devices

Open ghost opened this issue 1 year ago • 2 comments

Negative temperatures are not reported correctly. -8.8c (might not be exact as the temperature fluctuates a bit) is reported as 6544.8c

To Reproduce Simply place the xiaomi sensor in an environment with negative temperatures (in celcius) and check the mqqt output

Expected behavior Expected to see negative temperatures reported in MQTT. Both mqqt reports (the one with only temperature and the one with temperature & humidity) are incorrect.

As long as it's still cold enough here I can easily test any fixes.

ghost avatar Feb 10 '24 19:02 ghost

Fixed it (I think), changed

  else if(fmt[pos] === 'H') {
    res[keyArr[pos]] = le ? this.getUInt16LE() : this.getUInt16BE();
  }

to

  else if(fmt[pos] === 'H') {
    res[keyArr[pos]] = le ? this.getInt16LE() : this.getInt16BE();
  }

ghost avatar Feb 10 '24 20:02 ghost

getUInt16LE implies Unsigned integer so no negative values are possible. Changing to getInt16BE will allow for negative values so if the data looks ok it should be a valid solution

sdrsdr avatar Feb 12 '24 10:02 sdrsdr