From 712320fb474929153942aa1c765becc4f1697ebe Mon Sep 17 00:00:00 2001 From: NilsGrunwald Date: Sun, 2 Oct 2022 16:46:33 +0200 Subject: [PATCH] initial checkin with access to mqtt --- .vscode/launch.json | 25 +++++++++++++++++++++++++ __init__.py | 6 ++++++ __pycache__/__init__.cpython-37.pyc | Bin 0 -> 305 bytes __pycache__/app.cpython-37.pyc | Bin 0 -> 791 bytes app.py | 28 ++++++++++++++++++++++++++++ requirements.txt | 1 + 6 files changed, 60 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 __init__.py create mode 100644 __pycache__/__init__.cpython-37.pyc create mode 100644 __pycache__/app.cpython-37.pyc create mode 100644 app.py create mode 100644 requirements.txt diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d193fa2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,25 @@ +{ + // Verwendet IntelliSense zum Ermitteln möglicher Attribute. + // Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen. + // Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Flask", + "type": "python", + "request": "launch", + "module": "flask", + "env": { + "FLASK_APP": "app.py", + "FLASK_DEBUG": "1" + }, + "args": [ + "run", + "--no-debugger", + "--no-reload" + ], + "jinja": true, + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..608a2f0 --- /dev/null +++ b/__init__.py @@ -0,0 +1,6 @@ +import paho.mqtt.client as mqtt + +client = mqtt.Client("Web2Mqtt") +client.connect("192.168.178.76",1884) +client.publish("web2mqtt/status","Web2Mqtt starting up...") + diff --git a/__pycache__/__init__.cpython-37.pyc b/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..97740dcafcc65be0ec4d470d75bb4f0e99dd1bcc GIT binary patch literal 305 zcmXv|O-sW-5S`iPqZF&+#et z$-m&qNhJgGX5O1O%-oE}BcKRBmdO{@?~e50P;*ULh6EBMrjQ{6gp3J9P}mG4+o52J zHI5ueXU9lojVoR0b-lz#nEF4o4G&`Yq}H?h7i;UoU^(N#JmkS5e+Qo)8qf)*i-g2Hs{CIjP{)Z-8}N>=a} z6;dKrd<%czEvx=QS6ok9f~9+PAGXi&xqjJf))B1VKc6KZ2||Bta=RP|4!}wdjw6mU zByof#i3qki$sFlK4#WwrN0s|m0if6OV?A%a$x?vGPQiO=I8ZX^$ zB6I$anN`;XtC)R)fa5jNXpJ@gOg0WDTdW?fFn4zO1N3y)r_evR=|K!<>Be2*724YA zKy-n)w?Y@_2VIjDfmi!OgCc54C?D_)EoQo0*810~_1JQsX_ZbULJ7_msh%>sp~u>u zar%QpWf>b9t4V2`iO|Zkxj&nqWNA5VJ1VU5n;{rKDRK=1+UccgutD7ecNeVO1BVF3 zl!W*`4sl3A(!y20-8Am0{Q=4fSOF_LJY_|_#wALaU_8!aDaK>tfbyydP2;L!u0^GI ib=80H)$}X}6Fip%pJ(EQ{Tk&RaIK0!KmtO^9{mfh(Xt2t literal 0 HcmV?d00001 diff --git a/app.py b/app.py new file mode 100644 index 0000000..8bf0031 --- /dev/null +++ b/app.py @@ -0,0 +1,28 @@ +from flask import Flask, request +from datetime import datetime +from . import client + +import re + +app = Flask(__name__) + +CMD = "web2mqtt/command" + +@app.route("/") +def home(): + return "Small URL to MQTT Gateway for home automation...!" + +@app.route("/cmnd") +def command(): + opts = "" + command = CMD + + if request.args.get('cmnd'): + command += "/" + request.args.get('cmnd') + if request.args.get('opts'): + opts = request.args.get('opts') + + client.publish(command,opts) + + content = f"Command: {command} triggered with opts: {opts}" + return content \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4b2c12c --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +paho-mqtt == 1.5.0 \ No newline at end of file