zewelor / bt-mqtt-gateway

A simple Python script which provides a Bluetooth to MQTT gateway, easily extensible via custom workers. See https://github.com/zewelor/bt-mqtt-gateway/wiki for more information.
MIT License
548 stars 116 forks source link

Exception: Impedance is too high (limit >3000ohm) #148

Closed tuaminx closed 4 years ago

tuaminx commented 4 years ago

Describe the bug Mi body composition scale v2 (universe version). There is an exception: Exception: Impedance is too high (limit >3000ohm)

2020-02-09 14:02:51,903 ERROR bt-mqtt-gw logger.py:50:log_exception - Fatal error while executing worker command: Exception
Traceback (most recent call last):
  File "./gateway.py", line 89, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/bt-mqtt-gateway/bt-mqtt-gateway/workers_manager.py", line 58, in execute
    messages = self._callback(*self._args)
  File "/home/bt-mqtt-gateway/bt-mqtt-gateway/workers/miscale.py", line 72, in status_update
    results.weight, height, age, sex, int(results.impedance)
  File "/home/bt-mqtt-gateway/bt-mqtt-gateway/workers/miscale.py", line 266, in __init__
    raise Exception("Impedance is too high (limit >3000ohm)")
Exception: Impedance is too high (limit >3000ohm)
Traceback (most recent call last):
  File "./gateway.py", line 107, in <module>
    raise e
  File "./gateway.py", line 89, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/bt-mqtt-gateway/bt-mqtt-gateway/workers_manager.py", line 58, in execute
    messages = self._callback(*self._args)
  File "/home/bt-mqtt-gateway/bt-mqtt-gateway/workers/miscale.py", line 72, in status_update
    results.weight, height, age, sex, int(results.impedance)
  File "/home/bt-mqtt-gateway/bt-mqtt-gateway/workers/miscale.py", line 266, in __init__
    raise Exception("Impedance is too high (limit >3000ohm)")
Exception: Impedance is too high (limit >3000ohm)

When print the value, it's 65533

To Reproduce I just use Mi body composition scale v2 (this version provide Impedance). It happens at the first time.

Expected behavior Impedance is about 635, no exception, the "non-weight" values are correct (protein, body-mass, etc.).

Config N/A

Debug gateway logs N/A

Server (please complete the following information):

Additional context

The reason is https://github.com/zewelor/bt-mqtt-gateway/blob/master/workers/miscale.py#L183 In my case, data[24:26] = ff (1b1802a4e40702090e020ffdff3e35) This is my dirty fix (not confirm it with any document yet)

183                    self.results.impedance = int(data[22:24], 16)
184                    if data[24:26] != 'ff':
185                        self.results.impedance += int(data[24:26], 16)
dmirecki commented 4 years ago

For me, the same bug appears when I get off the MiScale just after measuring the weight, but before measuring the impedance. The expected behaviour would be in such case to send weight to mqtt without information about impedance, water etc.

I use bt-mqtt-gateway on docker and after the error occurs, whole container restarts - it's really annoying. It would be nice to have a fix for that.

tuaminx commented 4 years ago

Can you try the quick fix that I put on "Addition context"? Backup the file before modification just in case you need to get it back.

GrumpyMeow commented 4 years ago

I had the same error message. The suggested modification did resolve the error message. I didn't validate the numbers yet.