This commit is contained in:
2022-11-03 15:58:57 +01:00
2 changed files with 61 additions and 0 deletions
@@ -7,6 +7,7 @@ import urllib.request
import logging
import logging.handlers as handlers
import time
import json
logger = logging.getLogger('Rotating Log')
logger.setLevel(logging.INFO)
@@ -30,6 +31,15 @@ while True:
if (data == 'RING'):
try:
response = urllib.request.urlopen('http://192.168.178.60/bell/on', timeout=5).read().decode('utf-8')
# send MQTT
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjYjY5NjA5NmY0N2E0NmZlOGEzYjczOGYzYmUzOTk5ZSIsImlhdCI6MTY2MTM0NDgxOSwiZXhwIjoxOTc2NzA0ODE5fQ.z9fzbVOA1Pbur3Zb07481n-SoYesj8cetw-CX6WPmTs"
}
data = json.dumps({'payload': 'RING', 'topic': 'lewe/doorbell', 'retain': 'False'}).encode('utf8')
reqest = urllib.request.Request("https://www.nodebucket.de:8123/api/services/mqtt/publish", data, headers)
response = urllib.request.urlopen(reqest)
except Exception:
logger.error("Could not ring doorbell")
# logger.exception("Could not ring doorbell")