This project shows how I connected an ESP32 with MQTT, saved the data in InfluxDB, and used Flask to make a small web page for control and charts.
Authors: Majid Hosseinia & Parinaz Moeini
- ESP32 firmware (WiFi + MQTT via PubSubClient)
- Python backend (Flask) with InfluxDB 2.x client and MQTT publisher/subscriber
- Simple HTML template for front-end controls
- Data analysis helpers (Pandas/Numpy)
- Ready-to-fork repo with MIT license,
.gitignore
,requirements.txt
, and.env.example
. ├── codes/ │ ├── analyse.py # script for analyzing sensor data │ ├── conection.py # Flask + MQTT + InfluxDB backend │ └── templates/ │ └── index.html # web UI template ├── sketch_feb10a.ino # Arduino sketch for ESP32 ├── requirements.txt # Python dependencies ├── .env.example # example env vars (no secrets) ├── LICENSE # MIT license ├── CONTRIBUTING.md # contribution guidelines └── README.md # main documentation
Python 3.10+, InfluxDB 2.x, MQTT broker (like Mosquitto), Arduino IDE with ESP32.
-
Clone & create environment
git clone <your-fork-url>.git iot-project cd iot-project python -m venv .venv source .\.venv\Scripts\Activate.bat pip install -r requirements.txt cp .env.example .env
-
Configure environment
- Edit
.env
with your InfluxDB URL, token, org, and bucket. - Set your MQTT broker host/port/topic.
- Edit
-
Run the Flask app
export FLASK_APP=codes/conection.py # Windows: set FLASK_APP=codes/conection.py python codes/conection.py
The app runs on
http://localhost:5000
by default. -
InfluxDB setup
- Create an organization and bucket named in your
.env
(or change.env
). - Generate a read/write API token.
- Create an organization and bucket named in your
-
ESP32 firmware
- Open
sketch_feb10a.ino
in Arduino IDE. - Install libraries: WiFi, PubSubClient.
- Update WiFi SSID/password and MQTT broker settings in the sketch.
- Upload to your ESP32.
- Open
-
(Optional) Analysis
- Use
codes/analyse.py
as a starting point to query data from InfluxDB using Flux and analyze with Pandas/Numpy.
- Use
Don’t put real tokens in your code.
I use a .env
file for more safety.
-
Initialize git and make the first commit
git init git add . git commit -m "feat: initial public repo (Flask + ESP32 + InfluxDB)"
-
Create a new GitHub repository (on github.com) named, for example,
iot-project
. -
Add the remote and push
git branch -M main git remote add origin https://github.com/<your-username>/iot-project.git git push -u origin main
This project is licensed under the MIT License.
© 2025 Majid Hosseinia & Parinaz Moeini