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)