Skip to content

Commit c9804d4

Browse files
committed
Merge branch 'dockerize'
2 parents df4b125 + eff0af9 commit c9804d4

File tree

6 files changed

+55
-16
lines changed

6 files changed

+55
-16
lines changed

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM python:3.8
2+
3+
RUN apt-get update \
4+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --no-install-suggests \
5+
libsensors5 \
6+
&& rm -rf /var/lib/apt/lists/*
7+
8+
COPY requirements.txt /
9+
RUN pip install -r requirements.txt
10+
11+
COPY *.py /
12+
13+
CMD ["python", "-u", "./app.py"]

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
> Watch pre-defined lmsensors values and post them to MQTT topics.
44
5+
## Configuration
6+
7+
The following environment variables are expected:
8+
9+
* `MQTT_HOST` Name of the MQTT host
10+
* `MQTT_TOPIC` Prefix for the MQTT topic
11+
* `SENSORS` expects a JSON sensor configuration in the following form:
12+
```json
13+
{
14+
"<chip name>": {
15+
"features": {
16+
"<feature name>": {
17+
"label": "<feature label>",
18+
"mqtt": "<feature mqtt topic (added to prefix)>"
19+
}
20+
}
21+
}
22+
}
23+
```
24+
525
## Contributions
626

727
Contributions are welcome and should be made via PR.

app.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import sensors
1313

14+
import util
15+
1416
running = True
1517

1618

@@ -54,17 +56,17 @@ def emit_chip_values(mqtt_client, mqtt_prefix, cfg_chips, sensor_chip):
5456

5557

5658
def main():
59+
global running
5760
signal.signal(signal.SIGINT, sigint_handler)
5861

59-
with open("sensors-report-cfg.json", "r") as f:
60-
config = json.load(f)
61-
6262
mqtt_config = mqtt.MqttConfig.from_env("MQTT_")
6363
mqtt_client = mqtt.create_client(mqtt_config)
6464

6565
mqtt_prefix = mqtt_config.prefix
6666

67-
cfg_chips = config.get('chips', list())
67+
cfg_chips = json.loads(util.load_env("SENSORS", "{}"))
68+
print("Running with sensors config:")
69+
print(json.dumps(cfg_chips, indent=4))
6870

6971
emit_labels(mqtt_client, mqtt_prefix, cfg_chips)
7072

docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Do not forget to create the .env file (see template)
2+
# before using this container!
3+
4+
version: '2'
5+
6+
services:
7+
sensors-report:
8+
restart: always
9+
build: .
10+
env_file:
11+
- .env
12+
environment:
13+
MQTT_HOST: $MQTT_HOST
14+
MQTT_PREFIX: $MQTT_PREFIX
15+

dotenv.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
MQTT_HOST=
22
MQTT_PREFIX=
3+
SENSORS=

sensors-report-cfg.json.template

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)