commit 712320fb474929153942aa1c765becc4f1697ebe Author: NilsGrunwald Date: Sun Oct 2 16:46:33 2022 +0200 initial checkin with access to mqtt 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 0000000..97740dc Binary files /dev/null and b/__pycache__/__init__.cpython-37.pyc differ diff --git a/__pycache__/app.cpython-37.pyc b/__pycache__/app.cpython-37.pyc new file mode 100644 index 0000000..5c7a924 Binary files /dev/null and b/__pycache__/app.cpython-37.pyc differ 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