srivatsavdamaraju commited on
Commit
b31bfd8
·
verified ·
1 Parent(s): 1ddd346

Create app3.py

Browse files
Files changed (1) hide show
  1. app3.py +26 -0
app3.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template
2
+ from flask_socketio import SocketIO, emit
3
+
4
+ app = Flask(__name__)
5
+ socketio = SocketIO(app)
6
+
7
+ # WebSocket route for receiving data from Arduino
8
+ @socketio.on('message')
9
+ def handle_message(data):
10
+ print(f"Received from Arduino: {data}")
11
+ # Process the data here, or broadcast it to clients if necessary
12
+ emit('response', {'status': 'success', 'message': 'Data received'})
13
+
14
+ # WebSocket event for a new client connecting
15
+ @socketio.on('connect')
16
+ def handle_connect():
17
+ print("Client connected.")
18
+
19
+ # Home route (optional for testing purposes)
20
+ @app.route('/')
21
+ def index():
22
+ return render_template('index.html')
23
+
24
+ # Run the Flask app with WebSocket support
25
+ if __name__ == '__main__':
26
+ socketio.run(app, debug=True)