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

lywsd03mmc AttributeError passive #203

Open pidzej opened 3 years ago

pidzej commented 3 years ago

Describe the bug When added 2 lywsd03mmc getting error when start deamon lywsd03mmc running custom firmware and advertising type set to custom Config

manager:
  sensor_config:
    topic: homeassistant
    retain: true
  topic_subscription:
    update_all:
      topic: homeassistant/status
      payload: online
  command_timeout: 120
  workers:
    lywsd03mmc:
      args:
        devices:
          657: A4:C1:38:04:E6:57
          54E: A4:C1:38:A2:D5:4E
        topic_prefix: mijasensor_gen2
      update_interval: 240
      passive: false

Debug gateway logs run gateway.py with -d switch and paste formatted output log

2021-01-05 00:22:32,446 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:83:register_workers - Added thermostat config with a 2 seconds timeout
2021-01-05 00:22:32,451 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:93:register_workers - Added thermostat worker with 240 seconds interval and a 120 seconds timeout
2021-01-05 00:22:33,551 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:15:_setup - Adding 2 lywsd03mmc devices
2021-01-05 00:22:33,553 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device '657' (A4:C1:38:04:E6:57)
Traceback (most recent call last):
  File "./gateway.py", line 83, in <module>
    manager.register_workers(global_topic_prefix)
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 78, in register_workers
    command_timeout, global_topic_prefix, **worker_config["args"]
  File "/home/pi/bt-mqtt-gateway/workers/base.py", line 9, in __init__
    self._setup()
  File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 19, in _setup
    self.devices[name] = lywsd03mmc(mac, timeout=self.command_timeout, passive=self.passive)
AttributeError: 'Lywsd03MmcWorker' object has no attribute 'passive'

Server (please complete the following information):

zewelor commented 3 years ago

@westenberg

lwestenberg commented 3 years ago

Passive needs to be inside the args: in the config. Added this on the wrong level in the config.yaml.example, will change it asap.

Also note that in order to do custom firmware custom advertising readout, you will need to set passive to true. Since it will publish the temp/humidity/battery data unencrypted inside of the passive advertisement data.

pidzej commented 3 years ago

@westenberg ok changed position and pasive to true

--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.7/logging/__init__.py", line 1034, in emit
    msg = self.format(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 880, in format
    return fmt.format(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 619, in format
    record.message = record.getMessage()
  File "/usr/lib/python3.7/logging/__init__.py", line 380, in getMessage
    msg = msg % self.args
TypeError: must be real number, not NoneType
Call stack:
  File "./gateway.py", line 90, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 45, in execute
    for message in self._callback(*self._args):
  File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 43, in status_update
    ret = lywsd03mmc.readAll()
  File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 85, in readAll
    _LOGGER.debug("successfully read %f, %d, %d", temperature, humidity, battery)
Message: 'successfully read %f, %d, %d'
Arguments: (None, None, None)
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.7/logging/__init__.py", line 1034, in emit
    msg = self.format(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 880, in format
    return fmt.format(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 619, in format
    record.message = record.getMessage()
  File "/usr/lib/python3.7/logging/__init__.py", line 380, in getMessage
    msg = msg % self.args
TypeError: must be real number, not NoneType
Call stack:
  File "./gateway.py", line 90, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 45, in execute
    for message in self._callback(*self._args):
  File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 43, in status_update
    ret = lywsd03mmc.readAll()
  File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 85, in readAll
    _LOGGER.debug("successfully read %f, %d, %d", temperature, humidity, battery)
Message: 'successfully read %f, %d, %d'
Arguments: (None, None, None)
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.7/logging/__init__.py", line 1034, in emit
    msg = self.format(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 880, in format
    return fmt.format(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 619, in format
    record.message = record.getMessage()
  File "/usr/lib/python3.7/logging/__init__.py", line 380, in getMessage
    msg = msg % self.args
TypeError: must be real number, not NoneType
Call stack:
  File "./gateway.py", line 90, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 45, in execute
    for message in self._callback(*self._args):
  File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 43, in status_update
    ret = lywsd03mmc.readAll()
  File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 85, in readAll
    _LOGGER.debug("successfully read %f, %d, %d", temperature, humidity, battery)
Message: 'successfully read %f, %d, %d'
Arguments: (None, None, None)
2021-01-05 09:48:13,185 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/a', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/b', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/c', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}]
lwestenberg commented 3 years ago

looks like the logging can be improved when it can't receive the data but I can't see why it doesn't receive the data. Can you try to read the sensor with hcitool lescan or NRFconnect on android/iOS to see if the sensors are correctly flashed and outputting with custom advertisement type. Can you post the scan result line from the device with the service_data?

pidzej commented 3 years ago

hcitool lescan shows:

LE Scan ...
A4:C1:38:27:26:62 ATC_272662
A4:C1:38:04:E6:57 ATC_04E657
A4:C1:38:A2:D5:4E ATC_A2D54E
lwestenberg commented 3 years ago

I'm missing the service_data in the scan results but this could be because of the scan command. What do you get when you run: hcitool lescan --passive & hcidump --raw

pidzej commented 3 years ago
sudo hcitool lescan --passive & sudo hcidump --raw
[1] 761
LE Scan ...
HCI sniffer - Bluetooth packet analyzer ver 5.50
device: hci0 snap_len: 1500 filter: 0xffffffff
A4:C1:38:A2:D5:4E (unknown)
> 04 3E 1D 02 01 00 00 4E D5 A2 38 C1 A4 11 10 16 1A 18 A4 C1
  38 A2 D5 4E 00 D0 2F 49 0B 34 A5 B6
A4:C1:38:04:E6:57 (unknown)
> 04 3E 1D 02 01 00 00 57 E6 04 38 C1 A4 11 10 16 1A 18 A4 C1
  38 04 E6 57 00 D0 2F 58 0B BC 84 D3
A4:C1:38:27:26:62 (unknown)
> 04 3E 1D 02 01 00 00 62 26 27 38 C1 A4 11 10 16 1A 18 A4 C1
  38 27 26 62 00 D1 2F 59 0B C6 81 C7
lwestenberg commented 3 years ago

I can check/compare it some more this evening but it looks like it is not sending the custom advertising format. Can you set it again with the Telink Flasher. You can see/verify the format of the service data here: https://github.com/atc1441/ATC_MiThermometer#advertising-format-of-the-custom-firmware

pidzej commented 3 years ago

Ok, when go back to home i will check.

lwestenberg commented 3 years ago

I checked the sensors that I have and they are outputting service data that starts with the MAC address in the right order (not reversed). Let me know when you checked yours. I checked this with the NRFConnect app.

pidzej commented 3 years ago

NRFConnect show values: photo_2021-01-05_22-28-41

But gateway:

--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.7/logging/__init__.py", line 1034, in emit
    msg = self.format(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 880, in format
    return fmt.format(record)
  File "/usr/lib/python3.7/logging/__init__.py", line 619, in format
    record.message = record.getMessage()
  File "/usr/lib/python3.7/logging/__init__.py", line 380, in getMessage
    msg = msg % self.args
TypeError: must be real number, not NoneType
Call stack:
  File "./gateway.py", line 90, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 45, in execute
    for message in self._callback(*self._args):
  File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 43, in status_update
    ret = lywsd03mmc.readAll()
  File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 85, in readAll
    _LOGGER.debug("successfully read %f, %d, %d", temperature, humidity, battery)
Message: 'successfully read %f, %d, %d'
Arguments: (None, None, None)
2021-01-05 22:29:11,108 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/a', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}]
lwestenberg commented 3 years ago

In the screenshot you show the connected tab with all services. In this case connecting is not needed. Just go to the scanner tab, click on the device and then send a screen of the device expanded. Thanks.

pidzej commented 3 years ago

photo_2021-01-05_23-04-11

lwestenberg commented 3 years ago

Your data is correct. I managed to reproduce the issue here for 1/4 sensors that I have, which is weird. Will look into it tomorrow.

pidzej commented 3 years ago

I have 3 not working sensors. ID 2019DP8115 good night

lwestenberg commented 3 years ago

For the error I will add a check for None. But beside that I just discovered that this is caused by the sensor being too far away from the bluetooth scanner. Moved mine closer and it no longer has null values in MQTT.

Can you try it as well.

pidzej commented 3 years ago

No its not a problem 2m 1m 0,5m same: Arguments: (None, None, None)

lwestenberg commented 3 years ago

Made a PR to first fix the logging and add some logging so we can debug this better: https://github.com/zewelor/bt-mqtt-gateway/pull/207

the null results are only happening here when the device can't be found. This can e.g. be because of wrong Mac address set, too short scan duration or device out of reach. In the code the scan_timeout was on 10 sec by default. I changed it to 20 and you can now customise it as well in the config.

Check if any cases above for not being able to reach the device are applicable for your situation after updating. If not then share the improved logging output.

lwestenberg commented 3 years ago

@pidzej did you check the update?

pidzej commented 3 years ago

Yes but no data: Sensors are 1m far from raspberry

2021-01-07 23:56:01,844 INFO bt-mqtt-gw gateway.py:75:<module> - Starting
2021-01-07 23:56:01,926 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:__init__ - Setting LWT to: lwt_topic
2021-01-07 23:56:01,932 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:15:_setup - Adding 3 lywsd03mmc devices
2021-01-07 23:56:01,935 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'a' (A4:C1:38:27:26:62)
2021-01-07 23:56:01,938 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'b' (A4:C1:38:04:E6:57)
2021-01-07 23:56:01,942 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'c' (A4:C1:38:A2:D5:4E)
2021-01-07 23:56:01,946 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:93:register_workers - Added lywsd03mmc worker with 120 seconds interval and a 120 seconds timeout
2021-01-07 23:56:03,121 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: mijasensor_gen2/update_interval
2021-01-07 23:56:03,127 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: homeassistant/status
2021-01-07 23:56:03,153 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:159:update_all - Updating all workers
2021-01-07 23:56:23,510 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:27:26:62 - no data received
2021-01-07 23:56:23,516 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:04:E6:57 - no data received
2021-01-07 23:56:23,520 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:A2:D5:4E - no data received
2021-01-07 23:56:23,525 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/a', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/b', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/c', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}]
2021-01-07 23:58:23,147 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:27:26:62 - no data received
2021-01-07 23:58:23,151 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:04:E6:57 - no data received
2021-01-07 23:58:23,156 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:A2:D5:4E - no data received
2021-01-07 23:58:23,161 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/a', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/b', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/c', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}]
2021-01-08 00:00:23,157 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:27:26:62 - no data received
2021-01-08 00:00:23,161 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:04:E6:57 - no data received
2021-01-08 00:00:23,166 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:A2:D5:4E - no data received
2021-01-08 00:00:23,170 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/a', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/b', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/c', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}]
2021-01-08 00:02:23,186 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:27:26:62 - no data received
2021-01-08 00:02:23,191 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:04:E6:57 - no data received
2021-01-08 00:02:23,196 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:A2:D5:4E - no data received
2021-01-08 00:02:23,200 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/a', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/b', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/c', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}]
2021-01-08 00:04:23,180 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:27:26:62 - no data received
2021-01-08 00:04:23,184 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:04:E6:57 - no data received
2021-01-08 00:04:23,188 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:A2:D5:4E - no data received
2021-01-08 00:04:23,193 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/a', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/b', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/c', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}]
2021-01-08 00:06:23,178 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:27:26:62 - no data received
2021-01-08 00:06:23,183 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:04:E6:57 - no data received
2021-01-08 00:06:23,188 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:A2:D5:4E - no data received
2021-01-08 00:06:23,192 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/a', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/b', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/c', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}]
2021-01-08 00:08:23,187 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:27:26:62 - no data received
2021-01-08 00:08:23,191 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:04:E6:57 - no data received
2021-01-08 00:08:23,195 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:A2:D5:4E - no data received
2021-01-08 00:08:23,200 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/a', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/b', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}, {'topic': 'mijasensor_gen2/c', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}]
lwestenberg commented 3 years ago

What the logging tells is that it is not receiving any data for the sensors in the Bluetooth scan loop. According to your previous NRFconnect screenshot I saw that the sensors are correctly setup so that would mean it is something in the receiving part of your Bluetooth scanner. Not in the sensor and not a bug in the worker code.

MihataBG commented 3 years ago

Same issue here:

2021-01-11 15:39:14,737 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:8A:E6:54 - no data received
2021-01-11 15:39:14,738 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/bathroom', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}]

Screenshot_20210111-153558

lwestenberg commented 3 years ago

I will look into it asap and check if I can reproduce it. What hardware are you using?

MihataBG commented 3 years ago

I will look into it asap and check if I can reproduce it. What hardware are you using?

home-lab server with Debian 10 and CSR8510 A10 (Bus 001 Device 003: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode))

FW is https://github.com/pvvx/ATC_MiThermometer/raw/master/ATC_Thermometer11.bin

P.S. Now ill check new FW (https://github.com/pvvx/ATC_MiThermometer/raw/master/ATC_Thermometer12.bin)

Edit: with FW 1.2 same issue

2021-01-11 15:59:02,998 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - A4:C1:38:8A:E6:54 - no data received
2021-01-11 15:59:02,998 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/bathroom', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}]

Edit2: MAC address is case sensitive, if we set as lowercase we can get data. But in my case this data is wrong as you can see. I think its a little-endian.

2021-01-11 17:12:47,939 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:39:status_update - a4:c1:38:8a:e6:54 - received scan data 1a1854e68a38c1a4dd094419d50a3fc304
2021-01-11 17:12:47,939 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:87:readAll - a4:c1:38:8a:e6:54 - found values 5658.500000, 68, 25
2021-01-11 17:12:47,939 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/bathroom', 'payload': '{"temperature": 5658.5, "humidity": 68, "battery": 25}'}]

Edit 3: We can set adv format in @pvvx firmware, when it set as atc1441 everything works fine.

loopy321 commented 3 years ago

Is it possible to have the worker parse both the "adv" and "mi like" formats for the ATC firmware?

Mi like is useful with esphome, but was hoping to have the sensor read with bt-mqtt-gateway as well. Added debug readout to show the data:

DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:39:status_update - a4:c1:38:fd:bc:15 - received scan data 95fe50305b05d215bcfd38c1a40a100158000000

DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:39:status_update - a4:c1:38:fd:bc:15 - received scan data 95fe50305b05d315bcfd38c1a40d1004ed005401

"Mi like" advertising comes from here And is used in esphome

Thanks!

sorenbache commented 3 years ago

There is something wrong for sure with the calculation of the temperature when the temperature goes below zero (not sure about the exact value). I am running passive mode with the ATC firmware from @pvvx, with advertising mode set as atc1441.

2021-01-28 22:15:47,346 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:39:status_update - a4:c1:38:8f:ea:f5 - received scan data 1a18a4c1388feaf500e5285c0bd6de 2021-01-28 22:15:47,347 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:39:status_update - a4:c1:38:35:90:c4 - received scan data 1a18a4c1383590c4ffe452440b0414 2021-01-28 22:15:47,348 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:87:readAll - a4:c1:38:8f:ea:f5 - found values 22.900000, 40, 92 2021-01-28 22:15:47,349 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:87:readAll - a4:c1:38:35:90:c4 - found values 6550.800000, 82, 68

So the data with temperature 'ffe4' gets converted to a temp of 6550.800000. The calculation seems wrong:

int(data[16:20], 16) / 10

Compare this with the calculation that is done in this https://github.com/JsBergbau/MiTemperature2 where it works fine:

temperature = int.from_bytes(bytearray.fromhex(data[16:20]),byteorder='big',signed=True) / 10.

@westenberg

dingausmwald commented 3 years ago

Does this work now properly? And, is there any chance we can get the custom advertising mode from pvvx firmware implemented?

krzysztofkh commented 3 years ago

I can confirm the problem, it still exists.

scetu commented 2 years ago

Ok wanted to switch from ESP32 to RPi Zero for BLE Tracking, but cant get to work any of my lywsd03mmc flashed with pvvx firmware - tried setting up beacon type to all, but can't get readings from any device. Running with latest Docker image.

Always getting

Start in normal mode
15:11:43 Starting
15:11:43 Adding 1 lywsd03mmc_homeassistant devices
15:11:44 Updating 1 lywsd03mmc_homeassistant devices
15:11:49 Error during update of lywsd03mmc_homeassistant device 'device' (<MAC>): BTLEGattError
15:13:44 Updating 1 lywsd03mmc_homeassistant devices
15:13:50 Error during update of lywsd03mmc_homeassistant device 'device' (<MAC>): BTLEGattError
15:15:44 Updating 1 lywsd03mmc_homeassistant devices
15:15:47 Error during update of lywsd03mmc_homeassistant device 'device' (<MAC>): BTLEGattError
15:17:44 Updating 1 lywsd03mmc_homeassistant devices
15:17:56 Error during update of lywsd03mmc_homeassistant device 'device' (<MAC>): BTLEGattError
15:19:44 Updating 1 lywsd03mmc_homeassistant devices
15:19:48 Error during update of lywsd03mmc_homeassistant device 'device' (<MAC>): BTLEGattError
15:21:44 Updating 1 lywsd03mmc_homeassistant devices
15:21:47 Error during update of lywsd03mmc_homeassistant device 'device' (<MAC>): BTLEGattError
15:23:44 Updating 1 lywsd03mmc_homeassistant devices
pvvx commented 2 years ago

The format is expected to change to new "HA_BLE" in newer versions when it becomes available in Home Assistant. Participate in Support home brew DIY sensors After the formation of a new version, the format ATC1441 will no longer be supported.