initial checkin with access to mqtt

This commit is contained in:
2022-10-02 16:46:33 +02:00
commit 712320fb47
6 changed files with 60 additions and 0 deletions

25
.vscode/launch.json vendored Normal file
View File

@@ -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
}
]
}

6
__init__.py Normal file
View File

@@ -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...")

Binary file not shown.

Binary file not shown.

28
app.py Normal file
View File

@@ -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

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@
paho-mqtt == 1.5.0