fix up some mess
This commit is contained in:
parent
4e76c7db1a
commit
285a2503d7
BIN
.media/demo.gif
Normal file
BIN
.media/demo.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
@ -39,12 +39,12 @@ WORKDIR /src
|
|||||||
COPY ./python/src/ .
|
COPY ./python/src/ .
|
||||||
COPY ./python/docker_entrypoint.sh /
|
COPY ./python/docker_entrypoint.sh /
|
||||||
RUN mkdir data
|
RUN mkdir data
|
||||||
RUN touch DOCKER
|
|
||||||
VOLUME /src/data
|
VOLUME /src/data
|
||||||
|
|
||||||
RUN apk add --no-cache sudo bluez tzdata
|
RUN apk add --no-cache sudo bluez tzdata
|
||||||
ENV TZ=Europe/Berlin
|
ENV TZ=Europe/Berlin
|
||||||
ENV DOCKER=TRUE
|
ENV DOCKER=true
|
||||||
|
ENV API=false
|
||||||
|
|
||||||
# Copy pips from the pip build stage
|
# Copy pips from the pip build stage
|
||||||
COPY --from=pip_build_stage /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
|
COPY --from=pip_build_stage /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
|
||||||
|
|||||||
15
README.md
15
README.md
@ -1,5 +1,6 @@
|
|||||||
<!-- TOC -->
|
<!-- TOC -->
|
||||||
* [ATC_MiThermometer_Gateway](#atc_mithermometer_gateway)
|
* [ATC_MiThermometer_Gateway](#atc_mithermometer_gateway)
|
||||||
|
* [Roadmap](#roadmap)
|
||||||
* [Getting started](#getting-started)
|
* [Getting started](#getting-started)
|
||||||
* [Run Gateway](#run-gateway)
|
* [Run Gateway](#run-gateway)
|
||||||
* [Shell Scripts](#shell-scripts)
|
* [Shell Scripts](#shell-scripts)
|
||||||
@ -14,15 +15,16 @@ Python gateway for the [custom firmware](https://github.com/atc1441/ATC_MiThermo
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
**Features:**
|
## Roadmap
|
||||||
- WIP
|
|
||||||
|
**Done:**
|
||||||
|
- Make in runnable in a docker container (because only cool people are using docker)
|
||||||
|
- Make docker image smaller. I mean shiiit 1GB D: should be possible to be under 500MB (It's now around 100MB)
|
||||||
|
- Implement a loop for fetching the data every X seconds
|
||||||
|
|
||||||
**TODOs:**
|
**TODOs:**
|
||||||
- [WIP] Can run on Raspberry Pi (3, 4, zero w) or any other Linux driven hardware which has BLE and WiFi support
|
- [WIP] Can run on Raspberry Pi (3, 4, zero w) or any other Linux driven hardware which has BLE and WiFi support
|
||||||
- [WIP] Storing temperature, humidity and battery state as json in a text file
|
- [WIP] Storing temperature, humidity and battery state as json in a text file
|
||||||
- [WIP] Implement a loop for fetching the data every x minute
|
|
||||||
- [WIP] Make discoveries async
|
|
||||||
- [WIP] Make docker image smaller. I mean shiiit 1GB D: should be possible to be under 500MB
|
|
||||||
- [TODO] Make a microPython version for using the raspberry pico w or any other microcontroller with BLE and WiFi support
|
- [TODO] Make a microPython version for using the raspberry pico w or any other microcontroller with BLE and WiFi support
|
||||||
- [TODO] Collect data from multiple devices/gateways
|
- [TODO] Collect data from multiple devices/gateways
|
||||||
- [TODO] Command line tool for managing the devices
|
- [TODO] Command line tool for managing the devices
|
||||||
@ -31,11 +33,10 @@ Python gateway for the [custom firmware](https://github.com/atc1441/ATC_MiThermo
|
|||||||
- [TODO] MQTT publishing
|
- [TODO] MQTT publishing
|
||||||
- [TODO] Maybe... a webinterface. But I suck at web stuff, so I don't know.
|
- [TODO] Maybe... a webinterface. But I suck at web stuff, so I don't know.
|
||||||
- [TODO] Implement other BLE Sensors
|
- [TODO] Implement other BLE Sensors
|
||||||
- [BROK] Make in runnable in a docker container (because only cool people are using docker)
|
|
||||||
|
|
||||||
**Current State**
|
**Current State**
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
|
|||||||
@ -7,4 +7,4 @@ if [ "$API" = true ]; then
|
|||||||
sleep 1
|
sleep 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo python3.12 main.py
|
python3.12 main.py
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
bluepy
|
||||||
pyyaml
|
pyyaml
|
||||||
bs4
|
bs4
|
||||||
requests
|
requests
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
# This is a quick and dirty hack since the ENVs from the docker run command won't show up in the main.py
|
|
||||||
# I echo the output from the env command of a .env file, read and load it here into the os.environ.
|
|
||||||
# https://stackoverflow.com/questions/78684481/python-wont-find-the-env-in-my-docker-container
|
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def load_env():
|
|
||||||
if 'DOCKER' not in os.listdir('.'): return False
|
|
||||||
with open(file='.env', mode='r') as file: ENV = file.readlines()
|
|
||||||
for env in ENV:
|
|
||||||
env = env.strip()
|
|
||||||
key, value = env.split('=')
|
|
||||||
os.environ[key] = value
|
|
||||||
return True
|
|
||||||
@ -4,6 +4,8 @@ import json
|
|||||||
from data_class import Data
|
from data_class import Data
|
||||||
from devices import Device
|
from devices import Device
|
||||||
|
|
||||||
|
DEBUG = True if os.getenv('DEBUG') == 'true' else False
|
||||||
|
|
||||||
|
|
||||||
def log_to_json(devices):
|
def log_to_json(devices):
|
||||||
workdir, filename = os.path.split(os.path.abspath(__file__))
|
workdir, filename = os.path.split(os.path.abspath(__file__))
|
||||||
@ -13,7 +15,7 @@ def log_to_json(devices):
|
|||||||
data_obj: Data
|
data_obj: Data
|
||||||
from_config: Device
|
from_config: Device
|
||||||
file_name = f'{workdir}/data/{str(data_obj.mac).replace(":", "-")}.json'
|
file_name = f'{workdir}/data/{str(data_obj.mac).replace(":", "-")}.json'
|
||||||
print(file_name)
|
print(file_name) if DEBUG else {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(file_name, 'r') as file: data = json.load(file)
|
with open(file_name, 'r') as file: data = json.load(file)
|
||||||
|
|||||||
@ -2,16 +2,25 @@ import os
|
|||||||
from discovery import start_discovery
|
from discovery import start_discovery
|
||||||
from log_data import log_to_json
|
from log_data import log_to_json
|
||||||
from loop import start_loop
|
from loop import start_loop
|
||||||
from load_env import load_env
|
|
||||||
|
|
||||||
DOCKER = load_env()
|
|
||||||
INTERVAL = 40
|
INTERVAL = 40
|
||||||
TIMEOUT = 20
|
TIMEOUT = 20
|
||||||
|
DOCKER = True if os.getenv('DOCKER') == 'true' else False
|
||||||
|
DEBUG = True if os.getenv('DEBUG') == 'true' else False
|
||||||
|
interval = os.getenv('LOOP')
|
||||||
|
timeout = os.getenv('TIMEOUT')
|
||||||
|
|
||||||
|
if DEBUG:
|
||||||
|
print(f"INTERVAL: {INTERVAL}")
|
||||||
|
print(f"TIMEOUT: {TIMEOUT}")
|
||||||
|
print(f"interval: {interval}")
|
||||||
|
print(f"timeout: {timeout}")
|
||||||
|
print(f"DOCKER: {DOCKER}")
|
||||||
|
print(f"DEBUG: {DEBUG}")
|
||||||
|
print("")
|
||||||
|
|
||||||
if DOCKER:
|
if DOCKER:
|
||||||
print("Running in docker")
|
print("Running in docker")
|
||||||
interval = os.getenv('LOOP')
|
|
||||||
timeout = os.getenv('TIMEOUT')
|
|
||||||
|
|
||||||
try:INTERVAL = int(interval)
|
try:INTERVAL = int(interval)
|
||||||
except:pass
|
except:pass
|
||||||
@ -19,7 +28,8 @@ if DOCKER:
|
|||||||
try:TIMEOUT = int(timeout)
|
try:TIMEOUT = int(timeout)
|
||||||
except:pass
|
except:pass
|
||||||
|
|
||||||
start_loop(INTERVAL, TIMEOUT)
|
if interval is None: log_to_json(start_discovery(timeout=TIMEOUT))
|
||||||
|
else:start_loop(INTERVAL, TIMEOUT)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
start_loop(interval=40)
|
start_loop(interval=40)
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
TAG=develop
|
TAG="develop"
|
||||||
CONTAINER=dasmoorhuhn/atc-mithermometer-gateway:$TAG
|
CONTAINER="dasmoorhuhn/atc-mithermometer-gateway"
|
||||||
CONTAINER_NAME=ATC_MiThermometer_Gateway
|
CONTAINER_NAME="ATC_MiThermometer_Gateway"
|
||||||
VOLUME=YOUR_VOLUME
|
VOLUME=YOUR_VOLUME
|
||||||
|
|
||||||
D=""
|
BACKGROUND=""
|
||||||
TIME_ZONE="Europe/Berlin"
|
TIME_ZONE=""
|
||||||
INTERACTIVE=false
|
INTERACTIVE=false
|
||||||
BUILD=false
|
BUILD=false
|
||||||
API=false
|
API=false
|
||||||
|
DEBUG=false
|
||||||
LOOP="0"
|
LOOP="0"
|
||||||
TIMEOUT="0"
|
TIMEOUT="0"
|
||||||
|
|
||||||
@ -19,20 +20,19 @@ HELP="USAGE: sh run_docker.sh [OPTIONS] \n
|
|||||||
[ -a | --api ] Start with the API \n
|
[ -a | --api ] Start with the API \n
|
||||||
[ -tz | --timezone ] Set the timezone. Default is Europe/Berlin \n
|
[ -tz | --timezone ] Set the timezone. Default is Europe/Berlin \n
|
||||||
[ -to | --timeout ] Set the timeout for the bluetooth scan. default is 20s \n
|
[ -to | --timeout ] Set the timeout for the bluetooth scan. default is 20s \n
|
||||||
[ -h | --help ] Get this dialog"
|
[ -h | --help ] Get this dialog \n
|
||||||
|
[ --debug ] Set into debug mode"
|
||||||
|
|
||||||
docker_run() {
|
docker_run() {
|
||||||
sudo killall -9 bluetoothd > /dev/null 2>&1
|
sudo killall -9 bluetoothd > /dev/null 2>&1
|
||||||
echo Killing old container...
|
echo Killing old container...
|
||||||
docker stop $CONTAINER_NAME
|
docker stop $CONTAINER_NAME > /dev/null 2>&1
|
||||||
docker container rm $CONTAINER_NAME > /dev/null 2>&1
|
docker container rm $CONTAINER_NAME > /dev/null 2>&1
|
||||||
|
|
||||||
COMMAND="docker run $D"
|
COMMAND="docker run $BACKGROUND"
|
||||||
COMMAND="$COMMAND --cap-add=SYS_ADMIN"
|
COMMAND="$COMMAND --cap-add=SYS_ADMIN"
|
||||||
COMMAND="$COMMAND --cap-add=NET_ADMIN"
|
COMMAND="$COMMAND --cap-add=NET_ADMIN"
|
||||||
COMMAND="$COMMAND --net=host"
|
COMMAND="$COMMAND --net=host"
|
||||||
COMMAND="$COMMAND --env TZ=$TIME_ZONE"
|
|
||||||
COMMAND="$COMMAND --env API=$API"
|
|
||||||
COMMAND="$COMMAND --name=$CONTAINER_NAME"
|
COMMAND="$COMMAND --name=$CONTAINER_NAME"
|
||||||
COMMAND="$COMMAND --restart=on-failure"
|
COMMAND="$COMMAND --restart=on-failure"
|
||||||
COMMAND="$COMMAND --volume=/var/run/dbus/:/var/run/dbus/"
|
COMMAND="$COMMAND --volume=/var/run/dbus/:/var/run/dbus/"
|
||||||
@ -57,10 +57,28 @@ docker_run() {
|
|||||||
sh build_docker.sh --tag $TAG
|
sh build_docker.sh --tag $TAG
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$TIME_ZONE" != "" ]; then
|
||||||
|
COMMAND="$COMMAND --env TZ=$TIME_ZONE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$API" != false ]; then
|
||||||
|
COMMAND="$COMMAND --env API=$API"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$DEBUG" = true ]; then
|
||||||
|
COMMAND="$COMMAND --env DEBUG=$DEBUG"
|
||||||
|
COMMAND="$COMMAND $CONTAINER:$TAG"
|
||||||
|
echo
|
||||||
echo $COMMAND
|
echo $COMMAND
|
||||||
|
echo
|
||||||
|
echo DEBUG MODE
|
||||||
|
else
|
||||||
|
COMMAND="$COMMAND $CONTAINER:$TAG"
|
||||||
|
fi
|
||||||
|
|
||||||
echo Start container...
|
echo Start container...
|
||||||
echo
|
echo
|
||||||
$COMMAND $CONTAINER
|
$COMMAND
|
||||||
|
|
||||||
docker container rm $CONTAINER_NAME > /dev/null 2>&1
|
docker container rm $CONTAINER_NAME > /dev/null 2>&1
|
||||||
}
|
}
|
||||||
@ -68,7 +86,11 @@ docker_run() {
|
|||||||
while [ "$1" != "" ]; do
|
while [ "$1" != "" ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-d )
|
-d )
|
||||||
D="-d"
|
BACKGROUND="-d"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--debug )
|
||||||
|
DEBUG=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-a | --api)
|
-a | --api)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user