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"
|
||||
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"))
|
||||
print(kobuki_message)
|
||||
|
||||
@@ -16,24 +16,13 @@ mqtt_client.username_pw_set("server", "serverwachtwoordofzo")
|
||||
mqtt_client.connect("localhost", 80, 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
|
||||
|
||||
|
||||
cnx = mysql.connector.connect(
|
||||
host="127.0.0.1",
|
||||
port=3306,
|
||||
user="admin",
|
||||
password="kobuki",
|
||||
database="kobuki")
|
||||
|
||||
cnx.close()
|
||||
mqtt_client.on_message = on_message
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
@app.route('/control', methods=["GET","POST"])
|
||||
@app.route('/control', methods=["GET", "POST"])
|
||||
def control():
|
||||
if request.authorization and request.authorization.username == 'ishak' and request.authorization.password == 'kobuki':
|
||||
return render_template('control.html')
|
||||
@@ -47,15 +36,10 @@ def move():
|
||||
|
||||
# Verstuur de richting via MQTT
|
||||
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})
|
||||
|
||||
|
||||
@app.route('/data', methods=['GET'])
|
||||
def data():
|
||||
return kobuki_message
|
||||
|
||||
@app.route('/phpmyadmin/<path:path>')
|
||||
def phpmyadmin_passthrough(path):
|
||||
# Laat Apache deze route direct afhandelen
|
||||
@@ -64,16 +48,22 @@ def phpmyadmin_passthrough(path):
|
||||
@app.route("/database")
|
||||
def database():
|
||||
try:
|
||||
with cnx.cursor() as cur:
|
||||
cur.execute("SELECT DATABASE()")
|
||||
rows = cur.fetchall() # Haal alle rijen op uit het resultaat
|
||||
cnx = mysql.connector.connect(
|
||||
host="127.0.0.1",
|
||||
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)
|
||||
except Exception as e:
|
||||
print(f"Database error: {e}")
|
||||
return "je hebt iets fout gedaan.", 500
|
||||
|
||||
def add_command(command):
|
||||
command_query = "INSERT INTO kobuki (command) VALUES ();"
|
||||
except mysql.connector.Error as err:
|
||||
print(f"Database error: {err}")
|
||||
return f"Database error: {err}", 500
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, port=5000)
|
||||
app.run(debug=True, port=5000)
|
Reference in New Issue
Block a user