SteidlD / homebridge-inkbird-bt-thsensor

A homebridge-plugin for the Inkbird bluetooth temperature and humidity sensors.
GNU General Public License v3.0
8 stars 2 forks source link

Connecting external sensor/probe make CRC failing on TH1-Plus model #9

Closed hadjedjvincent closed 2 years ago

hadjedjvincent commented 3 years ago

Hi @SteidlD , thank you for this plugin :-)

I've noticed a little issue while connecting the external probe (TH1 Plus model) and if the sensor model is defined as TH1. There is no CRC issues if external sensor is disconnected.

This error does not occurs if the model is defined as "not in list, try anyway", and all the values are correct. Internal / External sensor are both correctly detected.

What kind of information do you need to add the TH1-Plus model into the list ? I've dumped some variables, if it helps, thank you!

Warning - CRC Error (expected 22bb, found a23). Ignoring data!!

self.dSensorCfg :

{
  datalength: 9,
  localName: 'sps',
  serviceDat: undefined,
  serviceUuids: 'fff0'
}

self.cRawStatus: <Buffer 0c 0a 24 13 01 23 0a 64 08> self.iCRC: 8891

SteidlD commented 3 years ago

Hi Vincent,

if the model is defined as "not in list, try anyway", the CRC checking is generally disabled. So no wonder you don't get CRC errors then... The questions is, why you get them on TH1 modell. Maybe your sensor has a different way of CRC calculation:

  1. Was this a single CRC errror or is the CRC generally false with the TH1-Plus model? A single CRC error actually can happen - not very often but can happen. I've already seen this with my sensor. That's why that gives only a warning and not an error. Values will be ignored and hopefully the next reading works.
  2. If the TH1-Plus really has a different way of calculating the CRC (what seems somewhat strange to me) we'd have to find out what's the polynomial, start value, and so on. At the moment the CRC will be calculate like this: CRC16_0x18005(self.cRawStatus, 0, 4, true, true, 0xFFFF, 0x0) - Meaning:
    • polynomial 0x18005
    • from byte 0 to byte 4 (first 5 bytes of the Raw Status). The CRC is transmitted in position 5&6
    • reflect input
    • reflect result
    • Initial value 0xFFFF
    • final xor with 0
  3. To find this out we'd need sufficient amount of data. Try the following:
    • set the log level to 4 (debug) - permanently in the config or online in the eve app
    • use a short interval (not the have to wait too long)
    • look in the log for all the lines like "Debug - ManufacturerData is 5406cd23009d8b3d08" and store them.
    • try to grab data where only one byte or better only 1 bit is changed (i.e. only a slight change in temperature)
    • try to find out if battery level ("3d" in example above) is included in crc (change battery, try to get same temp and humidity to see if the CRC is the same)

The rest is then a lot of calculating and guess work ;-) Send me the data and let's try to solve this riddle....

SteidlD commented 2 years ago

Hi @hadjedjvincent, are you still interested in solving this?

hadjedjvincent commented 2 years ago

Hi @SteidlD, yes of course, sorry !

I've enabled debug mode in order to retrieve the data you need.

I've managed to get same temperature+humidity with different battery level and compiled them into a table regarding all the data i've collected from the debug log.

ManufacturerData Temperature (°C) Humidity (%) Battery Level (%) Calculated CRC Expected CRC
8a051c250104062408 14.18 95 36 604 85a7
8a051c250108063008 14.18 95 48 608 85a7
8a051c250104062a08 14.18 95 42 604 85a7
8a051c25010b063008 14.18 95 48 60b 85a7
9e051c250103062f08 14.38 95 47 8697 8697
9e051c2501d5052f08 14.38 95 47 5d5 8697
9e051c2501c4053008 14.38 95 48 5c4 8697
9e051c2501b9053008 14.38 95 48 5b9 8697
9e051c2501b3052708 14.38 95 39 5b3 8697
a706b82401bd042b08 17.03 94 43 4bd b44b
bb06b8240164041f08 17.23 94 31 464 769a

It looks like the battery level is not included into the CRC calculation. Here are some of the logs if that helps you more.

Tell me if you need some more data or if i've to patch the package on my homebridge instance to test things.

Init sequence - 14.18°C - 95% humidity - 36% battery

[12/11/2021, 16:37:53] [Piscine] Initializing InkbirdBtTHSensor accessory...
[12/11/2021, 16:37:53] [Piscine] Start Initialization
[12/11/2021, 16:37:53] [Piscine] Info - Update Intervall 600s.
[12/11/2021, 16:37:53] [Piscine] Warning - Waiting for bluetooth low energy hardware to power on
[12/11/2021, 16:37:53] [Piscine] Debug - End Initialization
[12/11/2021, 16:37:53] [Piscine] Debug - Getting available services
[12/11/2021, 16:37:55] [Piscine] Debug - Start getting temperature
[12/11/2021, 16:37:55] [Piscine] Debug - Bluetooth low energy hardware powered on
[12/11/2021, 16:37:55] [Piscine] Debug - Start scanning for bluetooth sensor
[12/11/2021, 16:37:55] [Piscine] Debug - Start getting external sensor flag
[12/11/2021, 16:37:55] [Piscine] Debug - Start getting humidity
[12/11/2021, 16:37:55] [Piscine] Debug - Start getting battery low status
[12/11/2021, 16:37:55] [Piscine] Debug - Start getting battery level
[12/11/2021, 16:37:55] [Piscine] Info - Peripheral with MAC 49:42:06:00:41:90 found - stop scanning
[12/11/2021, 16:37:55] [Piscine] Debug - ManufacturerData is 8a051c250104062408
[12/11/2021, 16:37:55] [Piscine] Warning - CRC Error (expected 85a7, found 604). Ignoring data!!
{
  datalength: 9,
  localName: 'sps',
  serviceDat: undefined,
  serviceUuids: 'fff0'
}
<Buffer 8a 05 1c 25 01 04 06 24 08>
34215
[12/11/2021, 16:37:55] [Piscine] Debug - CRC Ok (85a7), temperature 14.18°C, relative humidity 95%, external sensor
[12/11/2021, 16:37:55] [Piscine] Debug - battery level 36%, battery ok
[12/11/2021, 16:37:55] [Piscine] Info - Sending temperature 14.18°C
[12/11/2021, 16:37:55] [Piscine] Info - Sending relative humidity 95%
[12/11/2021, 16:37:55] [Piscine] Info - Sending external sensor
[12/11/2021, 16:37:55] [Piscine] Info - Sending battery level 36%
[12/11/2021, 16:37:55] [Piscine] Info - Sending battery ok

14.18°C - 95% humidity - 48% battery (for compare purposes)

[12/11/2021, 17:08:06] [Piscine] Debug - ManufacturerData is 8a051c25010b063008
[12/11/2021, 17:08:06] [Piscine] Warning - CRC Error (expected 85a7, found 60b). Ignoring data!!
{
  datalength: 9,
  localName: 'sps',
  serviceDat: undefined,
  serviceUuids: 'fff0'
}
<Buffer 8a 05 1c 25 01 0b 06 30 08>
34215
[12/11/2021, 17:08:06] [Piscine] Debug - CRC Ok (85a7), temperature 14.18°C, relative humidity 95%, external sensor
[12/11/2021, 17:08:06] [Piscine] Debug - battery level 48%, battery ok
[12/11/2021, 17:08:06] [Piscine] Info - Sending temperature 14.18°C
[12/11/2021, 17:08:06] [Piscine] Info - Sending relative humidity 95%
[12/11/2021, 17:08:06] [Piscine] Info - Sending external sensor
[12/11/2021, 17:08:06] [Piscine] Info - Sending battery level 48%
[12/11/2021, 17:08:06] [Piscine] Info - Sending battery ok

14.18°C - 95% humidity - 42% battery (for compare purposes)

[12/11/2021, 16:57:59] [Piscine] Debug - ManufacturerData is 8a051c250104062a08
[12/11/2021, 16:57:59] [Piscine] Warning - CRC Error (expected 85a7, found 604). Ignoring data!!
{
  datalength: 9,
  localName: 'sps',
  serviceDat: undefined,
  serviceUuids: 'fff0'
}
<Buffer 8a 05 1c 25 01 04 06 2a 08>
34215
[12/11/2021, 16:57:59] [Piscine] Debug - CRC Ok (85a7), temperature 14.18°C, relative humidity 95%, external sensor
[12/11/2021, 16:57:59] [Piscine] Debug - battery level 42%, battery ok
[12/11/2021, 16:57:59] [Piscine] Info - Sending temperature 14.18°C
[12/11/2021, 16:57:59] [Piscine] Info - Sending relative humidity 95%
[12/11/2021, 16:57:59] [Piscine] Info - Sending external sensor
[12/11/2021, 16:57:59] [Piscine] Info - Sending battery level 42%
[12/11/2021, 16:57:59] [Piscine] Info - Sending battery ok

14.38°C - 95% humidity - 47% battery

[12/11/2021, 17:18:14] [Piscine] Debug - ManufacturerData is 9e051c250103062f08
[12/11/2021, 17:18:14] [Piscine] Warning - CRC Error (expected 8697, found 603). Ignoring data!!
{
  datalength: 9,
  localName: 'sps',
  serviceDat: undefined,
  serviceUuids: 'fff0'
}
<Buffer 9e 05 1c 25 01 03 06 2f 08>
34455
[12/11/2021, 17:18:14] [Piscine] Debug - CRC Ok (8697), temperature 14.38°C, relative humidity 95%, external sensor
[12/11/2021, 17:18:14] [Piscine] Debug - battery level 47%, battery ok
[12/11/2021, 17:18:14] [Piscine] Info - Sending temperature 14.38°C
[12/11/2021, 17:18:14] [Piscine] Info - Sending relative humidity 95%
[12/11/2021, 17:18:14] [Piscine] Info - Sending external sensor
[12/11/2021, 17:18:14] [Piscine] Info - Sending battery level 47%
[12/11/2021, 17:18:14] [Piscine] Info - Sending battery ok

14.38°C - 95% humidity - 48% battery

[12/11/2021, 17:38:24] [Piscine] Debug - ManufacturerData is 9e051c2501c4053008
[12/11/2021, 17:38:24] [Piscine] Warning - CRC Error (expected 8697, found 5c4). Ignoring data!!
{
  datalength: 9,
  localName: 'sps',
  serviceDat: undefined,
  serviceUuids: 'fff0'
}
<Buffer 9e 05 1c 25 01 c4 05 30 08>
34455
[12/11/2021, 17:38:24] [Piscine] Debug - CRC Ok (8697), temperature 14.38°C, relative humidity 95%, external sensor
[12/11/2021, 17:38:24] [Piscine] Debug - battery level 48%, battery ok
[12/11/2021, 17:38:24] [Piscine] Info - Sending temperature 14.38°C
[12/11/2021, 17:38:24] [Piscine] Info - Sending relative humidity 95%
[12/11/2021, 17:38:24] [Piscine] Info - Sending external sensor
[12/11/2021, 17:38:24] [Piscine] Info - Sending battery level 48%
[12/11/2021, 17:38:24] [Piscine] Info - Sending battery ok
SteidlD commented 2 years ago

Hi @hadjedjvincent,

thanks a lot for the good data. Here is what I think:

  1. The position where the TH1 has it's CRC is definitely not a CRC on TH1 plus with external sensor. Line 1-4 show that very good. All the 4 lines have the same data (apart from the battery). Line 1+3 have the same "CRC" value, but line 2+4 are different. Also a CRC typically changes a lot whenever you make only small changes in the data, but these values are different but very close to each other
  2. To me these values look like data transferred on the same position as the CRC on TH1 - probably there was no other room, so they let out the CRC and used the space for an additional value.
  3. Does the TH1 plus model show you the temperature of the internal and external sensor simultaneously in the app? -> then this could be the temperature of the external sensor. The values would fit as they are in the same range as the internal ones -> I added them in the table:
ManufacturerData Temperature (°C) Humidity (%) Battery Level (%) External temperature?? Expected CRC
8a051c250104062408 14.18 95 36 604 = 15.40°C 85a7
8a051c250108063008 14.18 95 48 608 = 15.44°C 85a7
8a051c250104062a08 14.18 95 42 604 = 15.40°C 85a7
8a051c25010b063008 14.18 95 48 60b = 15.47°C 85a7
9e051c250103062f08 14.38 95 47 603 = 15.39°C 8697
9e051c2501d5052f08 14.38 95 47 5d5 = 14.93°C 8697
9e051c2501c4053008 14.38 95 48 5c4 = 14.76°C 8697
9e051c2501b9053008 14.38 95 48 5b9 = 14.65°C 8697
9e051c2501b3052708 14.38 95 39 5b3 = 14.59°C 8697
a706b82401bd042b08 17.03 94 43 4bd = 12.13°C b44b
bb06b8240164041f08 17.23 94 31 464 = 11.24°C 769a

Thanks Dietmar

hadjedjvincent commented 2 years ago

Hi @SteidlD

You are right regarding the external temperature. It's not displayed into the app, or the device itself, but the values are corresponding to the internal sensor.

So, the device is returning both temperature when external sensor is plugged in. Good catch!

I can confirm that without the external sensor, there is no CRC error. Tell me how can i help ;-)

SteidlD commented 2 years ago

Hi @hadjedjvincent,

Just to be sure, could you please verify which temperature is which one, if the external sensor is connected. I would guess, that the first two bytes (The temperature that the plug-in shows) is always the internal sensor and that the external is in the place of the CRC. Heat the external sensor up a bit with your fingers or with a lighter and check which values go up.

That would be great! Thanks.

hadjedjvincent commented 2 years ago

@SteidlD The current temperature reported into Homebridge is the one from the external sensor, i'm 100% sure because it's the pool temperature and i was monitoring it during summer :) The other value is the one of the internal sensors, i've an outdoor Hue IR detector that includes a temperature sensor too, and the values were almost the same at the same time. I can check again if you want, tomorrow ;)

hadjedjvincent commented 2 years ago

Hi @SteidlD

So, here are the data you asked ;)

Before breathing into internal sensor

ManufacturerData Temperature (°C) Humidity (%) Battery Level (%) Calculated CRC Expected CRC
2105802501cf042d08 13.13 96 45 4cf 7342
2105e42501af042d08 13.13 97 45 4af ac03
2105e4250188042d08 13.13 97 45 488 ac03

After breathing into internal sensor

ManufacturerData Temperature (°C) Humidity (%) Battery Level (%) Calculated CRC Expected CRC
21055424014e0a2d08 13.13 93 45 a4e db03
2105542401bc0b2d08 13.13 93 45 bbc db03

So, the temperature went from (11.60 °C to 26.38 °C & 30.04 °C) Looks OK and confirm that this is the internal temperature at this position.

ColinDavis1 commented 2 years ago

Hi. Will there be an updated version of this plugin, as I am unable to get the external sensor of the IBS TH1 Plus to work within Homebridge. Many Thanks

SteidlD commented 2 years ago

The IBS-TH1-Plus model is supported in the newest version 0.5.0 (along with the IBS-TH2 models)

@hadjedjvincent: Could you test this on the IBS-TH1-Plus. I got myself an IBS-TH2-Plus. I guess they're compatible... Thanks