set image to latest
This commit is contained in:
parent
285a2503d7
commit
63e52fface
71
README.md
71
README.md
@ -2,9 +2,10 @@
|
||||
* [ATC_MiThermometer_Gateway](#atc_mithermometer_gateway)
|
||||
* [Roadmap](#roadmap)
|
||||
* [Getting started](#getting-started)
|
||||
* [Run Gateway](#run-gateway)
|
||||
* [Preconditions](#preconditions)
|
||||
* [Shell Scripts](#shell-scripts)
|
||||
* [Docker](#docker)
|
||||
* [Start Gateway](#start-gateway)
|
||||
* [Build your own docker container](#build-your-own-docker-container)
|
||||
* [MicroPython for MicroController](#micropython-for-microcontroller)
|
||||
* [Resources](#resources)
|
||||
<!-- TOC -->
|
||||
@ -42,23 +43,12 @@ Python gateway for the [custom firmware](https://github.com/atc1441/ATC_MiThermo
|
||||
|
||||
First of all, you need to flash the [custom firmware](https://github.com/atc1441/ATC_MiThermometer) on your LYWSD03MMC device. A step-by-step guid is in his youtube channel, the video is linked on his GitHub repo. It's straight forward and does not require any special hardware.
|
||||
|
||||
## Run Gateway
|
||||
|
||||
The libraries are needed to be installed as root, because the gateway itself needs to be executed as root, else it is not able to use the bluetooth adapter. In the future, I try to do it better. Also in the future it will be much easier to start and install.
|
||||
## Preconditions
|
||||
|
||||
Install `bluez`. It's needed for bluepy to communicate with the bluetooth adapter.
|
||||
```bash
|
||||
sudo apt-get install -y bluez
|
||||
```
|
||||
Install PIP Libraries
|
||||
```bash
|
||||
sudo pip3 install -r python/requirements.txt
|
||||
```
|
||||
Run Gateway
|
||||
```bash
|
||||
cd python/src
|
||||
sudo python3 main.py
|
||||
```
|
||||
|
||||
## Shell Scripts
|
||||
|
||||
@ -66,36 +56,53 @@ sudo python3 main.py
|
||||
|
||||
| Arg | Meaning | Default |
|
||||
|---------------|----------------------------|---------------------------------------|
|
||||
| -t \| --tag | Set a tag for build | develop |
|
||||
| -t \| --tag | Set a tag for build | latest |
|
||||
| -i \| --image | Set a image name for build | dasmoorhuhn/atc-mithermometer-gateway |
|
||||
| -h \| --help | Get this help in the CLI | |
|
||||
|
||||
**run_docker.sh**
|
||||
|
||||
| Arg | Meaning | Default |
|
||||
|-------------------|----------------------------------------------|---------------|
|
||||
| -d | Run in Backgrund | |
|
||||
| -t \| --tag | Set a docker tag | develop |
|
||||
| -b \| --build | Build the image before running the container | |
|
||||
| -l \| --loop | Start the gateway in looping mode | |
|
||||
| -a \| --api | Start with the API | false |
|
||||
| -tz \| --timezone | Set the timezone | Europe/Berlin |
|
||||
| -to \| --timeout | Set the timeout for the bluetooth scan | 20 |
|
||||
| -h \| --help | Get this dialog in CLI | |
|
||||
| Arg | Meaning | Default |
|
||||
|---------------------|------------------------------------------------------------------------------------------------------------------------|----------------------|
|
||||
| -d | Run in Backgrund | false |
|
||||
| -t \| --tag | Set a docker tag | latest |
|
||||
| -b \| --build | Build the image before running the container | false |
|
||||
| -l \| --loop | Start the gateway in looping mode | false (40s fallback) |
|
||||
| -i \| --interactive | Start the container in interactive mode. That means, you can read the console output in real time and abort via STRG+C | false |
|
||||
| -a \| --api | Start with the API | false |
|
||||
| -v \| --volume | Set the volume, where the data from the gateway will be stored. Use relative path like /home/user/gateway/data | data |
|
||||
| -tz \| --timezone | Set the timezone | Europe/Berlin |
|
||||
| -to \| --timeout | Set the timeout for the bluetooth scan | 20 |
|
||||
| -h \| --help | Get this dialog in CLI | |
|
||||
| --debug | Activate debug mode. Meant for fixing errors or development. | false |
|
||||
|
||||
## Docker
|
||||
## Start Gateway
|
||||
|
||||
Build docker container ()
|
||||
For getting started, you need to download the `run_gateway.sh` or build the docker run commands by your own.
|
||||
|
||||
Run Gateway
|
||||
```bash
|
||||
sh build_docker.sh
|
||||
# Or
|
||||
sh build_docker.sh -i your-image-name -t your-tag
|
||||
sh run_gateway.sh
|
||||
```
|
||||
Run docker container. Killing the hosts bluetooth service is needed to access it from the docker container.
|
||||
|
||||
Run Gateway with specified volume for persistence data, loop interval of 40 seconds and interactive mode
|
||||
```bash
|
||||
sudo sh run_docker.sh
|
||||
sh run_gateway.sh --volume /home/username/data --loop 40 --interactive
|
||||
```
|
||||
|
||||
## Build your own docker container
|
||||
|
||||
Build for your current platform (Without parameters, default values will be chosen)
|
||||
```bash
|
||||
sh build_docker.sh --image you/your-image-name you/your-image-name
|
||||
```
|
||||
|
||||
For building the docker container for multiple platforms at once, you need to have [docker buildx](https://github.com/docker/buildx) installed. (Without parameters, default values will be chosen)
|
||||
```bash
|
||||
sh build_docker_multi_platforn.sh --platforms linux/amd64,linux/arm64 --image you/your-image-name you/your-image-name
|
||||
```
|
||||
|
||||
|
||||
## MicroPython for MicroController
|
||||
|
||||
Coming when I develop it...
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
TAG=develop
|
||||
TAG=latest
|
||||
IMAGE=dasmoorhuhn/atc-mithermometer-gateway
|
||||
HELP="USAGE: sh build_docker.sh \n
|
||||
[ -t | --tag ] Select a tag for building. Default is develop \n
|
||||
[ -t | --tag ] Select a tag for building. Default is latest \n
|
||||
[ -i | --image ] Select image tag for building. Default is dasmoorhuhn/atc-mithermometer-gateway \n
|
||||
[ -h | --help ] Get this dialog"
|
||||
|
||||
docker version > /dev/null 2>&1
|
||||
if [ "$?" != 0 ]; then
|
||||
echo Missing docker. Please install docker and try build again.
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker_build(){
|
||||
docker build --tag $IMAGE:$TAG .
|
||||
}
|
||||
|
||||
@ -1,10 +1,55 @@
|
||||
TAG=develop
|
||||
TAG=latest
|
||||
IMAGE=dasmoorhuhn/atc-mithermometer-gateway
|
||||
PLATFORMS=linux/amd64,linux/arm64,linux/arm
|
||||
HELP="USAGE: sh build_docker.sh \n
|
||||
[ -t | --tag ] Select a tag for building. Default: latest \n
|
||||
[ -i | --image ] Select image tag for building. Default: dasmoorhuhn/atc-mithermometer-gateway \n
|
||||
[ -p | --platforms ] Select the platforms, for which the image should build. Default: linux/amd64,linux/arm64,linux/arm \n
|
||||
[ -h | --help ] Get this dialog"
|
||||
|
||||
set e
|
||||
docker buildx version
|
||||
unset e
|
||||
if [ "$?" != 0 ]; then
|
||||
echo Missing docker buildx. Please install docker buildx from https://github.com/docker/buildx and try build again.
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker buildx create --name builder
|
||||
docker buildx use builder
|
||||
create_builder() {
|
||||
docker buildx create --name builder
|
||||
docker buildx use builder
|
||||
}
|
||||
|
||||
docker buildx build --tag dasmoorhuhn/atc-mithermometer-gateway:$TAG --platform=linux/amd64,linux/arm64,linux/arm --push .
|
||||
build_docker() {
|
||||
create_builder
|
||||
docker login
|
||||
docker buildx build --tag $IMAGE:$TAG --platform=$PLATFORMS --push .
|
||||
}
|
||||
|
||||
while [ "$1" != "" ]; do
|
||||
case $1 in
|
||||
-t | --tag )
|
||||
shift
|
||||
TAG=$1
|
||||
shift
|
||||
;;
|
||||
-i | --image )
|
||||
shift
|
||||
IMAGE=$1
|
||||
shift
|
||||
;;
|
||||
-p | --platforms )
|
||||
shift
|
||||
PLATFORMS=$1
|
||||
shift
|
||||
;;
|
||||
-h | --help )
|
||||
echo $HELP
|
||||
exit
|
||||
;;
|
||||
* )
|
||||
echo $HELP
|
||||
echo $1
|
||||
exit 1
|
||||
esac
|
||||
done
|
||||
|
||||
build_docker
|
||||
@ -23,15 +23,19 @@ def log_to_json(devices):
|
||||
with open(file_name, 'w') as file: file.write("[]")
|
||||
data = []
|
||||
|
||||
data.append({
|
||||
measurements = {
|
||||
"timestamp": data_obj.timestamp,
|
||||
"temperature": data_obj.temperature,
|
||||
"humidity": data_obj.humidity,
|
||||
"battery_percent": data_obj.battery_percent,
|
||||
"battery_volt": data_obj.battery_volt,
|
||||
"rssi": dev.rssi,
|
||||
"name": from_config.name,
|
||||
"room": from_config.room
|
||||
})
|
||||
}
|
||||
data.append(measurements)
|
||||
|
||||
print(measurements) if DEBUG else {}
|
||||
|
||||
with open(file_name, 'w') as file: file.write(json.dumps(data, indent=2))
|
||||
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
TAG="develop"
|
||||
|
||||
|
||||
TAG="latest"
|
||||
CONTAINER="dasmoorhuhn/atc-mithermometer-gateway"
|
||||
CONTAINER_NAME="ATC_MiThermometer_Gateway"
|
||||
VOLUME=YOUR_VOLUME
|
||||
VOLUME=data
|
||||
|
||||
BACKGROUND=""
|
||||
TIME_ZONE=""
|
||||
@ -14,15 +16,23 @@ TIMEOUT="0"
|
||||
|
||||
HELP="USAGE: sh run_docker.sh [OPTIONS] \n
|
||||
[ -d ] Run in Backgrund \n
|
||||
[ -t | --tag ] Set a docker tag \n
|
||||
[ -t | --tag ] Set a docker tag. Default: latest \n
|
||||
[ -b | --build ] Build the image before running the container \n
|
||||
[ -l | --loop ] Start the gateway in looping mode. e.g.: --loop 40 will set the interval of the loop to 40s. Default is single run mode \n
|
||||
[ -i | --interactive ] Start the container in interactive mode. That means, you can read the console output in real time and abort via STRG+C \n
|
||||
[ -a | --api ] Start with the API \n
|
||||
[ -v | --volume ] Set the volume, where the data from the gateway will be stored. Use relative path like /home/user/gateway/data \n
|
||||
[ -tz | --timezone ] Set the timezone. Default is Europe/Berlin \n
|
||||
[ -to | --timeout ] Set the timeout for the bluetooth scan. default is 20s \n
|
||||
[ -h | --help ] Get this dialog \n
|
||||
[ --debug ] Set into debug mode"
|
||||
|
||||
docker version > /dev/null 2>&1
|
||||
if [ "$?" != 0 ]; then
|
||||
echo Missing docker. Please install docker and try build again.
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker_run() {
|
||||
sudo killall -9 bluetoothd > /dev/null 2>&1
|
||||
echo Killing old container...
|
||||
@ -101,6 +111,11 @@ while [ "$1" != "" ]; do
|
||||
BUILD=true
|
||||
shift
|
||||
;;
|
||||
-v | --volume )
|
||||
shift
|
||||
VOLUME=$1
|
||||
shift
|
||||
;;
|
||||
-tz | --timezone )
|
||||
shift
|
||||
TIME_ZONE=$1
|
||||
@ -118,8 +133,15 @@ while [ "$1" != "" ]; do
|
||||
;;
|
||||
-l | --loop )
|
||||
shift
|
||||
LOOP=$1
|
||||
shift
|
||||
firstchar=`echo $1 | cut -c1-1`
|
||||
if [ "$firstchar" = "-" ]; then
|
||||
LOOP=0
|
||||
elif [ "$firstchar" = "" ]; then
|
||||
LOOP=0
|
||||
else
|
||||
LOOP=$1
|
||||
shift
|
||||
fi
|
||||
;;
|
||||
-i | --interactive )
|
||||
INTERACTIVE=true
|
||||
@ -135,5 +157,5 @@ while [ "$1" != "" ]; do
|
||||
esac
|
||||
done
|
||||
|
||||
docker_run
|
||||
# docker_run
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user