To build a weather station, we need environmental sensors. In Chapter 2, Making Visual Data and Animation on an LCD, we learned how to retrieve temperature and humidity from a DHT22 module, and displayed this in the LCD.
To work with DHT22, we declare a DHT module type and its GPIO pin on ESP32:
#include <dht.h>
static const dht_sensor_type_t sensor_type = DHT_TYPE_DHT22;
static const gpio_num_t dht_gpio = 26;
We can obtain the temperature and humidity from DHT22, and we can call the dht_read_data() function by passing temperature and humidity variables, as follows:
int16_t temperature = 0;
int16_t humidity = 0;
dht_read_data(sensor_type, dht_gpio, &humidity, &temperature);
Next, we will implement a weather station with ESP32.