mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
see if connection is actually made
This commit is contained in:
@@ -6,7 +6,7 @@ app = Flask(__name__)
|
|||||||
|
|
||||||
kobuki_message = "empty"
|
kobuki_message = "empty"
|
||||||
def on_message(client, userdata, message):
|
def on_message(client, userdata, message):
|
||||||
global kobuki_message #set scope for this variable
|
global kobuki_message
|
||||||
kobuki_message = str(message.payload.decode("utf-8"))
|
kobuki_message = str(message.payload.decode("utf-8"))
|
||||||
print(kobuki_message)
|
print(kobuki_message)
|
||||||
|
|
||||||
@@ -16,24 +16,13 @@ mqtt_client.username_pw_set("server", "serverwachtwoordofzo")
|
|||||||
mqtt_client.connect("localhost", 80, 60)
|
mqtt_client.connect("localhost", 80, 60)
|
||||||
mqtt_client.loop_start()
|
mqtt_client.loop_start()
|
||||||
mqtt_client.subscribe("kobuki/data")
|
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
|
mqtt_client.on_message = on_message
|
||||||
|
|
||||||
|
|
||||||
cnx = mysql.connector.connect(
|
|
||||||
host="127.0.0.1",
|
|
||||||
port=3306,
|
|
||||||
user="admin",
|
|
||||||
password="kobuki",
|
|
||||||
database="kobuki")
|
|
||||||
|
|
||||||
cnx.close()
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
||||||
|
@app.route('/control', methods=["GET", "POST"])
|
||||||
@app.route('/control', methods=["GET","POST"])
|
|
||||||
def control():
|
def control():
|
||||||
if request.authorization and request.authorization.username == 'ishak' and request.authorization.password == 'kobuki':
|
if request.authorization and request.authorization.username == 'ishak' and request.authorization.password == 'kobuki':
|
||||||
return render_template('control.html')
|
return render_template('control.html')
|
||||||
@@ -47,15 +36,10 @@ def move():
|
|||||||
|
|
||||||
# Verstuur de richting via MQTT
|
# Verstuur de richting via MQTT
|
||||||
if direction:
|
if direction:
|
||||||
mqtt_client.publish("home/commands", direction) # Het topic kan aangepast worden
|
mqtt_client.publish("home/commands", direction)
|
||||||
|
|
||||||
return jsonify({"status": "success", "direction": direction})
|
return jsonify({"status": "success", "direction": direction})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/data', methods=['GET'])
|
|
||||||
def data():
|
|
||||||
return kobuki_message
|
|
||||||
|
|
||||||
@app.route('/phpmyadmin/<path:path>')
|
@app.route('/phpmyadmin/<path:path>')
|
||||||
def phpmyadmin_passthrough(path):
|
def phpmyadmin_passthrough(path):
|
||||||
# Laat Apache deze route direct afhandelen
|
# Laat Apache deze route direct afhandelen
|
||||||
@@ -64,16 +48,22 @@ def phpmyadmin_passthrough(path):
|
|||||||
@app.route("/database")
|
@app.route("/database")
|
||||||
def database():
|
def database():
|
||||||
try:
|
try:
|
||||||
with cnx.cursor() as cur:
|
cnx = mysql.connector.connect(
|
||||||
cur.execute("SELECT DATABASE()")
|
host="127.0.0.1",
|
||||||
rows = cur.fetchall() # Haal alle rijen op uit het resultaat
|
port=3306,
|
||||||
|
user="admin",
|
||||||
|
password="kobuki",
|
||||||
|
database="kobuki"
|
||||||
|
)
|
||||||
|
cursor = cnx.cursor()
|
||||||
|
cursor.execute("SELECT * FROM kobuki_data")
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
cursor.close()
|
||||||
|
cnx.close()
|
||||||
return str(rows)
|
return str(rows)
|
||||||
except Exception as e:
|
except mysql.connector.Error as err:
|
||||||
print(f"Database error: {e}")
|
print(f"Database error: {err}")
|
||||||
return "je hebt iets fout gedaan.", 500
|
return f"Database error: {err}", 500
|
||||||
|
|
||||||
def add_command(command):
|
|
||||||
command_query = "INSERT INTO kobuki (command) VALUES ();"
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, port=5000)
|
app.run(debug=True, port=5000)
|
Reference in New Issue
Block a user