Skip to content

Commit

Permalink
dockerized home status service
Browse files Browse the repository at this point in the history
  • Loading branch information
wassfila committed May 30, 2024
1 parent caa6b92 commit a617c5d
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 34 deletions.
11 changes: 9 additions & 2 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ services:
#socket_domain ipv4 https://github.com/eclipse/mosquitto/issues/1004
image: eclipse-mosquitto
ports:
- "1883:1883"
- "1884:1884"
- 1883:1883
- 1884:1884
volumes:
- ${PWD}/containers/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
restart: unless-stopped
Expand All @@ -17,10 +17,17 @@ services:
- ${PWD}/containers/influxdb/data:/var/log/influx
environment:
- INFLUXDB_DB:=mqtt
home_status:
build: ./home_status
volumes:
- /var/log/home_status:/var/log/home_status
environment:
- BROKER=10.0.0.91
chronograf:
image: chronograf
ports:
- "8888:8888"

grafana:
image: grafana/grafana
ports:
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions home_status/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.9-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install -r requirements.txt
COPY *.py .
COPY config.json .

ENTRYPOINT ["python", "home.py"]
File renamed without changes.
3 changes: 1 addition & 2 deletions py/home_status/config.json → home_status/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"mqtt":{
"host":"mqtt_broquer",
"port":1883,
"keepalive":60,
"client_id":"home_status_client",
Expand Down Expand Up @@ -48,7 +47,7 @@
}
},
"log":{
"logfile":"/home/pi/share/home_status(date).log",
"logfile":"/var/log/home_status/(date).log",
"level":"Info"
}
}
6 changes: 0 additions & 6 deletions py/home_status/home.py → home_status/home.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#https://github.com/studioimaginaire/phue


#https://pypi.python.org/pypi/paho-mqtt/1.1
import paho.mqtt.client as mqtt
import json
from time import sleep
import logging as log
import sys,os
import cfg
from mqtt import mqtt_start
import requests
Expand Down
11 changes: 5 additions & 6 deletions py/home_status/mqtt.py → home_status/mqtt.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import paho.mqtt.client as mqtt
import datetime
import logging as log
import cfg
from time import sleep,time
import json
from time import sleep
import os
import socket

conf = {}
Expand Down Expand Up @@ -36,9 +34,10 @@ def mqtt_connect_retries(client):
connected = False
while(not connected):
try:
client.connect(config["mqtt"]["host"], config["mqtt"]["port"], config["mqtt"]["keepalive"])
host = os.environ.get("BROKER","mqtt_broquer")
client.connect(host, config["mqtt"]["port"], config["mqtt"]["keepalive"])
connected = True
log.info( "mqtt> connected to "+config["mqtt"]["host"]+":"+str(config["mqtt"]["port"])+" with id: "+ cid )
log.info( "mqtt> connected to "+host+":"+str(config["mqtt"]["port"])+" with id: "+ cid )
except socket.error:
log.error("socket.error will try a reconnection in 10 s")
sleep(10)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
paho-mqtt
requests
11 changes: 0 additions & 11 deletions py/home_status/home_status.service

This file was deleted.

7 changes: 0 additions & 7 deletions py/home_status/setup.sh

This file was deleted.

0 comments on commit a617c5d

Please sign in to comment.