-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
56 lines (40 loc) · 1.37 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
# Import necessary libraries
from flask import request, jsonify
# ... Your existing code ...
# Flask route to handle window control
@app.route('/control', methods=['POST'])
def control_window():
direction = request.form.get('direction')
if direction == 'open':
look_around2() # Call your existing function for opening the window
elif direction == 'close':
look_around() # Call your existing function for closing the window
return jsonify({'status': 'success'})
# Start the Flask app
if __name__ == '__main__':
app.run(debug=True)
# ... Your existing code ...
# MQTT message handling
def message_arrived(topic, msg):
print("[INFO] {}{}".format(topic, msg))
if topic == b'udemedellin/dexteram':
if msg == b'1':
print("[INFO] ad dextram")
look_around2() # Open the window
elif topic == b'udemedellin/sinistram':
if msg == b'1':
print("[INFO] ad sinistram")
look_around() # Close the window
elif topic == b'udemedellin/declinemus':
if msg == b'1':
print("[INFO] ut declinemus")
apagado()
# Add more conditions as needed
# ... Your existing code ...
if __name__ == '__main__':
app.run(debug=True)