set up docker generation
This commit is contained in:
8
web2mqtt/__init__.py
Normal file
8
web2mqtt/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from flask import Flask # Import the Flask class
|
||||
app = Flask(__name__) # Create an instance of the class for our use
|
||||
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
client = mqtt.Client("Web2Mqtt")
|
||||
client.connect("192.168.178.76",1884)
|
||||
client.publish("web2mqtt/status","Web2Mqtt starting up...")
|
||||
5
web2mqtt/static/data.json
Normal file
5
web2mqtt/static/data.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"01": {
|
||||
"note" : "Data is very simple because we're demonstrating only the mechanism."
|
||||
}
|
||||
}
|
||||
32
web2mqtt/static/site.css
Normal file
32
web2mqtt/static/site.css
Normal file
@@ -0,0 +1,32 @@
|
||||
.message {
|
||||
font-weight: 600;
|
||||
color: blue;
|
||||
}
|
||||
|
||||
.navbar {
|
||||
background-color: lightslategray;
|
||||
font-size: 1em;
|
||||
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
|
||||
color: white;
|
||||
padding: 8px 5px 8px 5px;
|
||||
}
|
||||
|
||||
.navbar a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-size: 1.2em;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.navbar-item {
|
||||
font-variant: small-caps;
|
||||
margin-left: 30px;
|
||||
}
|
||||
|
||||
.body-content {
|
||||
padding: 5px;
|
||||
font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
}
|
||||
7
web2mqtt/templates/about.html
Normal file
7
web2mqtt/templates/about.html
Normal file
@@ -0,0 +1,7 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block title %}
|
||||
About us
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<p>About page for the Visual Studio Code Flask tutorial.</p>
|
||||
{% endblock %}
|
||||
7
web2mqtt/templates/contact.html
Normal file
7
web2mqtt/templates/contact.html
Normal file
@@ -0,0 +1,7 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block title %}
|
||||
Contact us
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<p>Contact page for the Visual Studio Code Flask tutorial.</p>
|
||||
{% endblock %}
|
||||
16
web2mqtt/templates/hello_there.html
Normal file
16
web2mqtt/templates/hello_there.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='site.css') }}" />
|
||||
<title>Hello, Flask</title>
|
||||
</head>
|
||||
<body>
|
||||
{%if name %}
|
||||
<span class="message">Hello there, {{ name }}!</span> It's {{ date.strftime("%A, %d %B, %Y at %X") }}.
|
||||
{% else %}
|
||||
<span class="message">What's your name? Provide it after /hello/ in the URL.</span>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
<!-- The above syntax makes use of jinja and it's documentation can be found over here http://jinja.pocoo.org/docs/2.10/templates/ -->
|
||||
7
web2mqtt/templates/home.html
Normal file
7
web2mqtt/templates/home.html
Normal file
@@ -0,0 +1,7 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block title %}
|
||||
Home
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<p>Home page for the Visual Studio Code Flask tutorial.</p>
|
||||
{% endblock %}
|
||||
25
web2mqtt/templates/layout.html
Normal file
25
web2mqtt/templates/layout.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>{% block title %}{% endblock %}</title>
|
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='site.css') }}" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="navbar">
|
||||
<a href="{{ url_for('home') }}" class="navbar-brand">Home</a>
|
||||
<a href="{{ url_for('about') }}" class="navbar-item">About</a>
|
||||
<a href="{{ url_for('contact') }}" class="navbar-item">Contact</a>
|
||||
</div>
|
||||
|
||||
<div class="body-content">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
<hr/>
|
||||
<footer>
|
||||
<p>© 2018</p>
|
||||
</footer>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
45
web2mqtt/views.py
Normal file
45
web2mqtt/views.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from datetime import datetime
|
||||
from flask import Flask, render_template,request
|
||||
from . import app, client
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
return render_template("home.html")
|
||||
|
||||
@app.route("/about/")
|
||||
def about():
|
||||
return render_template("about.html")
|
||||
|
||||
@app.route("/contact/")
|
||||
def contact():
|
||||
return render_template("contact.html")
|
||||
|
||||
@app.route("/hello/")
|
||||
@app.route("/hello/<name>")
|
||||
def hello_there(name = None):
|
||||
return render_template(
|
||||
"hello_there.html",
|
||||
name=name,
|
||||
date=datetime.now()
|
||||
)
|
||||
|
||||
@app.route("/api/data")
|
||||
def get_data():
|
||||
return app.send_static_file("data.json")
|
||||
|
||||
CMD = "web2mqtt/command"
|
||||
|
||||
@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
|
||||
6
web2mqtt/webapp.py
Normal file
6
web2mqtt/webapp.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# Entry point for the application.
|
||||
from . import app # For application discovery by the 'flask' command.
|
||||
from . import views # For import side-effects of setting up routes.
|
||||
|
||||
# Time-saver: output a URL to the VS Code terminal so you can easily Ctrl+click to open a browser
|
||||
# print('http://127.0.0.1:5000/hello/VSCode')
|
||||
Reference in New Issue
Block a user