devbis / ble2mqtt

Bluetooth to MQTT bridge, add your bluetooth-capable (including controllable) devices to your smart home
MIT License
125 stars 26 forks source link

Docker compose error #49

Closed roblomq closed 1 year ago

roblomq commented 1 year ago

I'm trying to install ble2mqtt on docker but I get the error messages below. Googled already, most answers point in the direction of disk space but that seems (not 100% sure because it also can be the virtual volume in docker but can't find how to check that) not the problem.

pi@P1-Logger:/home/ble2mqtt $ docker build -t ble2mqtt:dev .
[+] Building 7.9s (7/14)
 => [internal] load .dockerignore                                                                                                                                                                    0.1s
 => => transferring context: 2B                                                                                                                                                                      0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                 0.1s
 => => transferring dockerfile: 875B                                                                                                                                                                 0.0s
 => [internal] load metadata for docker.io/library/python:3.9-slim                                                                                                                                   1.8s
 => [internal] load build context                                                                                                                                                                    0.2s
 => => transferring context: 2.10kB                                                                                                                                                                  0.0s
 => CACHED [app 1/5] FROM docker.io/library/python:3.9-slim@sha256:5192f07402cbe8b0267eef13085b321d50ab8aaac79d2f0657f96810c3f4555c                                                                  0.0s
 => ERROR [builder 2/6] RUN apt-get update &&     apt-get install gcc git -y &&     apt-get clean                                                                                                    5.8s
 => ERROR [app 2/5] RUN apt-get update &&     apt-get install bluez -y &&     apt-get clean                                                                                                          5.8s
------
 > [builder 2/6] RUN apt-get update &&     apt-get install gcc git -y &&     apt-get clean:
#6 3.436 Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
#6 3.626 Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
#6 3.629 Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
#6 4.277 Err:1 http://deb.debian.org/debian bullseye InRelease
#6 4.277   At least one invalid signature was encountered.
#6 4.818 Err:2 http://deb.debian.org/debian-security bullseye-security InRelease
#6 4.818   At least one invalid signature was encountered.
#6 5.373 Err:3 http://deb.debian.org/debian bullseye-updates InRelease
#6 5.373   At least one invalid signature was encountered.
#6 5.404 Reading package lists...
#6 5.550 W: GPG error: http://deb.debian.org/debian bullseye InRelease: At least one invalid signature was encountered.
#6 5.550 E: The repository 'http://deb.debian.org/debian bullseye InRelease' is not signed.
#6 5.550 W: GPG error: http://deb.debian.org/debian-security bullseye-security InRelease: At least one invalid signature was encountered.
#6 5.550 E: The repository 'http://deb.debian.org/debian-security bullseye-security InRelease' is not signed.
#6 5.550 W: GPG error: http://deb.debian.org/debian bullseye-updates InRelease: At least one invalid signature was encountered.
#6 5.550 E: The repository 'http://deb.debian.org/debian bullseye-updates InRelease' is not signed.
------
------
 > [app 2/5] RUN apt-get update &&     apt-get install bluez -y &&     apt-get clean:
#5 3.473 Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
#5 3.599 Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
#5 3.599 Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
#5 4.218 Err:1 http://deb.debian.org/debian bullseye InRelease
#5 4.218   At least one invalid signature was encountered.
#5 4.779 Err:2 http://deb.debian.org/debian-security bullseye-security InRelease
#5 4.779   At least one invalid signature was encountered.
#5 5.327 Err:3 http://deb.debian.org/debian bullseye-updates InRelease
#5 5.327   At least one invalid signature was encountered.
#5 5.356 Reading package lists...
#5 5.469 W: GPG error: http://deb.debian.org/debian bullseye InRelease: At least one invalid signature was encountered.
#5 5.469 E: The repository 'http://deb.debian.org/debian bullseye InRelease' is not signed.
#5 5.469 W: GPG error: http://deb.debian.org/debian-security bullseye-security InRelease: At least one invalid signature was encountered.
#5 5.469 E: The repository 'http://deb.debian.org/debian-security bullseye-security InRelease' is not signed.
#5 5.469 W: GPG error: http://deb.debian.org/debian bullseye-updates InRelease: At least one invalid signature was encountered.
#5 5.469 E: The repository 'http://deb.debian.org/debian bullseye-updates InRelease' is not signed.
------
process "/bin/sh -c apt-get update &&     apt-get install bluez -y &&     apt-get clean" did not complete successfully: exit code: 100
devbis commented 1 year ago

Check your date and time in docker, seems it is not correct. BTW, I have never run it in docker, the Dockerfile is a contribution from the community.

roblomq commented 1 year ago

Do you also know how I can check and set the time?

devbis commented 1 year ago

Check your docker configuration, i don't have idea. These errors are not related to ble2mqtt.

roblomq commented 1 year ago

I've managed to get it running.

docker compose up
[+] Running 1/1
 ✔ Container ble2mqtt-ble2mqtt-1  Recreated                                                                                                                                                                                         0.5s
Attaching to ble2mqtt-ble2mqtt-1
ble2mqtt-ble2mqtt-1  | Starting system message bus: dbus.
ble2mqtt-ble2mqtt-1  | 2023-04-09 20:54:38 INFO: Starting BLE2MQTT version 0.1.5
ble2mqtt-ble2mqtt-1  | 2023-04-09 20:54:38 INFO: Connected to localhost

Then paired the AM43 device and added the mac to the config file. But what's the next step? I see in my MQTT Explorer there is a topic called ble2mqtt which is online. But for me it's not clear what to do next?

devbis commented 1 year ago

If the device is connected, it should create corresponding topics in homeassistant/* and in ble2mqtt prefixes

Check logs for incorrect config or connection issues.

roblomq commented 1 year ago

I see no homeassistant/* topics in my MQTT explorer. Where can I find the logs?

devbis commented 1 year ago

In docker output. Try to set ENV variable BLE2MQTT_CONFIG=/path/to/file/in/docker explicitly. The default value is /etc/ble2mqtt.json

roblomq commented 1 year ago

I appreciate your help. As I'm no programmer (I'm a mechanical engineer) I'm doing this by using the trial and error method but when there are no errors but It's still not working I got a bit stuck. I am always struggling with paths and file locations especially with docker I sometimes got a bit lost. But I think docker has the future so that's why I'm trying to learn it. Also with ble2mqtt I spend a lot of time in finding the right file location for the config file ble2mqtt.json. I got a lot of errors because somehow there was a folder created called ble2mqtt.json instead of that it read the file. My docker-compose.yml file that gives no errors anymore is shown below.

version: '3.7'
services:
  ble2mqtt:
    image: ble2mqtt:dev
    build: ./ble2mqtt
    hostname: ble2mqtt
    restart: always
    environment:
      - BLE2MQTT_CONFIG=./ble2mqtt.json ble2mqtt
      - TZ=Europe/Amsterdam
    volumes:
      - /home/ble2mqtt/ble2mqtt.json:/etc/ble2mqtt.json:ro
    network_mode: host
    cap_add:
      - NET_ADMIN

But I think the BLE2MQTT_CONFIG is pointing to a file and not a folder, is that correct? Does the BLE2MQTT_CONFIG needs to be a file or a folder? And if it needs to be a folder, does the json config file needs to be IN that folder?

roblomq commented 1 year ago

This is the output of the bluetoothctl info.

info 02:BE:3A:9E:6E:0E
Device 02:BE:3A:9E:6E:0E (public)
        Name: Voorraam
        Alias: Voorraam
        Paired: yes
        Trusted: no
        Blocked: no
        Connected: yes
        LegacyPairing: no
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        UUID: Google Inc.               (0000fe50-0000-1000-8000-00805f9b34fb)
        ManufacturerData Key: 0x0000
[CHG] Device 02:BE:3A:9E:6E:0E ServicesResolved: no
[CHG] Device 02:BE:3A:9E:6E:0E Paired: no
[CHG] Device 02:BE:3A:9E:6E:0E Connected: no
devbis commented 1 year ago

You're mounting file from /home/ble2mqtt/ble2mqtt.json -> /etc/ble2mqtt.json

Check /home/ble2mqtt/ble2mqtt.json for config file or change the location

BLE2MQTT_CONFIG should be a path to a file, not a folder.

roblomq commented 1 year ago

my config file is (removed the MAC)

{
    "mqtt_host": "192.168.178.7",
    "mqtt_port": 1883,
    "mqtt_user": "",
    "mqtt_password": "",
    "log_level": "INFO",
    "devices": [
        {
            "address": "xx:xx:xx:xx:xx:xx",
            "type": "am43"
            "key": "0000"
        }
    ]
}

Through the help of chatgpt I think I found the log using portainer.

Starting system message bus: dbus.
2023-04-09 20:54:38 INFO: Starting BLE2MQTT version 0.1.5
2023-04-09 20:54:38 INFO: Connected to localhost
2023-04-10 00:21:19 INFO: Starting BLE2MQTT version 0.1.5
2023-04-10 00:21:19 INFO: Connected to localhost
2023-04-10 00:29:13 INFO: Starting BLE2MQTT version 0.1.5
2023-04-10 00:29:13 INFO: Connected to localhost

Seems there are no errors...

devbis commented 1 year ago

It seems it doesn't use your config file, because it contains syntax errors and b2m will fail on parsing it

roblomq commented 1 year ago

Came a little bit further I think. The config file was not loaded indeed, also recognizable because the log shows "Connected to localhost" while in my config file I used an IP address. When I remove the - BLE2MQTT_CONFIG=./ble2mqtt.json ble2mqtt from the docker compose file then it seems to use the correct config file. When I then run the docker the log shows the information below.

docker compose up
[+] Running 1/0
 ✔ Container ble2mqtt  Created                                                                                                                                                                       0.0s
Attaching to ble2mqtt
ble2mqtt  | 2023-04-10 19:06:55 INFO: Starting BLE2MQTT version 0.1.5
ble2mqtt  | 2023-04-10 19:06:55 INFO: Connected to 192.168.178.7
ble2mqtt  | 2023-04-10 19:06:55 ERROR: [Blind_AM43_02be3a9e6e0e] connection problem, attempts=1
ble2mqtt  | Traceback (most recent call last):
ble2mqtt  |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 573, in manage_device
ble2mqtt  |     await device.connect(self._hci_adapter)
ble2mqtt  |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/devices/base.py", line 390, in connect
ble2mqtt  |     self.client = await self.get_client(
ble2mqtt  |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/devices/base.py", line 383, in get_client
ble2mqtt  |     client.manager = await get_global_bluez_manager()
ble2mqtt  |   File "/root/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/manager.py", line 910, in get_global_bluez_manager
ble2mqtt  |     await instance.async_init()
ble2mqtt  |   File "/root/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/manager.py", line 190, in async_init
ble2mqtt  |     bus = MessageBus(bus_type=BusType.SYSTEM, auth=get_dbus_authenticator())
ble2mqtt  |   File "/root/.local/lib/python3.9/site-packages/dbus_fast/aio/message_bus.py", line 172, in __init__
ble2mqtt  |     super().__init__(bus_address, bus_type, ProxyObject, negotiate_unix_fd)
ble2mqtt  |   File "src/dbus_fast/message_bus.py", line 186, in dbus_fast.message_bus.BaseMessageBus.__init__
ble2mqtt  |   File "src/dbus_fast/message_bus.py", line 740, in dbus_fast.message_bus.BaseMessageBus._setup_socket
ble2mqtt  |   File "src/dbus_fast/message_bus.py", line 713, in dbus_fast.message_bus.BaseMessageBus._setup_socket
ble2mqtt  | ConnectionRefusedError: [Errno 111] Connection refused
ble2mqtt  | 2023-04-10 19:07:05 ERROR: Blind_AM43_02be3a9e6e0e not disconnected in 10 secs
ble2mqtt  | Traceback (most recent call last):
ble2mqtt  |   File "/usr/local/lib/python3.9/asyncio/locks.py", line 226, in wait
ble2mqtt  |     await fut
ble2mqtt  | asyncio.exceptions.CancelledError
ble2mqtt  |
ble2mqtt  | During handling of the above exception, another exception occurred:
ble2mqtt  |
ble2mqtt  | Traceback (most recent call last):
ble2mqtt  |   File "/usr/local/lib/python3.9/asyncio/tasks.py", line 490, in wait_for
ble2mqtt  |     return fut.result()
ble2mqtt  | asyncio.exceptions.CancelledError
ble2mqtt  |
ble2mqtt  | The above exception was the direct cause of the following exception:
ble2mqtt  |
ble2mqtt  | Traceback (most recent call last):
ble2mqtt  |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 710, in manage_device
ble2mqtt  |     await aio.wait_for(
ble2mqtt  |   File "/usr/local/lib/python3.9/asyncio/tasks.py", line 492, in wait_for
ble2mqtt  |     raise exceptions.TimeoutError() from exc
ble2mqtt  | asyncio.exceptions.TimeoutError
devbis commented 1 year ago

Your mosquito server is not accessible, check ports, interfaces it listens on, firewalls, etc.

roblomq commented 1 year ago

The connection with mosquitto is working. THis is confirmed by both the above log entry INFO: Connected to 192.168.178.7 but also with my MQTT exploder which confirms the ble2mqqt is online.

2023-04-15_18h04_43

I think the connection with the AM43 is not working for some reason but all the info in the log doesn't ring any bells to me.

roblomq commented 1 year ago

Is it possible that the bluetooth USB dongle is not reachable through docker ?

roblomq commented 1 year ago

OK I give up. I can't get this to work using docker. If someone does, please let me know..

devbis commented 1 year ago

Is it possible that the bluetooth USB dongle is not reachable through docker ?

That might be a clue. It looks like you have a problems with connecting to Dbus. You can try to run dbus on the host machine and mount /var/run/dbus inside the container. Or, configure dbus in the container to accept anonymous connections

roblomq commented 1 year ago

Got indeed some dbus errors but even bluetoothctl does not work inside the container. Do you know how I can configure the dbus inside the container because I've googled quite intense but only found people with the same problem, mostly HA related, but no solutions that works. I even tried updating bluez to the latest version (seems that you have to do it manually because otherwise there is an older version installed).

devbis commented 1 year ago

As I said above, I didn't try to use it in docker, Dockerfile and supplementary stuff was uploaded by users. Do I have no idea about configuring dbus, unfortunately. And I don't have hardware setup right now to try it out.

roblomq commented 1 year ago

Got a little bit further, seems indeed that the dbus and therefore the bluetooth isn't running in the container. When I manually start them (see below) the ble2mqtt is running.

service dbus start
service bluetooth start
bluetoothctl

Through the mqtt autodiscovery 2 devices are automatically created in Domoticz. These are a lux device and a shades device, they also work perfectly. Only the "linkquality" in the mqtt command stays on "null", is that correct?

Now I have to find out how to start the dbus and bluetooth inside the docker to get it also running after a reboot.

devbis commented 1 year ago

Did you try to use docker_entrypoint.sh that is added to this repo?