doorbell: 5s threshold for MQTT notifications
This commit is contained in:
@@ -20,6 +20,11 @@ logger.info('Initializing')
|
|||||||
|
|
||||||
|
|
||||||
arduino = serial.Serial('/dev/Doorbell', 9600, timeout=.1)
|
arduino = serial.Serial('/dev/Doorbell', 9600, timeout=.1)
|
||||||
|
# for ESP32
|
||||||
|
#arduino.setDTR(False)
|
||||||
|
#arduino.setRTS(False)
|
||||||
|
|
||||||
|
last_ring = time.time()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data = arduino.readline()[:-2] #the last bit gets rid of the new-line chars
|
data = arduino.readline()[:-2] #the last bit gets rid of the new-line chars
|
||||||
@@ -35,7 +40,9 @@ while True:
|
|||||||
try:
|
try:
|
||||||
response = urllib.request.urlopen('http://192.168.178.60/bell/on', timeout=5).read().decode('utf-8')
|
response = urllib.request.urlopen('http://192.168.178.60/bell/on', timeout=5).read().decode('utf-8')
|
||||||
|
|
||||||
# send MQTT
|
# send MQTT if last ring was more than 5 seconds ago
|
||||||
|
if ((time.time() - last_ring) > 5):
|
||||||
|
last_ring = time.time()
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjYjY5NjA5NmY0N2E0NmZlOGEzYjczOGYzYmUzOTk5ZSIsImlhdCI6MTY2MTM0NDgxOSwiZXhwIjoxOTc2NzA0ODE5fQ.z9fzbVOA1Pbur3Zb07481n-SoYesj8cetw-CX6WPmTs",
|
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjYjY5NjA5NmY0N2E0NmZlOGEzYjczOGYzYmUzOTk5ZSIsImlhdCI6MTY2MTM0NDgxOSwiZXhwIjoxOTc2NzA0ODE5fQ.z9fzbVOA1Pbur3Zb07481n-SoYesj8cetw-CX6WPmTs",
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
|
|||||||
Reference in New Issue
Block a user