From cd7f9d8f9a8ca7fa4c54c53b6085564a908d375f Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 5 Apr 2022 09:12:02 -0500 Subject: [PATCH] Use a different service (XMPP this time) --- temperato.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/temperato.py b/temperato.py index 455ecfb..d785538 100644 --- a/temperato.py +++ b/temperato.py @@ -22,21 +22,33 @@ import threading import time import os import json -import math +import xmpp set_point = 82.22 -sleep_timer = 15 +sleep_timer = 1 +tick_threshold = 5 spi = board.SPI() cs = digitalio.DigitalInOut(board.D26) sensor = adafruit_max31865.MAX31865(spi, cs, wires=3) +jid = xmpp.protocol.JID(os.environ.get('XMPP_SENDER')) +conn = xmpp.Client(server=jid.getDomain(), debug=False) +conn.connect() +conn.auth(user=jid.getNode(), password=os.environ.get('XMPP_SENDER_PASSWORD'), resource=jid.getResource()) class tempThread (threading.Thread): def run(self): + ticks = 0 while True: temp = sensor.temperature - if math.isclose(temp,set_point): - print(requests.post(os.environ.get('NOTIF_URL'), headers={'Content-Type': 'application/json', 'Authorization': 'Bearer ' + os.environ.get('ACCESS_TOKEN')}, data=json.dumps({'message': '@all ' + os.environ.get('MESSAGE'), 'channel_id': os.environ.get('CHANNEL_ID')}), timeout=5)) + if temp >= set_point: + ticks += 1 + else: + ticks = 0 + + if ticks == tick_threshold: + ticks = 0 + conn.send(xmpp.protocol.Message(to=os.environ.get('XMPP_RECEIVER'), body=os.environ.get('MESSAGE'))) time.sleep(sleep_timer) T_thread = tempThread()