File size: 793 Bytes
b31bfd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376e1cc
69408aa
b31bfd8
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
from flask import Flask, render_template
from flask_socketio import SocketIO, emit

app = Flask(__name__)
socketio = SocketIO(app)

# WebSocket route for receiving data from Arduino
@socketio.on('message')
def handle_message(data):
    print(f"Received from Arduino: {data}")
    # Process the data here, or broadcast it to clients if necessary
    emit('response', {'status': 'success', 'message': 'Data received'})

# WebSocket event for a new client connecting
@socketio.on('connect')
def handle_connect():
    print("Client connected.")

# Home route (optional for testing purposes)
@app.route('/')
def index():
    return render_template('index.html')

# Run the Flask app with WebSocket support
if __name__ == '__main__':
    print("server is running")
    socketio.run(app, debug=True)