Merge branch 'master' of https://www.nodebucket.de:3000/tilman/smart-home
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# https://www.instructables.com/id/Arduino-Python-Communication-via-USB/
|
# https://www.instructables.com/id/Arduino-Python-Communication-via-USB/
|
||||||
# in rc.local:
|
# in /etc/systemd/system/startup-commands.service (s. https://www.nodebucket.de/index.php/apps/cms_pico/pico/server/setup):
|
||||||
# su tilman -c 'python3 /media/hd/admin/doorbell/doorbell.py >> /media/hd/admin/doorbell/doorbell.log 2>&1 &'
|
# ExecStart = su tilman -c 'python3 /media/hd/admin/doorbell/doorbell.py >> /media/hd/admin/doorbell/doorbell.log 2>&1 &'
|
||||||
|
|
||||||
import serial
|
import serial
|
||||||
import urllib.request
|
import urllib.request
|
||||||
@@ -28,21 +28,21 @@ while True:
|
|||||||
data = data.decode('utf8')
|
data = data.decode('utf8')
|
||||||
except (UnicodeDecodeError) as ude:
|
except (UnicodeDecodeError) as ude:
|
||||||
logger.error(ude)
|
logger.error(ude)
|
||||||
|
else:
|
||||||
|
logger.info(data)
|
||||||
|
|
||||||
if (data == 'RING'):
|
if (data == 'RING'):
|
||||||
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
|
||||||
headers = {
|
headers = {
|
||||||
# "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjYjY5NjA5NmY0N2E0NmZlOGEzYjczOGYzYmUzOTk5ZSIsImlhdCI6MTY2MTM0NDgxOSwiZXhwIjoxOTc2NzA0ODE5fQ.z9fzbVOA1Pbur3Zb07481n-SoYesj8cetw-CX6WPmTs",
|
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjYjY5NjA5NmY0N2E0NmZlOGEzYjczOGYzYmUzOTk5ZSIsImlhdCI6MTY2MTM0NDgxOSwiZXhwIjoxOTc2NzA0ODE5fQ.z9fzbVOA1Pbur3Zb07481n-SoYesj8cetw-CX6WPmTs",
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
data = json.dumps({'payload': 'RING', 'topic': 'lewe/doorbell', 'retain': 'False'}).encode('utf8')
|
data = json.dumps({'payload': 'RING', 'topic': 'lewe/doorbell', 'retain': 'False'}).encode('utf8')
|
||||||
request = urllib.request.Request("localhost:8123/api/services/mqtt/publish", data, headers)
|
request = urllib.request.Request("https://www.nodebucket.de:8123/api/services/mqtt/publish", data, headers)
|
||||||
# request = urllib.request.Request("https://www.nodebucket.de:8123/api/services/mqtt/publish", data, headers)
|
|
||||||
response = urllib.request.urlopen(request)
|
response = urllib.request.urlopen(request)
|
||||||
except Exception as err:
|
except Exception:
|
||||||
logger.error("Could not ring doorbell")
|
logger.error("Could not ring doorbell")
|
||||||
time.sleep(300)
|
time.sleep(300)
|
||||||
else:
|
|
||||||
logger.info(data)
|
|
||||||
Reference in New Issue
Block a user