Use a different service (XMPP this time)
This commit is contained in:
parent
1d1381f390
commit
cd7f9d8f9a
20
temperato.py
20
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()
|
||||
|
Loading…
Reference in New Issue
Block a user