👨💻 Author: bgramaje
This project collects environmental data using the ENS160 and AHT21 sensors and publishes the data to an MQTT broker. It also uses NTP for timestamping the data.
- ESP32 or compatible microcontroller
- ENS160 sensor
- AHT21 sensor
- WiFi network
- PlatformIO IDE with VSCode
- MQTT broker, here mosquitto is the one used.
-
Clone this Repository:
- Clone or download this repository.
-
Install Dependencies:
- Open the cloned project in PlatformIO IDE.
- PlatformIO should automatically install the required libraries defined in
platformio.ini.
-
WiFi Configuration:
- Update the
WIFI_SSIDandWIFI_PASSWORDconstants insrc/main.cppwith your WiFi credentials.
- Update the
-
MQTT Configuration:
- Update the
MQTT_HOST,MQTT_USER, andMQTT_PASWORDconstants insrc/main.cppwith your MQTT broker details. - Ensure the
MQTT_PORTis correctly set to your MQTT broker's port (default is 1883).
- Update the
-
Pin Configuration:
- Verify the
SDA_PINandSCL_PINconstants insrc/main.cppmatch your hardware setup. - The
LED_PINis set to pin 2 by default.
- Verify the
-
Build and Upload the Code:
- Connect your ESP32 to your computer.
- Click the
PlatformIO: Uploadbutton in the PlatformIO IDE to compile and upload the code.
-
Monitor Serial Output:
- Open the Serial Monitor in PlatformIO IDE.
- You should see debug output indicating the status of the WiFi connection, MQTT connection, and sensor readings.
- MQTT Data:
- The sensor data is published to the MQTT broker under the topic
sensors/<MAC_ADDRESS>, where<MAC_ADDRESS>is the MAC address of your ESP32 without colons.
- The sensor data is published to the MQTT broker under the topic


