wip
This commit is contained in:
@@ -12,6 +12,11 @@ import paho.mqtt.client as mqtt
|
||||
from climate_control.sensors import Dht22
|
||||
from climate_control.heat import Heat
|
||||
|
||||
LOG_FILE = "/var/log/climate.log"
|
||||
LOG_FORMAT = "%(asctime)s %(filename)s:%(lineno)d %(message)s"
|
||||
LOG_LEVEL = logging.INFO
|
||||
LOG_INTERVAL = 5
|
||||
|
||||
MQTT_BROKER = "mqtt.blackfinn.de"
|
||||
MQTT_PORT = 8883
|
||||
MQTT_CERT = "/etc/ssl/certs/DST_Root_CA_X3.pem"
|
||||
@@ -26,6 +31,8 @@ ROOM_HEAT_THRESHOLD = {"on": 1.0, "off": 2.0}
|
||||
STATE_OFF = "off"
|
||||
STATE_ON = "ON"
|
||||
|
||||
#logging.basicConfig(format=LOG_FORMAT, level=LOG_LEVEL, filename=LOG_FILE)
|
||||
|
||||
class ClimateControl(threading.Thread):
|
||||
__water_heat = Heat(20)
|
||||
__room_heat = Heat(21)
|
||||
@@ -69,6 +76,7 @@ class ClimateControl(threading.Thread):
|
||||
self.__now = time.time()
|
||||
if self.__next <= self.__now:
|
||||
humidity, temperature = self.__climate.read()
|
||||
logging.info("Temperature: {}\tHumidity: {}".format(temperature, humidity))
|
||||
try:
|
||||
client = mqtt.Client()
|
||||
client.tls_set(MQTT_CERT)
|
||||
@@ -86,8 +94,8 @@ class ClimateControl(threading.Thread):
|
||||
client.publish(MQTT_ROOM_HEAT_TOPIC, msg, qos=2, retain=True)
|
||||
client.loop_stop()
|
||||
client.disconnect()
|
||||
except(ValueError, TypeError, socket.error, ssl.CertificateError):
|
||||
logging.info('unable to publish to mqtt')
|
||||
except(ValueError, TypeError, socket.error, ssl.CertificateError) as error:
|
||||
logging.info('unable to publish to mqtt ({})'.format(error))
|
||||
self.__next = self.__now + self.__interval
|
||||
time.sleep(1)
|
||||
|
||||
|
Reference in New Issue
Block a user