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
549 stars 116 forks source link

null values from LYWSD03MMC #257

Open kellyatkinson opened 2 years ago

kellyatkinson commented 2 years ago

[X] I've read the Troubleshooting Wiki, my problem is not described there and I am already using the specified minimum bluez version.

Describe the bug I can run the script but my sensor returns null values

Expected behavior Correct temp and humidity values should be pulled from the sensor.

Config

  workers:
    lywsd03mmc:
      args:
        devices:
          master_bedroom:  a4:c1:38:c6:76:90
        passive: true
        topic_prefix: mijasensor_gen2
      update_interval: 60

Debug gateway logs

2022-07-06 08:24:46,046 INFO bt-mqtt-gw gateway.py:75:<module> - Starting
2022-07-06 08:24:46,080 DEBUG bt-mqtt-gw.mqtt mqtt.py:35:__init__ - Setting LWT to: lwt_topic
2022-07-06 08:24:46,081 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:15:_setup - Adding 1 lywsd03mmc devices
2022-07-06 08:24:46,081 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'master_bedroom' (a4:c1:38:c6:76:90)
2022-07-06 08:24:46,081 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:98:register_workers - Added lywsd03mmc worker with 60 seconds interval and a 35 seconds timeout
2022-07-06 08:24:46,435 DEBUG bt-mqtt-gw.mqtt mqtt.py:130:callbacks_subscription - Subscribing to: mijasensor_gen2/update_interval
2022-07-06 08:24:46,435 DEBUG bt-mqtt-gw.mqtt mqtt.py:130:callbacks_subscription - Subscribing to: homeassistant/status
2022-07-06 08:24:46,440 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:168:update_all - Updating all workers
2022-07-06 08:25:06,509 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - a4:c1:38:c6:76:90 - no data received
2022-07-06 08:25:06,512 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/master_bedroom', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}]
2022-07-06 08:26:06,439 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:89:readAll - a4:c1:38:c6:76:90 - no data received
2022-07-06 08:26:06,441 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:57:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/master_bedroom', 'payload': '{"temperature": null, "humidity": null, "battery": null}'}]

Server (please complete the following information):

Additional context Sensor connects successfully to Android phone. Has pvvx firmware flashed.

jewelooper commented 1 year ago

Did you also try to set the mac in uppercase in config file? The comparison in the find_device method is case sensitive and it depends if the btle scanner delivers the found macs in uppercase or in lowercase. However for me the scanner delivers all macs in lowercase and when I set the macs in uppercase I also get null values.

Tested with: pvvx v4.0 firmware on LYWSD03MMC HW 2.0 Configured advertising format: atc1441

piatho commented 1 year ago

Hi I have the same problems with zero values coming from my LYWSD03MMC B1.6, I have flashed them with fimware v4.0

Environment:

image

I have setup the confg for one devive in uppercase and for one device in lower case. hcitool lescan shows all MAC in upercase

I have also tested the interface with some other script which generates outputs

jewelooper commented 1 year ago

@piatho Did you also checked the debug output? Are there also these "no data received" messages? What is your Config? Do you run the worker in passive mode?

How are your programming skills? I think the easiest way to get around is to place your own debug commands _LOGGER.debug in workers/lywsd03mmc.py and run the gateway in debug mode. Maybe you can place a log-command in line 35 to write out all addresses res.addr find by the scanner. If your device address is not returned by the scanner, than there may be a problem with bluez or your bluetooth driver. When your device is found you can place another command in line 38 to check the raw data value revived from your device.

piatho commented 1 year ago

Hi @jewelooper , the logs give me indeed no-data received. image

Passive mode: both tried, usually passive should be the preferred option

I would rather not think of an issue with the bluetooth driver, since the same device to provide an output and updated values when running openmqttgatway/Theengs. (Theengs is a bit to resource heavy, thats why i want to replace it)

I am running your and theengs in a container - obviously not at the same time.

On your suggestion to implement some debugs comments in the worker, i am not sure if can adjust the docker container in a way you describe. I am rather new to docker :-)

piatho commented 1 year ago

Update: I have now managed to add the loggers. I have added: _LOGGER.debug("Scanned device: %s", res) in row 35 and _LOGGER.debug("Scan data received: %s", value).

The logs showed that devices are scanned but now raw data been recorded.

That helped me to become clear that the error was about case sensitivity. "res" contains the MAC in lower cases and thus did not find a match. After changing the config file to lowercase, gateway finds values and updates perfectly.

Thanks for the help @jewelooper