fix html and added password to enter page

This commit is contained in:
2024-11-12 14:13:43 +01:00
parent 194920bdad
commit 0e30854b51
2 changed files with 8 additions and 5 deletions

View File

@@ -2,7 +2,7 @@ from flask import Flask, request, render_template, jsonify
import paho.mqtt.client as mqtt
app = Flask(__name__)
# This function gets triggered when it receives a mqtt message
def on_message(client, userdata, message):
global kobuki_message #set scope for this variable
kobuki_message = str(message.payload.decode("utf-8"))
@@ -10,7 +10,7 @@ def on_message(client, userdata, message):
# Create an MQTT client instance
mqtt_client = mqtt.Client()
mqtt_client.username_pw_set("ishak", "kobuki")
mqtt_client.connect("145.92.224.21", 1883, 60)
mqtt_client.connect("localhost", 1883, 60)
mqtt_client.loop_start()
mqtt_client.subscribe("kobuki/data")
mqtt_client.on_message = on_message # this lines needs to be under the function definition otherwise it cant find which function it needs to use
@@ -18,7 +18,10 @@ mqtt_client.on_message = on_message # this lines needs to be under the function
@app.route('/', methods=["GET","POST"])
def index():
return render_template('index.html')
if request.authorization and request.authorization.username == 'ishak' and request.authorization.password == 'kobuki':
return render_template('index.html')
else:
return ('Unauthorized', 401, {'WWW-Authenticate': 'Basic realm="Login Required"'})
@app.route('/move', methods=['POST'])
def move():
@@ -40,4 +43,4 @@ def data():
if __name__ == '__main__':
app.run(debug=True)
app.run(debug=True, port=5000)

View File

@@ -29,7 +29,7 @@
<div class="container">
<h1>Sensor Data</h1>
<div class="data">
<table id="sensor-data-table">
<table id="sensor-data"> <!-- Do not change -->
<thead>
<tr>
<th>Sensor</th>