Measure temperature and umidity
Even the powerful ESP32 module itself is not able to provide information like temperature and humidity. Specific sensors are needed to read physical properties. This example uses the BME280 device, that provides calibrated digital signal output of the temperature, pression and humidity. The ESP32 module can be programmed to read temperature, pression and humidity from the BME280 device and then publish temperature, pression and humidity values towards an MQTT broker. In order to reduce power usage, the ESP32 sleeps between two consecutive measurements. The following topics are published by this experiment:
Hardware set-up
Following hardware is required to build the experiment:
ESP32 software
Before writing software make sure to have installed the software development environment, downlodable from Arduino Software web site. It may be needed to download some library if not already present. Libraries are required also to manage the external devices. The sketch has to include the required libraries:
The setup() function performs all the logic for the IoT sensor and then it goes to sleep.
In this example the loop() function is not used. Download the complete sketch here, change the secret values and the MQTT broker address and deploy it on ESP32 board. Testing the measurement device
After succesful deployment of software on ESP32 board, assuming that you have installed Mosquitto on your preferred platform, e.g. Raspberry PI, you can use the following commands to subscribe each parameter:
You can also subscribe to all measurements together by executing the following command:
|