JsBergbau / MiTemperature2

Read the values of the Xiaomi Mi Bluetooth Temperature sensor 2 including custom encrypted format.
706 stars 162 forks source link

Docker ATC Mode - ModuleNotFoundError: No module named 'bluetooth_utils' #94

Closed Willem-Renders closed 3 years ago

Willem-Renders commented 3 years ago

I'm trying to get the ATC mode running in a docker container. There are 2 scenario's I tried but don't work.

Scenario 1: Use the base Image "xavierrrr/xrrzero:stretchpython3.7"

After some tweaking I have not managed to get rid of the following error: ImportError: /lib/arm-linux-gnueabihf/libc.so.6: version GLIBC_2.28 not found (required by /usr/local/lib/python3.7/site-packages/bluetooth/_bluetooth.cpython-37m-arm-linux-gnueabihf.so)

Im using the following Dockerfile code:

# Start from a Python3.7 base image I published

FROM xavierrrr/xrrzero:stretchpython3.7 

# http://bugs.python.org/issue19846
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
ENV LANG C.UTF-8

RUN apt-get update
RUN apt-get -y --no-install-recommends install python-pip bluetooth bluez libbluetooth-dev

RUN /usr/local/bin/pip3.7 install pybluez
RUN /usr/local/bin/pip3.7 install bluepy
RUN /usr/local/bin/pip3.7 install requests
RUN /usr/local/bin/pip3.7 install paho-mqtt

COPY LYWSD03MMC.py LYWSD03MMC.py 
COPY mqtt.conf mqtt.conf
COPY sensors.ini sensors.ini

ENTRYPOINT service dbus start

#Change to the following line to match your needs

ENTRYPOINT while true; do /usr/local/bin/python3.7m LYWSD03MMC.py --atc --mqttconfigfile mqtt.conf --devicelistfile sensors.ini; sleep 2; done

# start the created image with sudo docker run --net=host -t your_image_name /bin/bash

So it seems something is wrong with the OS version, and played with the pip versions a bit but couldn't get rid of the error, so I tried another base image.

Scenario 2: Changing the base image

After some playing around I get a running image with the following docker file:

# Start from a Python3.7 base image I published

FROM arm32v7/python:3.7.4

RUN apt-get -y update
RUN apt-get -y install bluetooth
RUN apt-get -y install bluez
RUN apt-get -y install libbluetooth-dev

RUN pip3 install requests
RUN pip3 install bluepy
RUN pip3 install paho-mqtt
RUN pip3 install pybluez
RUN setcap cap_net_raw,cap_net_admin+eip $(eval readlink -f `which python3`)

COPY LYWSD03MMC.py LYWSD03MMC.py 
COPY mqtt.conf mqtt.conf
COPY sensors.ini sensors.ini

ENTRYPOINT service dbus start

#Change to the following line to match your needs

ENTRYPOINT while true; do python3 LYWSD03MMC.py --atc --mqttconfigfile mqtt.conf --devicelistfile sensors.ini; sleep 2; done

# start the created image with sudo docker run --net=host -t your_image_name /bin/bash

However same story, I get stuck on the following error: Traceback (most recent call last): File "LYWSD03MMC.py", line 528, in <module> from bluetooth_utils import (toggle_device, ModuleNotFoundError: No module named 'bluetooth_utils'

Also tried the same on the RPI itself but stuck on the same error

rocket59 commented 3 years ago

you also need to have the file bluetooth_utils.py in the same folder as LYWSD03MMC.py