Open Yvon-Indel opened 4 years ago
Try this branch https://github.com/zewelor/bt-mqtt-gateway/pull/170 to see if it solves this.
today my second sensor arrived and can test this, with your PR i got this message:
Traceback (most recent call last):
File "./gateway.py", line 89, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/opt/bt-mqtt-gateway/app/workers_manager.py", line 56, in execute
messages += message
TypeError: 'MqttMessage' object is not iterable
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 "/opt/bt-mqtt-gateway/app/workers_manager.py", line 56, in execute
messages += message
TypeError: 'MqttMessage' object is not iterable
Currently this Workaround works (for me :) ):
return "/".join([self.topic_prefix, *args])
def status_update(self):
+ result = []
for name, lywsd03mmc in self.devices.items():
ret = lywsd03mmc.readAll()
if not ret:
- return []
+ continue
- return [
- MqttMessage(
- topic=self.format_static_topic(name), payload=json.dumps(ret)
- )
- ]
+ mqttmsg = MqttMessage(
+ topic=self.format_static_topic(name), payload=json.dumps(ret)
+ )
+ result.append(mqttmsg)
+
+ return result
def __repr__(self):
return self.__module__.split(".")[-1]
Try this branch #170 to see if it solves this.
Hi,
No, i've got the same error as above.
(.venv) pi@raspberrypi:~/bt-mqtt-gateway $ sudo ./gateway.py -d
2020-04-27 18:21:48,966 INFO bt-mqtt-gw gateway.py:75:<module> - Starting
2020-04-27 18:21:48,979 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:__init__ - Setting LWT to: lwt_topic
2020-04-27 18:21:57,575 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:16:_setup - Adding 2 lywsd03mmc devices
2020-04-27 18:21:57,584 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'chambre' (A4:C1:38:12:E3:AB)
2020-04-27 18:21:57,594 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'veranda' (A4:C1:38:1E:29:DF)
2020-04-27 18:21:57,604 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:107:register_workers - Added lywsd03mmc worker with 60 seconds interval and a 35 seconds timeout
2020-04-27 18:21:57,721 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: mijasensor_gen2/update_interval
2020-04-27 18:21:57,730 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: homeassistant/status
2020-04-27 18:21:57,824 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:173:update_all - Updating all workers
2020-04-27 18:21:59,275 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:52:connected - A4:C1:38:12:E3:AB connected
2020-04-27 18:22:06,325 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:readAll - successfully read 21.800000, 59, 2
2020-04-27 18:22:06,346 ERROR bt-mqtt-gw logger.py:50:log_exception - Fatal error while executing worker command: TypeError
Traceback (most recent call last):
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 57, in execute
messages += message
TypeError: 'MqttMessage' object is not iterable
Traceback (most recent call last):
File "./gateway.py", line 106, in <module>
raise e
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 57, in execute
messages += message
TypeError: 'MqttMessage' object is not iterable
Right stupid error, plz try now.
seem to read the second device now but an error occurs just after
(.venv) pi@raspberrypi:~/bt-mqtt-gateway $ sudo ./gateway.py -d
2020-04-27 18:54:32,976 INFO bt-mqtt-gw gateway.py:75:<module> - Starting
2020-04-27 18:54:32,989 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:__init__ - Setting LWT to: lwt_topic
2020-04-27 18:54:41,017 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:16:_setup - Adding 2 lywsd03mmc devices
2020-04-27 18:54:41,022 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'chambre' (A4:C1:38:12:E3:AB)
2020-04-27 18:54:41,028 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'veranda' (A4:C1:38:1E:29:DF)
2020-04-27 18:54:41,035 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:107:register_workers - Added lywsd03mmc worker with 60 seconds interval and a 35 seconds timeout
2020-04-27 18:54:41,104 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: mijasensor_gen2/update_interval
2020-04-27 18:54:41,114 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: homeassistant/status
2020-04-27 18:54:41,170 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:173:update_all - Updating all workers
2020-04-27 18:54:41,780 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:52:connected - A4:C1:38:12:E3:AB connected
2020-04-27 18:54:50,672 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:readAll - successfully read 21.800000, 59, 2
2020-04-27 18:54:50,697 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:52:connected - A4:C1:38:1E:29:DF connected
2020-04-27 18:54:58,332 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:readAll - successfully read 24.000000, 54, 2
2020-04-27 18:54:58,368 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/chambre', 'payload': '{"temperature": 21.8, "humidity": 59, "battery": 2.997}'}, {'topic': 'mijasensor_gen2/veranda', 'payload': '{"temperature": 24.0, "humidity": 54, "battery": 2.95}'}]
2020-04-27 18:55:41,108 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:52:connected - A4:C1:38:12:E3:AB connected
2020-04-27 18:55:45,262 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:60:connected - failed connect Failed to connect to peripheral A4:C1:38:12:E3:AB, addr type: public
2020-04-27 18:55:45,275 ERROR bt-mqtt-gw logger.py:50:log_exception - Fatal error while executing worker command: AttributeError
Traceback (most recent call last):
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 56, in execute
for message in self._callback(*self._args):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 29, in status_update
logger.debug("Error during update of %s device '%s'", repr(self), name)
AttributeError: module 'logger' has no attribute 'debug'
Traceback (most recent call last):
File "./gateway.py", line 106, in <module>
raise e
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 56, in execute
for message in self._callback(*self._args):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 29, in status_update
logger.debug("Error during update of %s device '%s'", repr(self), name)
AttributeError: module 'logger' has no attribute 'debug'
FIxed
The fist connexion is ok, i see 2 topics
{"temperature": 21.7, "humidity": 60, "battery": 2.968}
qos : 0, retain : false, cmd : publish, dup : false, topic : mijasensor_gen2/chambre, messageId : , length : 80, Raw payload : 123341161011091121011149711611711410134583250494655443234104117109105100105116121345832544844323498971161161011141213458325046575456125
{"temperature": 23.8, "humidity": 56, "battery": 2.95}
qos : 0, retain : false, cmd : publish, dup : false, topic : mijasensor_gen2/veranda, messageId : , length : 79, Raw payload : 1233411610110911210111497116117114101345832505146564432341041171091051001051161213458325354443234989711611610111412134583250465753125
After only one topics , always the same device
{"temperature": 21.7, "humidity": 60, "battery": 2.968}
qos : 0, retain : false, cmd : publish, dup : false, topic : mijasensor_gen2/chambre, messageId : , length : 80, Raw payload : 123341161011091121011149711611711410134583250494655443234104117109105100105116121345832544844323498971161161011141213458325046575456125
{"temperature": 21.7, "humidity": 60, "battery": 2.968}
qos : 0, retain : false, cmd : publish, dup : false, topic : mijasensor_gen2/chambre, messageId : , length : 80, Raw payload : 123341161011091121011149711611711410134583250494655443234104117109105100105116121345832544844323498971161161011141213458325046575456125
{"temperature": 21.8, "humidity": 60, "battery": 2.968}
qos : 0, retain : false, cmd : publish, dup : false, topic : mijasensor_gen2/chambre, messageId : , length : 80, Raw payload : 123341161011091121011149711611711410134583250494656443234104117109105100105116121345832544844323498971161161011141213458325046575456125
and finally an error occurs
below the complete log.
(.venv) pi@raspberrypi:~/bt-mqtt-gateway $ sudo ./gateway.py -d 2020-04-27 19:25:32,959 INFO bt-mqtt-gw gateway.py:75:<module> - Starting
2020-04-27 19:25:32,975 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:__init__ - Setting LWT to: lwt_topic
2020-04-27 19:25:41,173 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:16:_set up - Adding 2 lywsd03mmc devices
2020-04-27 19:25:41,179 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_set up - Adding lywsd03mmc device 'chambre' (A4:C1:38:12:E3:AB)
2020-04-27 19:25:41,185 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_set up - Adding lywsd03mmc device 'veranda' (A4:C1:38:1E:29:DF)
2020-04-27 19:25:41,192 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:107: register_workers - Added lywsd03mmc worker with 120 seconds interval and a 35 se conds timeout
2020-04-27 19:25:41,260 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: mijasensor_gen2/update_interval
2020-04-27 19:25:41,270 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: homeassistant/status
2020-04-27 19:25:41,327 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:173: update_all - Updating all workers
2020-04-27 19:25:41,946 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:52:con nected - A4:C1:38:12:E3:AB connected
2020-04-27 19:25:58,834 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:rea dAll - successfully read 21.700000, 60, 2
2020-04-27 19:25:58,856 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:52:con nected - A4:C1:38:1E:29:DF connected
2020-04-27 19:26:13,180 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:60:con nected - failed connect Failed to connect to peripheral A4:C1:38:1E:29:DF, addr type: public
2020-04-27 19:26:13,213 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:29:sta tus_update - Error during update of lywsd03mmc device 'veranda'
2020-04-27 19:26:13,224 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:e xecute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/chambre', 'payload': '{"temperature": 21.7, "humidity": 60, "ba ttery": 2.968}'}]
2020-04-27 19:27:41,264 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:52:connected - A4:C1:38:12:E3:AB connected
2020-04-27 19:27:52,834 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:readAll - successfully read 21.800000, 60, 2
2020-04-27 19:27:52,856 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:52:connected - A4:C1:38:1E:29:DF connected
2020-04-27 19:28:03,857 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:readAll - successfully read 23.800000, 56, 2
2020-04-27 19:28:03,880 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/chambre', 'payload': '{"temperature": 21.8, "humidity": 60, "battery": 2.968}'}, {'topic': 'mijasensor_gen2/veranda', 'payload': '{"temperature": 23.8, "humidity": 56, "battery": 2.95}'}]
2020-04-27 19:29:41,268 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:52:connected - A4:C1:38:12:E3:AB connected
2020-04-27 19:29:47,834 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:readAll - successfully read 21.800000, 60, 2
2020-04-27 19:29:47,857 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:52:connected - A4:C1:38:1E:29:DF connected
2020-04-27 19:29:57,834 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:readAll - successfully read 23.800000, 55, 2
2020-04-27 19:29:57,858 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/chambre', 'payload': '{"temperature": 21.8, "humidity": 60, "battery": 2.968}'}, {'topic': 'mijasensor_gen2/veranda', 'payload': '{"temperature": 23.8, "humidity": 55, "battery": 2.95}'}]
2020-04-27 19:31:41,314 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:52:connected - A4:C1:38:12:E3:AB connected
2020-04-27 19:31:45,178 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:readAll - successfully read 21.800000, 60, 2
2020-04-27 19:31:45,200 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:52:connected - A4:C1:38:1E:29:DF connected
2020-04-27 19:31:54,245 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:60:connected - failed connect Device disconnected
2020-04-27 19:31:54,264 ERROR bt-mqtt-gw logger.py:50:log_exception - Fatal error while executing worker command: RuntimeError
Traceback (most recent call last):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 57, in connected
yield device
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 68, in readAll
self.getData(device)
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 84, in getData
if device.waitForNotifications(self.timeout):
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 560, in waitForNotifications
resp = self._getResp(['ntfy','ind'], timeout)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 407, in _getResp
resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 362, in _waitResp
raise BTLEDisconnectError("Device disconnected", resp)
bluepy.btle.BTLEDisconnectError: Device disconnected
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 56, in execute
for message in self._callback(*self._args):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 26, in status_update
ret = lywsd03mmc.readAll()
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 78, in readAll
"battery": battery,
File "/usr/lib/python3.7/contextlib.py", line 161, in __exit__
raise RuntimeError("generator didn't stop after throw()")
RuntimeError: generator didn't stop after throw()
Traceback (most recent call last):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 57, in connected
yield device
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 68, in readAll
self.getData(device)
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 84, in getData
if device.waitForNotifications(self.timeout):
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 560, in waitForNotifications
resp = self._getResp(['ntfy','ind'], timeout)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 407, in _getResp
resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 362, in _waitResp
raise BTLEDisconnectError("Device disconnected", resp)
bluepy.btle.BTLEDisconnectError: Device disconnected
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./gateway.py", line 106, in <module>
raise e
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 56, in execute
for message in self._callback(*self._args):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 26, in status_update
ret = lywsd03mmc.readAll()
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 78, in readAll
"battery": battery,
File "/usr/lib/python3.7/contextlib.py", line 161, in __exit__
raise RuntimeError("generator didn't stop after throw()")
RuntimeError: generator didn't stop after throw()
Looks like this worker needs better exception handling. Hard to debug without device, lets hope someone will look into this.
ok, thanks for your job.
May be some clues: I increase the command_timeout to 45 and all was working for about 30 min.
After, i put one device out of range and the error occurs:
2020-04-27 20:14:18,276 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:60:connected - failed connect Device disconnected
2020-04-27 20:14:18,293 ERROR bt-mqtt-gw logger.py:50:log_exception - Fatal error while executing worker command: RuntimeError
Traceback (most recent call last):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 57, in connected
yield device
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 68, in readAll
self.getData(device)
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 84, in getData
if device.waitForNotifications(self.timeout):
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 560, in waitForNotifications
resp = self._getResp(['ntfy','ind'], timeout)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 407, in _getResp
resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 362, in _waitResp
raise BTLEDisconnectError("Device disconnected", resp)
bluepy.btle.BTLEDisconnectError: Device disconnected
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 56, in execute
for message in self._callback(*self._args):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 26, in status_update
ret = lywsd03mmc.readAll()
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 78, in readAll
"battery": battery,
File "/usr/lib/python3.7/contextlib.py", line 161, in __exit__
raise RuntimeError("generator didn't stop after throw()")
RuntimeError: generator didn't stop after throw()
Traceback (most recent call last):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 57, in connected
yield device
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 68, in readAll
self.getData(device)
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 84, in getData
if device.waitForNotifications(self.timeout):
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 560, in waitForNotifications
resp = self._getResp(['ntfy','ind'], timeout)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 407, in _getResp
resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 362, in _waitResp
raise BTLEDisconnectError("Device disconnected", resp)
bluepy.btle.BTLEDisconnectError: Device disconnected
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./gateway.py", line 106, in <module>
raise e
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 56, in execute
for message in self._callback(*self._args):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 26, in status_update
ret = lywsd03mmc.readAll()
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 78, in readAll
"battery": battery,
File "/usr/lib/python3.7/contextlib.py", line 161, in __exit__
raise RuntimeError("generator didn't stop after throw()")
RuntimeError: generator didn't stop after throw()
I can do some test if needed.
Added some fixes for exception handling, please try now.
2020-04-28 21:53:15,737 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - XX:XX:XX:XX:XX:XX connected
2020-04-28 21:53:15,766 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:80:connected - failed connect Failed to connect to peripheral XX:XX:XX:XX:XX:XX, addr type: public
2020-04-28 21:53:15,767 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:32:status_update - Error during update of lywsd03mmc device 'tempsensor1'
2020-04-28 21:53:15,768 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:37:3A:67 connected
2020-04-28 21:53:19,100 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:93:readAll - successfully read 20.900000, 54, 2
2020-04-28 21:53:19,105 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor/tempsensor2', 'payload': '{"temperature": 20.9, "humidity": 54, "battery": 2.79}'}]
2020-04-28 21:53:19,108 INFO bt-mqtt-gw.workers.thermostat thermostat.py:190:status_update - Updating 2 thermostat devices
2020-04-28 21:53:19,109 DEBUG bt-mqtt-gw.workers.thermostat thermostat.py:192:status_update - Updating thermostat device 'tempsensor1' (00:1A:22:10:F3:26)
the tempsensor does not get any data now :/
You mean only one thermostat gets updated ? Can you paste full log with better formatting ?
Hi,
I try with 3 sensors:
config.yaml
mqtt:
host: 192.168.1.27
port: 1883
username: xxxx
password: xxxx
#ca_cert: /etc/ssl/certs/ca-certificates.crt # Uncomment to enable MQTT TLS, update path to appropriate location.
#ca_verify: False # Verify TLS certificate chain and host, disable for testing with self-signed certificates, default to True
topic_prefix: # All messages will have that prefix added, remove if you dont need this.
client_id: bt-mqtt-gateway
availability_topic: lwt_topic
manager:
sensor_config:
topic: homeassistant
retain: true
topic_subscription:
update_all:
topic: homeassistant/status
payload: online
command_timeout: 60 # Timeout for worker operations. Can be removed if the default of 35 seconds is sufficient.
workers:
lywsd03mmc:
args:
devices:
chambre: A4:C1:38:12:E3:AB
veranda: A4:C1:38:1E:29:DF
cuisine: A4:C1:38:47:77:99
topic_prefix: mijasensor_gen2
update_interval: 120
1-There is more fail to connect 2- I put the the sensor "veranda" out of range and the error occurs.
Here is the log:
(.venv) pi@raspberrypi:~/bt-mqtt-gateway $ sudo ./gateway.py -d
2020-04-29 11:52:14,903 INFO bt-mqtt-gw gateway.py:75:<module> - Starting
2020-04-29 11:52:14,921 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:__init__ - Setting LWT to: lwt_topic
2020-04-29 11:52:22,347 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:16:_setup - Adding 3 lywsd03mmc devices
2020-04-29 11:52:22,352 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'chambre' (A4:C1:38:12:E3:AB)
2020-04-29 11:52:22,358 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'veranda' (A4:C1:38:1E:29:DF)
2020-04-29 11:52:22,364 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'cuisine' (A4:C1:38:47:77:99)
2020-04-29 11:52:22,370 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:107:register_workers - Added lywsd03mmc worker with 120 seconds interval and a 60 seconds timeout
2020-04-29 11:52:22,432 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: mijasensor_gen2/update_interval
2020-04-29 11:52:22,442 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: homeassistant/status
2020-04-29 11:52:22,491 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:173:update_all - Updating all workers
2020-04-29 11:52:23,058 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:12:E3:AB connected
2020-04-29 11:52:31,434 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:80:connected - failed connect Failed to connect to peripheral A4:C1:38:12:E3:AB, addr type: public
2020-04-29 11:52:31,478 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:32:status_update - Error during update of lywsd03mmc device 'chambre'
2020-04-29 11:52:31,487 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:1E:29:DF connected
2020-04-29 11:52:48,221 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:93:readAll - successfully read 20.900000, 54, 2
2020-04-29 11:52:48,244 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:47:77:99 connected
2020-04-29 11:52:54,664 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:93:readAll - successfully read 22.200000, 52, 3
2020-04-29 11:52:54,688 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/veranda', 'payload': '{"temperature": 20.9, "humidity": 54, "battery": 2.976}'}, {'topic': 'mijasensor_gen2/cuisine', 'payload': '{"temperature": 22.2, "humidity": 52, "battery": 3.052}'}]
2020-04-29 11:54:22,444 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:12:E3:AB connected
2020-04-29 11:54:27,416 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:93:readAll - successfully read 20.800000, 53, 2
2020-04-29 11:54:27,438 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:1E:29:DF connected
2020-04-29 11:54:39,374 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:93:readAll - successfully read 21.000000, 54, 2
2020-04-29 11:54:39,395 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:47:77:99 connected
2020-04-29 11:54:57,721 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:93:readAll - successfully read 22.200000, 52, 3
2020-04-29 11:54:57,743 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/chambre', 'payload': '{"temperature": 20.8, "humidity": 53, "battery": 2.998}'}, {'topic': 'mijasensor_gen2/veranda', 'payload': '{"temperature": 21.0, "humidity": 54, "battery": 2.976}'}, {'topic': 'mijasensor_gen2/cuisine', 'payload': '{"temperature": 22.2, "humidity": 52, "battery": 3.052}'}]
2020-04-29 11:56:22,445 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:12:E3:AB connected
2020-04-29 11:56:28,221 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:93:readAll - successfully read 20.600000, 54, 2
2020-04-29 11:56:28,244 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:1E:29:DF connected
2020-04-29 11:56:41,221 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:93:readAll - successfully read 20.900000, 54, 2
2020-04-29 11:56:41,244 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:47:77:99 connected
2020-04-29 11:56:56,721 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:93:readAll - successfully read 22.200000, 52, 3
2020-04-29 11:56:56,745 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/chambre', 'payload': '{"temperature": 20.6, "humidity": 54, "battery": 2.998}'}, {'topic': 'mijasensor_gen2/veranda', 'payload': '{"temperature": 20.9, "humidity": 54, "battery": 2.976}'}, {'topic': 'mijasensor_gen2/cuisine', 'payload': '{"temperature": 22.2, "humidity": 52, "battery": 3.052}'}]
2020-04-29 11:58:22,445 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:12:E3:AB connected
2020-04-29 11:58:30,721 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:93:readAll - successfully read 20.600000, 54, 2
2020-04-29 11:58:30,745 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:1E:29:DF connected
2020-04-29 11:58:46,469 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:80:connected - failed connect Failed to connect to peripheral A4:C1:38:1E:29:DF, addr type: public
2020-04-29 11:58:46,492 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:32:status_update - Error during update of lywsd03mmc device 'veranda' -> I put the sensor out of range
2020-04-29 11:58:46,504 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:47:77:99 connected
2020-04-29 11:58:54,375 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:80:connected - failed connect Failed to connect to peripheral A4:C1:38:47:77:99, addr type: public
2020-04-29 11:58:54,381 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:32:status_update - Error during update of lywsd03mmc device 'cuisine'
2020-04-29 11:58:54,388 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/chambre', 'payload': '{"temperature": 20.6, "humidity": 54, "battery": 2.998}'}]
2020-04-29 12:00:22,490 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:12:E3:AB connected
2020-04-29 12:00:29,550 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:80:connected - failed connect Failed to connect to peripheral A4:C1:38:12:E3:AB, addr type: public
2020-04-29 12:00:29,561 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:32:status_update - Error during update of lywsd03mmc device 'chambre'
2020-04-29 12:00:29,578 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:1E:29:DF connected
2020-04-29 12:01:22,496 ERROR bt-mqtt-gw logger.py:50:log_exception - Execution of command Lywsd03MmcWorker.status_update timed out after 60 seconds
Traceback (most recent call last):
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 66, in execute
raise e
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 56, in execute
for message in self._callback(*self._args):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 28, in status_update
ret = lywsd03mmc.readAll()
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 84, in readAll
with self.connected() as device:
File "/usr/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 75, in connected
device.writeCharacteristic(0x0038, b'\x01\x00', True)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 543, in writeCharacteristic
return self._getResp('wr')
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 407, in _getResp
resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 347, in _waitResp
rv = self._helper.stdout.readline()
File "/usr/local/lib/python3.7/dist-packages/interruptingcow/__init__.py", line 74, in handler
raise exception
exceptions.WorkerTimeoutError: Execution of command Lywsd03MmcWorker.status_update timed out after 60 seconds
after this error, there will be no new data:
2020-04-29 13:39:53,512 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:FC:DA:3B connected
2020-04-29 13:40:02,307 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:80:connected - failed connect Failed to connect to peripheral A4:C1:38:FC:DA:3B, addr type: public
2020-04-29 13:40:02,308 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:32:status_update - Error during update of lywsd03mmc device 'tempsensor1'
2020-04-29 13:40:02,308 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:72:connected - A4:C1:38:37:3A:XX connected
2020-04-29 13:40:13,513 ERROR bt-mqtt-gw logger.py:50:log_exception - Execution of command Lywsd03MmcWorker.status_update timed out after 20 seconds
Traceback (most recent call last):
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/opt/bt-mqtt-gateway/app/workers_manager.py", line 66, in execute
raise e
File "/opt/bt-mqtt-gateway/app/workers_manager.py", line 56, in execute
for message in self._callback(*self._args):
File "/opt/bt-mqtt-gateway/app/workers/lywsd03mmc.py", line 28, in status_update
ret = lywsd03mmc.readAll()
File "/opt/bt-mqtt-gateway/app/workers/lywsd03mmc.py", line 88, in readAll
self.getData(device)
File "/opt/bt-mqtt-gateway/app/workers/lywsd03mmc.py", line 104, in getData
if device.waitForNotifications(self.timeout):
File "/opt/bt-mqtt-gateway/app/.venv/lib/python3.7/site-packages/bluepy/btle.py", line 560, in waitForNotifications
resp = self._getResp(['ntfy','ind'], timeout)
File "/opt/bt-mqtt-gateway/app/.venv/lib/python3.7/site-packages/bluepy/btle.py", line 407, in _getResp
resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
File "/opt/bt-mqtt-gateway/app/.venv/lib/python3.7/site-packages/bluepy/btle.py", line 342, in _waitResp
fds = self._poller.poll(timeout*1000)
File "/opt/bt-mqtt-gateway/app/.venv/lib/python3.7/site-packages/interruptingcow/__init__.py", line 74, in handler
raise exception
exceptions.WorkerTimeoutError: Execution of command Lywsd03MmcWorker.status_update timed out after 20 seconds
i've tested a while, and may its an issue with the device? bcz when bt-mqtt-gateway does not can handle this device. it does not shows up with "hcitool lescan", only when restart the LYWSD03MMC, the its possible to get data...
i've tested a while, and may its an issue with the device? bcz when bt-mqtt-gateway does not can handle this device. it does not shows up with "hcitool lescan", only when restart the LYWSD03MMC, the its possible to get data...
Yes, sometime the device is not responding, event if it's connected. I try also with gatttool. I guess that trying to get data more than 1 times (3 ?) before exiting with "Failed to connect to peripheral" will help not loosing data.
This is what your script at https://github.com/mklooss/MiTemperature2 seems to do:
Trying to connect to A4:C1:38:12:E3:AB
Connection lost
Waiting...
Trying to connect to A4:C1:38:12:E3:AB
Connection lost
Waiting...
Trying to connect to A4:C1:38:12:E3:AB
Connection lost
Waiting...
Trying to connect to A4:C1:38:12:E3:AB
Temperature: 20.6
Humidity: 56
Battery voltage: 2.977
Hi,
i try to code what was in my mind. The code try to connect x time before exiting.
I'ts better for me because as you can see in the log, sometime the connection fail, so trying again before exiting is a good way for loosing less data.
I will keep trying tonight with normal update interval (1800), it seems to work.
the log:
pi@raspberrypi:~/bt-mqtt-gateway $ sudo ./gateway.py -d
2020-04-30 19:53:28,117 INFO bt-mqtt-gw gateway.py:75:<module> - Starting
2020-04-30 19:53:28,129 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:__init__ - Setting LWT to: lwt_topic
2020-04-30 19:53:35,778 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:15:_setup - Adding 3 lywsd03mmc devices
2020-04-30 19:53:35,788 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:17:_setup - Adding lywsd03mmc device 'chambre' (A4:C1:38:12:E3:AB)
2020-04-30 19:53:35,803 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:17:_setup - Adding lywsd03mmc device 'veranda' (A4:C1:38:1E:29:DF)
2020-04-30 19:53:35,807 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:17:_setup - Adding lywsd03mmc device 'cuisine' (A4:C1:38:47:77:99)
2020-04-30 19:53:35,819 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:107:register_workers - Added lywsd03mmc worker with 60 seconds interval and a 120 seconds timeout
2020-04-30 19:53:35,933 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: mijasensor_gen2/update_interval
2020-04-30 19:53:35,957 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: homeassistant/status
2020-04-30 19:53:36,047 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:173:update_all - Updating all workers
2020-04-30 19:53:36,609 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:connected - trying to connect to A4:C1:38:12:E3:AB
2020-04-30 19:53:49,577 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:84:connected - failed to connect to A4:C1:38:12:E3:AB : 1/4 attempt
2020-04-30 19:53:49,583 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:91:connected - waiting for next try...
2020-04-30 19:53:54,594 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:connected - trying to connect to A4:C1:38:12:E3:AB
2020-04-30 19:53:57,246 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:84:connected - failed to connect to A4:C1:38:12:E3:AB : 2/4 attempt
2020-04-30 19:53:57,268 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:91:connected - waiting for next try...
2020-04-30 19:54:02,282 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:connected - trying to connect to A4:C1:38:12:E3:AB
2020-04-30 19:54:13,419 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:75:connected - connected to A4:C1:38:12:E3:AB
2020-04-30 19:54:13,640 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:78:connected - A4:C1:38:12:E3:AB query done
2020-04-30 19:54:18,549 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:106:readAll - successfully read 18.900000, 55, 2
2020-04-30 19:54:18,566 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:81:connected - A4:C1:38:12:E3:AB is disconnected
2020-04-30 19:54:18,574 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:connected - trying to connect to A4:C1:38:1E:29:DF
2020-04-30 19:54:25,091 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:75:connected - connected to A4:C1:38:1E:29:DF
2020-04-30 19:54:27,040 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:78:connected - A4:C1:38:1E:29:DF query done
2020-04-30 19:54:29,711 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:106:readAll - successfully read 23.100000, 46, 2
2020-04-30 19:54:29,731 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:81:connected - A4:C1:38:1E:29:DF is disconnected
2020-04-30 19:54:29,739 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:connected - trying to connect to A4:C1:38:47:77:99
2020-04-30 19:54:35,417 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:75:connected - connected to A4:C1:38:47:77:99
2020-04-30 19:54:35,642 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:78:connected - A4:C1:38:47:77:99 query done
2020-04-30 19:54:42,548 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:106:readAll - successfully read 23.800000, 48, 3
2020-04-30 19:54:42,566 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:81:connected - A4:C1:38:47:77:99 is disconnected
2020-04-30 19:54:42,576 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/chambre', 'payload': '{"temperature": 18.9, "humidity": 55, "battery": 2.982}'}, {'topic': 'mijasensor_gen2/veranda', 'payload': '{"temperature": 23.1, "humidity": 46, "battery": 2.897}'}, {'topic': 'mijasensor_gen2/cuisine', 'payload': '{"temperature": 23.8, "humidity": 48, "battery": 3.098}'}]
2020-04-30 19:54:42,602 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:connected - trying to connect to A4:C1:38:12:E3:AB
2020-04-30 19:54:48,433 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:84:connected - failed to connect to A4:C1:38:12:E3:AB : 1/4 attempt
2020-04-30 19:54:48,455 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:91:connected - waiting for next try...
2020-04-30 19:54:53,470 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:connected - trying to connect to A4:C1:38:12:E3:AB
2020-04-30 19:55:01,380 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:75:connected - connected to A4:C1:38:12:E3:AB
2020-04-30 19:55:01,590 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:78:connected - A4:C1:38:12:E3:AB query done
2020-04-30 19:55:04,549 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:106:readAll - successfully read 18.900000, 55, 2
2020-04-30 19:55:04,566 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:81:connected - A4:C1:38:12:E3:AB is disconnected
2020-04-30 19:55:04,573 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:connected - trying to connect to A4:C1:38:1E:29:DF
2020-04-30 19:55:09,100 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:75:connected - connected to A4:C1:38:1E:29:DF
2020-04-30 19:55:13,457 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:84:connected - failed to connect to A4:C1:38:1E:29:DF : 1/4 attempt
2020-04-30 19:55:13,473 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:91:connected - waiting for next try...
2020-04-30 19:55:18,490 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:connected - trying to connect to A4:C1:38:1E:29:DF
2020-04-30 19:55:27,559 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:75:connected - connected to A4:C1:38:1E:29:DF
2020-04-30 19:55:27,760 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:78:connected - A4:C1:38:1E:29:DF query done
2020-04-30 19:55:34,549 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:106:readAll - successfully read 23.000000, 46, 2
2020-04-30 19:55:34,566 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:81:connected - A4:C1:38:1E:29:DF is disconnected
2020-04-30 19:55:34,574 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:73:connected - trying to connect to A4:C1:38:47:77:99
2020-04-30 19:55:38,401 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:75:connected - connected to A4:C1:38:47:77:99
2020-04-30 19:55:38,642 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:78:connected - A4:C1:38:47:77:99 query done
2020-04-30 19:55:41,548 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:106:readAll - successfully read 23.800000, 48, 3
2020-04-30 19:55:41,566 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:81:connected - A4:C1:38:47:77:99 is disconnected
2020-04-30 19:55:41,573 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/chambre', 'payload': '{"temperature": 18.9, "humidity": 55, "battery": 2.982}'}, {'topic': 'mijasensor_gen2/veranda', 'payload': '{"temperature": 23.0, "humidity": 46, "battery": 2.897}'}, {'topic': 'mijasensor_gen2/cuisine', 'payload': '{"temperature": 23.8, "humidity": 48, "battery": 3.098}'}]
My code is below (i don't know how to put it on the repo):
in lywsd03mmc.py
add : import time
change this:
def __init__(self, mac, timeout=30,maxattempt=4):
self.mac = mac
self.timeout = timeout
self.maxattempt = maxattempt
self._temperature = None
self._humidity = None
self._battery = None
def connected(self):
from bluepy import btle
attempt = 1
while attempt < (self.maxattempt + 1) :
try:
device = btle.Peripheral()
_LOGGER.debug("trying to connect to %s", self.mac)
device.connect(self.mac)
_LOGGER.debug("connected to %s", self.mac)
device.writeCharacteristic(0x0038, b'\x01\x00', True)
device.writeCharacteristic(0x0046, b'\xf4\x01\x00', True)
_LOGGER.debug("%s query done ", self.mac)
yield device
device.disconnect()
_LOGGER.debug("%s is disconnected ", self.mac)
attempt = (self.maxattempt + 1)
except btle.BTLEDisconnectError as er:
_LOGGER.debug("failed to connect to %s : " + str(attempt) + "/" + str(self.maxattempt) + " attempt", self.mac)
if attempt == self.maxattempt :
yield None
pass
return
else:
attempt = attempt + 1
_LOGGER.debug("waiting for next try...")
time.sleep(5)
pass
maybe you can test and do a better code than mine...but it's working for me.
Maybe it not the best way to active query this thermometers, maybe it should be done passive way, same as here: https://github.com/custom-components/sensor.mitemp_bt ?
Fixed exception handling in workers, please try now, it still wont solve retry, but should fix some errors from above and code is a lot cleaner.
Maybe it not the best way to active query this thermometers, maybe it should be done passive way, same as here: https://github.com/custom-components/sensor.mitemp_bt ?
Yes, maybe it's better because you just listen and decode the data the device is sending. I already try the HA integration and have the pairing key. I can do some test if you need.
As you can see my coding skills are not very good :)
Fixed exception handling in workers, please try now, it still wont solve retry, but should fix some errors from above and code is a lot cleaner.
I try the code from #172 but still have an error when one sensor can't connect:
pi@raspberrypi:~/bt-mqtt-gateway $ sudo ./gateway.py -d
2020-05-01 17:55:59,465 INFO bt-mqtt-gw gateway.py:75:<module> - Starting
2020-05-01 17:55:59,477 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:__init__ - Setting LWT to: lwt_topic
2020-05-01 17:56:06,871 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:16:_setup - Adding 3 lywsd03mmc devices
2020-05-01 17:56:06,876 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'chambre' (A4:C1:38:12:E3:AB)
2020-05-01 17:56:06,882 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'veranda' (A4:C1:38:1E:29:DF)
2020-05-01 17:56:06,887 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'cuisine' (A4:C1:38:47:77:99)
2020-05-01 17:56:06,894 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:107:register_workers - Added lywsd03mmc worker with 60 seconds interval and a 120 seconds timeout
2020-05-01 17:56:06,956 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: mijasensor_gen2/update_interval
2020-05-01 17:56:06,965 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: homeassistant/status
2020-05-01 17:56:07,017 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:173:update_all - Updating all workers
2020-05-01 17:56:07,581 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:51:connected - A4:C1:38:12:E3:AB connected
2020-05-01 17:56:18,828 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:65:readAll - successfully read 19.500000, 59, 2
2020-05-01 17:56:18,848 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:51:connected - A4:C1:38:1E:29:DF connected
2020-05-01 17:56:26,329 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:65:readAll - successfully read 23.700000, 47, 2
2020-05-01 17:56:26,351 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:51:connected - A4:C1:38:47:77:99 connected
2020-05-01 17:56:37,828 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:65:readAll - successfully read 23.700000, 52, 3
2020-05-01 17:56:37,854 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/chambre', 'payload': '{"temperature": 19.5, "humidity": 59, "battery": 2.982}'}, {'topic': 'mijasensor_gen2/veranda', 'payload': '{"temperature": 23.7, "humidity": 47, "battery": 2.932}'}, {'topic': 'mijasensor_gen2/cuisine', 'payload': '{"temperature": 23.7, "humidity": 52, "battery": 3.098}'}]
2020-05-01 17:57:06,964 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:51:connected - A4:C1:38:12:E3:AB connected
2020-05-01 17:57:11,406 ERROR bt-mqtt-gw logger.py:50:log_exception - Fatal error while executing worker command: AttributeError
Traceback (most recent call last):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 26, in status_update
ret = lywsd03mmc.readAll()
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 59, in readAll
with self.connected() as device:
File "/usr/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 53, in connected
device.connect(self.mac)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 445, in connect
self._connect(addr, addrType, iface)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 439, in _connect
raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral A4:C1:38:12:E3:AB, addr type: public
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 56, in execute
for message in self._callback(*self._args):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 27, in status_update
except btle.BluetoothBackendException as e:
AttributeError: module 'bluepy.btle' has no attribute 'BluetoothBackendException'
Traceback (most recent call last):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 26, in status_update
ret = lywsd03mmc.readAll()
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 59, in readAll
with self.connected() as device:
File "/usr/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 53, in connected
device.connect(self.mac)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 445, in connect
self._connect(addr, addrType, iface)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 439, in _connect
raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral A4:C1:38:12:E3:AB, addr type: public
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./gateway.py", line 106, in <module>
raise e
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 56, in execute
for message in self._callback(*self._args):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 27, in status_update
except btle.BluetoothBackendException as e:
AttributeError: module 'bluepy.btle' has no attribute 'BluetoothBackendException'
Right wrong exception added, sorry I'm coding this blindly without bluetooth even on this laptop. Pushed fixes, it should be more stable now.
no, error on timeout.
It's difficult for you to debug without devices. I can give you remote access to my pc if you need. I created also a temporary bt2mqtt telegram group
pi@raspberrypi:~/bt-mqtt-gateway $ sudo ./gateway.py -d
2020-05-01 20:01:03,806 INFO bt-mqtt-gw gateway.py:75:<module> - Starting
2020-05-01 20:01:03,818 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:__init__ - Setting LWT to: lwt_topic
2020-05-01 20:01:11,525 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:16:_setup - Adding 3 lywsd03mmc devices
2020-05-01 20:01:11,530 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'chambre' (A4:C1:38:12:E3:AB)
2020-05-01 20:01:11,536 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'veranda' (A4:C1:38:1E:29:DF)
2020-05-01 20:01:11,542 INFO bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:18:_setup - Adding lywsd03mmc device 'cuisine' (A4:C1:38:47:77:99)
2020-05-01 20:01:11,550 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:107:register_workers - Added lywsd03mmc worker with 180 seconds interval and a 60 seconds timeout
2020-05-01 20:01:11,612 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: mijasensor_gen2/update_interval
2020-05-01 20:01:11,622 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: homeassistant/status
2020-05-01 20:01:11,672 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:173:update_all - Updating all workers
2020-05-01 20:01:12,227 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:49:connected - A4:C1:38:12:E3:AB connected
2020-05-01 20:01:21,388 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:63:readAll - successfully read 19.500000, 59, 2
2020-05-01 20:01:21,409 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:49:connected - A4:C1:38:1E:29:DF connected
2020-05-01 20:01:34,238 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:63:readAll - successfully read 22.100000, 52, 2
2020-05-01 20:01:34,259 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:49:connected - A4:C1:38:47:77:99 connected
2020-05-01 20:01:43,345 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:63:readAll - successfully read 23.700000, 51, 3
2020-05-01 20:01:43,368 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:execute - Execution result of command Lywsd03MmcWorker.status_update: [{'topic': 'mijasensor_gen2/chambre', 'payload': '{"temperature": 19.5, "humidity": 59, "battery": 2.985}'}, {'topic': 'mijasensor_gen2/veranda', 'payload': '{"temperature": 22.1, "humidity": 52, "battery": 2.968}'}, {'topic': 'mijasensor_gen2/cuisine', 'payload': '{"temperature": 23.7, "humidity": 51, "battery": 3.096}'}]
2020-05-01 20:04:11,625 DEBUG bt-mqtt-gw.workers.lywsd03mmc lywsd03mmc.py:49:connected - A4:C1:38:12:E3:AB connected
2020-05-01 20:04:19,945 ERROR bt-mqtt-gw logger.py:50:log_exception - Fatal error while executing worker command: AttributeError
Traceback (most recent call last):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 26, in status_update
ret = lywsd03mmc.readAll()
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 57, in readAll
with self.connected() as device:
File "/usr/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 51, in connected
device.connect(self.mac)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 445, in connect
self._connect(addr, addrType, iface)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 439, in _connect
raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral A4:C1:38:12:E3:AB, addr type: public
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 56, in execute
for message in self._callback(*self._args):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 27, in status_update
except btle.DeviceTimeoutError:
AttributeError: module 'bluepy.btle' has no attribute 'DeviceTimeoutError'
Traceback (most recent call last):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 26, in status_update
ret = lywsd03mmc.readAll()
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 57, in readAll
with self.connected() as device:
File "/usr/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 51, in connected
device.connect(self.mac)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 445, in connect
self._connect(addr, addrType, iface)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 439, in _connect
raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral A4:C1:38:12:E3:AB, addr type: public
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./gateway.py", line 106, in <module>
raise e
File "./gateway.py", line 88, in <module>
mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 56, in execute
for message in self._callback(*self._args):
File "/home/pi/bt-mqtt-gateway/workers/lywsd03mmc.py", line 27, in status_update
except btle.DeviceTimeoutError:
AttributeError: module 'bluepy.btle' has no attribute 'DeviceTimeoutError'
Hi, i'm running with last commit of #172 for 3 days without issue. Sensors are not updated at each update interval (set to 1800), depending if connection fail or not.
sorry have corrently no time for debugging, but after the last changes in this branch, i've issues with command to my eq3 thermostats :/
I made a pull request for passive readout of the lywsd03mmc by using the custom firmware from https://github.com/atc1441/ATC_MiThermometer
Currently reading 5 devices passive, fast, no issues.
I made a pull request for passive readout of the lywsd03mmc by using the custom firmware from https://github.com/atc1441/ATC_MiThermometer
Currently reading 5 devices passive, fast, no issues.
Good news, I will use your code for testing. 👍
Thanks! let me know when you have any issues.
Op 27 dec. 2020, om 15:47 heeft Yvon_Indel notifications@github.com het volgende geschreven:
I made a pull request for passive readout of the lywsd03mmc by using the custom firmware from https://github.com/atc1441/ATC_MiThermometer https://github.com/atc1441/ATC_MiThermometer Currently reading 5 devices passive, fast, no issues.
Good news, I will use your code for testing. 👍
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/zewelor/bt-mqtt-gateway/issues/169#issuecomment-751475931, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEH7KZA6TYN3KOH5O5AIJPTSW5CG5ANCNFSM4MRMZATQ.
[] 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 have 2 lywsd03mmc devices and only the first device is updated. I try to reverse the order of the device with the same result
To Reproduce
Expected behavior all the devices updated
Config
workers: lywsd03mmc: args: devices: chambre: A4:C1:38:12:E3:AB veranda: A4:C1:38:1E:29:DF topic_prefix: mijasensor_gen2 update_interval: 60
Debug gateway logs
Server (please complete the following information):
Additional context Add any other context about the problem here.