bt-mqtt-gateway
bt-mqtt-gateway copied to clipboard
EnvironmentError: [Errno 2] (other issue?)
[] 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 don't know what causes the bug but I keep getting an error and the solution described with the existing ERRNO 2 doesn't work for me because those condition is already met..
To Reproduce Steps to reproduce the behavior:
- Go to '~/bt-mqtt-gateway $...'
- Run: source .venv/bin/activate
- Run: sudo ./gateway.py -d
- See error
Expected behavior I expected to run the program and get messages from my 2 Xiaomi MyFlora
Config Used config
Debug gateway logs
run gateway.py with -d switch and paste formatted output log
pi@raspberrypi:~/bt-mqtt-gateway $ source .venv/bin/activate
(.venv) pi@raspberrypi:~/bt-mqtt-gateway $ sudo ./gateway.py -d
2020-12-19 17:07:39,862 INFO bt-mqtt-gw gateway.py:75:<module> - Starting
2020-12-19 17:07:39,864 DEBUG bt-mqtt-gw.mqtt mqtt.py:30:__init__ - Setting LWT to: lwt_topic
Could not install packages due to an EnvironmentError: [Errno 2] File or Folder doesn't exist: '/tmp/pip-req-tracker-egvio8vf/842a9cdb9c2fec1838b90e5a1c92a091b46562f90b8268bda8196a1d'
2020-12-19 17:07:43,135 INFO bt-mqtt-gw.workers.miflora miflora.py:31:_setup - Adding 2 miflora devices
2020-12-19 17:07:43,136 DEBUG bt-mqtt-gw.workers.miflora miflora.py:33:_setup - Adding miflora device 'palm' (C4:7C:8D:6A:71:42)
2020-12-19 17:07:43,138 ERROR btlewrap.bluepy bluepy.py:102:check_backend - bluepy not found: No module named 'bluepy'
2020-12-19 17:07:43,138 DEBUG bt-mqtt-gw.workers.miflora miflora.py:33:_setup - Adding miflora device 'dracena' (C4:7C:8D:6A:BD:D1)
2020-12-19 17:07:43,140 ERROR btlewrap.bluepy bluepy.py:102:check_backend - bluepy not found: No module named 'bluepy'
2020-12-19 17:07:43,141 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:97:register_workers - Added miflora config with a 2 seconds timeout
2020-12-19 17:07:43,141 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:107:register_workers - Added miflora worker with 300 seconds interval and a 35 seconds timeout
2020-12-19 17:07:43,149 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: miflora/update_interval
2020-12-19 17:07:43,150 DEBUG bt-mqtt-gw.mqtt mqtt.py:117:callbacks_subscription - Subscribing to: domoticz/in
2020-12-19 17:07:43,153 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:68:execute - Execution result of command MifloraWorker.config: [{'topic': 'sensor/C4-7C-8D-6A-71-42/miflora_palm_temperature/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6A-71-42/miflora_palm_temperature", "state_topic": "miflora/palm/temperature", "name": "miflora_palm_temperature", "device": {"identifiers": ["C4:7C:8D:6A:71:42", "bt-mqtt-gateway/C4-7C-8D-6A-71-42/miflora_palm"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_palm"}, "device_class": "temperature", "unit_of_measurement": "\\u00b0C"}'}, {'topic': 'sensor/C4-7C-8D-6A-71-42/miflora_palm_moisture/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6A-71-42/miflora_palm_moisture", "state_topic": "miflora/palm/moisture", "name": "miflora_palm_moisture", "device": {"identifiers": ["C4:7C:8D:6A:71:42", "bt-mqtt-gateway/C4-7C-8D-6A-71-42/miflora_palm"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_palm"}, "icon": "mdi:water", "unit_of_measurement": "%"}'}, {'topic': 'sensor/C4-7C-8D-6A-71-42/miflora_palm_light/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6A-71-42/miflora_palm_illuminance", "state_topic": "miflora/palm/light", "name": "miflora_palm_light", "device": {"identifiers": ["C4:7C:8D:6A:71:42", "bt-mqtt-gateway/C4-7C-8D-6A-71-42/miflora_palm"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_palm"}, "device_class": "illuminance", "unit_of_measurement": "lux"}'}, {'topic': 'sensor/C4-7C-8D-6A-71-42/miflora_palm_conductivity/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6A-71-42/miflora_palm_conductivity", "state_topic": "miflora/palm/conductivity", "name": "miflora_palm_conductivity", "device": {"identifiers": ["C4:7C:8D:6A:71:42", "bt-mqtt-gateway/C4-7C-8D-6A-71-42/miflora_palm"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_palm"}, "icon": "mdi:leaf", "unit_of_measurement": "\\u00b5S/cm"}'}, {'topic': 'sensor/C4-7C-8D-6A-71-42/miflora_palm_battery/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6A-71-42/miflora_palm_battery", "state_topic": "miflora/palm/battery", "name": "miflora_palm_battery", "device": {"identifiers": ["C4:7C:8D:6A:71:42", "bt-mqtt-gateway/C4-7C-8D-6A-71-42/miflora_palm"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_palm"}, "device_class": "battery", "unit_of_measurement": "%"}'}, {'topic': 'binary_sensor/C4-7C-8D-6A-71-42/miflora_palm_low_battery/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6A-71-42/miflora_palm_low_battery", "state_topic": "miflora/palm/low_battery", "name": "miflora_palm_low_battery", "device": {"identifiers": ["C4:7C:8D:6A:71:42", "bt-mqtt-gateway/C4-7C-8D-6A-71-42/miflora_palm"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_palm"}, "device_class": "battery"}'}, {'topic': 'sensor/C4-7C-8D-6A-BD-D1/miflora_dracena_temperature/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6A-BD-D1/miflora_dracena_temperature", "state_topic": "miflora/dracena/temperature", "name": "miflora_dracena_temperature", "device": {"identifiers": ["C4:7C:8D:6A:BD:D1", "bt-mqtt-gateway/C4-7C-8D-6A-BD-D1/miflora_dracena"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_dracena"}, "device_class": "temperature", "unit_of_measurement": "\\u00b0C"}'}, {'topic': 'sensor/C4-7C-8D-6A-BD-D1/miflora_dracena_moisture/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6A-BD-D1/miflora_dracena_moisture", "state_topic": "miflora/dracena/moisture", "name": "miflora_dracena_moisture", "device": {"identifiers": ["C4:7C:8D:6A:BD:D1", "bt-mqtt-gateway/C4-7C-8D-6A-BD-D1/miflora_dracena"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_dracena"}, "icon": "mdi:water", "unit_of_measurement": "%"}'}, {'topic': 'sensor/C4-7C-8D-6A-BD-D1/miflora_dracena_light/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6A-BD-D1/miflora_dracena_illuminance", "state_topic": "miflora/dracena/light", "name": "miflora_dracena_light", "device": {"identifiers": ["C4:7C:8D:6A:BD:D1", "bt-mqtt-gateway/C4-7C-8D-6A-BD-D1/miflora_dracena"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_dracena"}, "device_class": "illuminance", "unit_of_measurement": "lux"}'}, {'topic': 'sensor/C4-7C-8D-6A-BD-D1/miflora_dracena_conductivity/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6A-BD-D1/miflora_dracena_conductivity", "state_topic": "miflora/dracena/conductivity", "name": "miflora_dracena_conductivity", "device": {"identifiers": ["C4:7C:8D:6A:BD:D1", "bt-mqtt-gateway/C4-7C-8D-6A-BD-D1/miflora_dracena"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_dracena"}, "icon": "mdi:leaf", "unit_of_measurement": "\\u00b5S/cm"}'}, {'topic': 'sensor/C4-7C-8D-6A-BD-D1/miflora_dracena_battery/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6A-BD-D1/miflora_dracena_battery", "state_topic": "miflora/dracena/battery", "name": "miflora_dracena_battery", "device": {"identifiers": ["C4:7C:8D:6A:BD:D1", "bt-mqtt-gateway/C4-7C-8D-6A-BD-D1/miflora_dracena"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_dracena"}, "device_class": "battery", "unit_of_measurement": "%"}'}, {'topic': 'binary_sensor/C4-7C-8D-6A-BD-D1/miflora_dracena_low_battery/config', 'payload': '{"unique_id": "bt-mqtt-gateway/C4-7C-8D-6A-BD-D1/miflora_dracena_low_battery", "state_topic": "miflora/dracena/low_battery", "name": "miflora_dracena_low_battery", "device": {"identifiers": ["C4:7C:8D:6A:BD:D1", "bt-mqtt-gateway/C4-7C-8D-6A-BD-D1/miflora_dracena"], "manufacturer": "Xiaomi", "model": "MiFlora", "name": "miflora_dracena"}, "device_class": "battery"}'}]
2020-12-19 17:07:43,166 DEBUG bt-mqtt-gw.workers_manager workers_manager.py:173:update_all - Updating all workers
2020-12-19 17:07:43,167 INFO bt-mqtt-gw.workers.miflora miflora.py:106:status_update - Updating 2 miflora devices
2020-12-19 17:07:43,167 DEBUG bt-mqtt-gw.workers.miflora miflora.py:109:status_update - Updating miflora device 'palm' (C4:7C:8D:6A:71:42)
2020-12-19 17:07:43,170 ERROR bt-mqtt-gw logger.py:50:log_exception - Fatal error while executing worker command: ModuleNotFoundError
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/miflora.py", line 114, in status_update
yield self.update_device_state(name, data["poller"])
File "/home/pi/bt-mqtt-gateway/workers/miflora.py", line 142, in update_device_state
payload=poller.parameter_value(attr),
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 156, in parameter_value
self.fill_cache()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 85, in fill_cache
firmware_version = self.firmware_version()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 127, in firmware_version
with self._bt_interface.connect(self._mac) as connection:
File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 47, in __enter__
self._backend.connect(self._mac)
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 49, in connect
from bluepy.btle import Peripheral
ModuleNotFoundError: No module named 'bluepy'
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/miflora.py", line 114, in status_update
yield self.update_device_state(name, data["poller"])
File "/home/pi/bt-mqtt-gateway/workers/miflora.py", line 142, in update_device_state
payload=poller.parameter_value(attr),
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 156, in parameter_value
self.fill_cache()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 85, in fill_cache
firmware_version = self.firmware_version()
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 127, in firmware_version
with self._bt_interface.connect(self._mac) as connection:
File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 47, in __enter__
self._backend.connect(self._mac)
File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 49, in connect
from bluepy.btle import Peripheral
ModuleNotFoundError: No module named 'bluepy'
Server (please complete the following information):
- OS: Linux
- Distro: Raspbian]
- Version December 2020
Additional context Add any other context about the problem here.
try to run:
pip install `./gateway.py -r configured`
Unfortunately that didn't work for me with this error:
pi@raspberrypi:~/bt-mqtt-gateway $ pip install `./gateway.py -r configured`
Traceback (most recent call last):
File "./gateway.py", line 11, in <module>
import logger
File "/home/pi/bt-mqtt-gateway/logger.py", line 3, in <module>
import yaml
ModuleNotFoundError: No module named 'yaml'
ERROR: You must give at least one requirement to install (see "pip help install")
By the way: I did upgrade pip after a warning to:
WARNING: You are using pip version 20.3.1; however, version 20.3.3 is available.
You should consider upgrading via the '/home/pi/bt-mqtt-gateway/.venv/bin/python -m pip install --upgrade pip' command.
Did you run sudo pip3 install -r requirements.txt before ?
Yes I did. No errors when a ran that during set-up.
Try "sudo pip install ./gateway.py -r configured"
That didn't help either with the next Error:
$ sudo pip install ./gateway.py -r configured
Invalid requirement: './gateway.py'
It looks like a path. File './gateway.py' does not exist.
I think I solved it. Bluepy was in the wrong folder namely Python2.7. I renamed that Folder and reinstalled Bluepy by using: sudo pip3 install bluepy.
Now I get results from MQTT
The only now is that I get an error when running:
sudo systemctl status bt-mqtt-gateway
With an ERROR like this:
● bt-mqtt-gateway.service - Bluetooth MQTT gateway
Loaded: loaded (/etc/systemd/system/bt-mqtt-gateway.service; enabled; vendor
Active: failed (Result: exit-code) since Mon 2020-12-21 14:56:54 CET; 2min 6s
Docs: https://github.com/zewelor/bt-mqtt-gateway
Process: 539 ExecStart=/home/pi/bt-mqtt-gateway/service.sh (code=exited, statu
Main PID: 539 (code=exited, status=1/FAILURE)
dec 21 14:56:54 raspberrypi systemd[1]: bt-mqtt-gateway.service: Service Restart
dec 21 14:56:54 raspberrypi systemd[1]: bt-mqtt-gateway.service: Scheduled resta
dec 21 14:56:54 raspberrypi systemd[1]: Stopped Bluetooth MQTT gateway.
dec 21 14:56:54 raspberrypi systemd[1]: bt-mqtt-gateway.service: Start request r
dec 21 14:56:54 raspberrypi systemd[1]: bt-mqtt-gateway.service: Failed with res
dec 21 14:56:54 raspberrypi systemd[1]: Failed to start Bluetooth MQTT gateway.
Perhaps you have a clue, but I'm convinced I will solve that problem as well. For now it runs, but I have to restart it after a reboot myself. I can live with that for the moment.
I know this is a kind of hacky way (because you leave dependencies in a two places)
But it worked for me adding this line to service.sh:
python3 -m pip install -r requirements.txt
then start the service, check if it works and remove the line afterwards