Spaces:
Runtime error
Runtime error
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 | |
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 | |
def handle_connect(): | |
print("Client connected.") | |
# Home route (optional for testing purposes) | |
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) | |