👨💻 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_SSID
andWIFI_PASSWORD
constants insrc/main.cpp
with your WiFi credentials.
- Update the
-
MQTT Configuration:
- Update the
MQTT_HOST
,MQTT_USER
, andMQTT_PASWORD
constants insrc/main.cpp
with your MQTT broker details. - Ensure the
MQTT_PORT
is correctly set to your MQTT broker's port (default is 1883).
- Update the
-
Pin Configuration:
- Verify the
SDA_PIN
andSCL_PIN
constants insrc/main.cpp
match your hardware setup. - The
LED_PIN
is set to pin 2 by default.
- Verify the
-
Build and Upload the Code:
- Connect your ESP32 to your computer.
- Click the
PlatformIO: Upload
button 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