Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Multithreading sensors instead of multithreading workers only #65

Closed
hobbypunk90 opened this issue Mar 29, 2019 · 3 comments · Fixed by #96
Closed

Multithreading sensors instead of multithreading workers only #65

hobbypunk90 opened this issue Mar 29, 2019 · 3 comments · Fixed by #96

Comments

@hobbypunk90
Copy link
Contributor

Is your feature request related to a problem? Please describe.
At this moment, bt-mqtt-gateway collects all data of any sensor and sends after collecting the data via mqtt and on a timeout error on one sensor the complete worker stops and no data are sended.

Describe the solution you'd like
With one worker per sensor instead of one worker for all sensors of a type, errors for single sensors don't mess up with other sensors.

Log
MiThermometer

2019-03-29 19:13:04,074 INFO bt-mqtt-gw.workers.mithermometer mithermometer.py:25:status_update - Updating 4 mithermometer devices
2019-03-29 19:13:04,078 DEBUG bt-mqtt-gw.workers.mithermometer mithermometer.py:28:status_update - Updating mithermometer device 'bath' (4C:65:A8:D9:B7:4D)
2019-03-29 19:13:39,075 ERROR bt-mqtt-gw logger.py:48:log_exception - Execution of command MithermometerWorker.status_update timed out after 35 seconds
Traceback (most recent call last):
  File "gateway.py", line 49, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/alarm/bt-mqtt-gateway/workers_manager.py", line 34, in execute
    messages = self._callback(*self._args)
  File "/home/alarm/bt-mqtt-gateway/workers/mithermometer.py", line 30, in status_update
    ret += self.update_device_state(name, poller)
  File "/home/alarm/bt-mqtt-gateway/workers/mithermometer.py", line 39, in update_device_state
    ret.append(MqttMessage(topic=self.format_topic(name, attr), payload=poller.parameter_value(attr)))
  File "/usr/lib/python3.7/site-packages/mithermometer/mithermometer_poller.py", line 136, in parameter_value
    self.fill_cache()
  File "/usr/lib/python3.7/site-packages/mithermometer/mithermometer_poller.py", line 60, in fill_cache
    self.firmware_version()
  File "/usr/lib/python3.7/site-packages/mithermometer/mithermometer_poller.py", line 109, in firmware_version
    with self._bt_interface.connect(self._mac) as connection:
  File "/usr/lib/python3.7/site-packages/btlewrap/base.py", line 42, in __enter__
    self._lock.acquire()
  File "/usr/lib/python3.7/site-packages/interruptingcow/__init__.py", line 74, in handler
    raise exception
TimeoutError: Execution of command MithermometerWorker.status_update timed out after 35 seconds
2019-03-29 19:13:55,929 INFO bt-mqtt-gw.workers.thermostat thermostat.py:74:status_update - Updating 2 thermostat devices

MiFlora

2019-03-29 19:24:26,703 INFO bt-mqtt-gw.workers.miflora miflora.py:25:status_update - Updating 10 miflora devices
2019-03-29 19:24:55,002 DEBUG bt-mqtt-gw.workers.miflora miflora.py:28:status_update - Updating miflora device 'diddy' (C4:7C:8D:66:4D:35)
2019-03-29 19:25:01,709 ERROR bt-mqtt-gw logger.py:48:log_exception - Execution of command MifloraWorker.status_update timed out after 35 seconds
Traceback (most recent call last):
  File "gateway.py", line 49, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/alarm/bt-mqtt-gateway/workers_manager.py", line 34, in execute
    messages = self._callback(*self._args)
  File "/home/alarm/bt-mqtt-gateway/workers/miflora.py", line 30, in status_update
    ret += self.update_device_state(name, poller)
  File "/home/alarm/bt-mqtt-gateway/workers/miflora.py", line 39, in update_device_state
    ret.append(MqttMessage(topic=self.format_topic(name, attr), payload=poller.parameter_value(attr)))
  File "/usr/lib/python3.7/site-packages/miflora/miflora_poller.py", line 132, in parameter_value
    self.fill_cache()
  File "/usr/lib/python3.7/site-packages/miflora/miflora_poller.py", line 61, in fill_cache
    firmware_version = self.firmware_version()
  File "/usr/lib/python3.7/site-packages/miflora/miflora_poller.py", line 103, in firmware_version
    with self._bt_interface.connect(self._mac) as connection:
  File "/usr/lib/python3.7/site-packages/btlewrap/base.py", line 44, in __enter__
    self._backend.connect(self._mac)
  File "/usr/lib/python3.7/site-packages/btlewrap/bluepy.py", line 26, in _func_wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python3.7/site-packages/btlewrap/bluepy.py", line 55, in connect
    self._peripheral = Peripheral(mac, iface=iface)
  File "/usr/lib/python3.7/site-packages/bluepy/btle.py", line 361, in __init__
    self._connect(deviceAddr, addrType, iface)
  File "/usr/lib/python3.7/site-packages/bluepy/btle.py", line 406, in _connect
    rsp = self._getResp('stat')
  File "/usr/lib/python3.7/site-packages/bluepy/btle.py", line 377, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/usr/lib/python3.7/site-packages/bluepy/btle.py", line 319, in _waitResp
    rv = self._helper.stdout.readline()
  File "/usr/lib/python3.7/site-packages/interruptingcow/__init__.py", line 74, in handler
    raise exception
TimeoutError: Execution of command MifloraWorker.status_update timed out after 35 seconds
2019-03-29 19:25:01,762 INFO bt-mqtt-gw.workers.mithermometer mithermometer.py:25:status_update - Updating 4 mithermometer devices

@Maczuga
Copy link

Maczuga commented Jun 1, 2019

Can confirm. Got 5 sensors, from time to time 1 fails due to timeout (device is on the edge of BT range), this prevents the other 4 from sending updates.

@mateuszdrab
Copy link

mateuszdrab commented Jul 13, 2019

Yup, same issue here, incredibly annoying. I also seem to experience an issue when after some time of running the daemon, all the sensors stop updating. Will try crontab to bounce the service at regular intervals.

@zewelor
Copy link
Owner

zewelor commented Aug 29, 2019

This should be fixed in #96. Please test it

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants