initial checkin with access to mqtt
This commit is contained in:
25
.vscode/launch.json
vendored
Normal file
25
.vscode/launch.json
vendored
Normal 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
6
__init__.py
Normal 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...")
|
||||||
|
|
||||||
BIN
__pycache__/__init__.cpython-37.pyc
Normal file
BIN
__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/app.cpython-37.pyc
Normal file
BIN
__pycache__/app.cpython-37.pyc
Normal file
Binary file not shown.
28
app.py
Normal file
28
app.py
Normal 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
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
paho-mqtt == 1.5.0
|
||||||
Reference in New Issue
Block a user