This project simulates an ESP device using Flask and MQTT. It allows you to:
- Publish simulated motor responses and sensor data to MQTT topics
- Subscribe to MQTT topics via HTTP endpoints
- Python 3.8+
- MQTT broker (e.g., Mosquitto, EMQX)
- See
requirements.txtfor Python dependencies
- Install dependencies:
pip install -r requirements.txt
- Create a
.envfile in the project root with the following variables:MQTT_BROKER=your_mqtt_broker_url MQTT_PORT=8883 ESP_TOKEN=your_esp_token APPLICATION_RUNNING_PORT=5005
Start the Flask server:
python app.py-
POST /publish-motor-response
Publish a motor response to a topic.
Body:{ "motor_response": {...}, "topic": "your/topic" } -
POST /publish-realtime-sensor-data
Publish simulated sensor data.
Body:{ "espId": "...", "userId": "...", "topic": "your/topic" } -
POST /subscribe
Subscribe to MQTT topics.
Body:{ "topics": ["topic1", "topic2"] }
- Uses TLS for MQTT (insecure, for development only)
- Prints MQTT events to the console