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 AM2302/DHT22 device, that provides calibrated digital signal output of the temperature and humidity. The ESP32 module can be programmed to read temperature and humidity from the AM2302 device and then POSTs the temperature and humidity values towards an external web server, where data are stored and showed by a script. In this experiment a PHP script is used in the web server. In order to reduce power usage, the ESP32 sleeps between two consecutive measurements. Hardware set-up
Following hardware is required to build the experiment:
Confused about all three-letters acronyms? Here is a brief explanation: GND is the ground line, Vcc/Vdd is the positive supply line, SDA is the serial data line, GPIO is generic purpose Input/Output. The following picture shows the IoT device breadboard: 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 value and the web server name, then connect your ESP module to your computer using a USB cable and upload the sketch. Server side software
Information is received by the server in a POST request. The information is encoded in JSON format, including a secret value used to check that the information is really sent by the IoT device. The received information is stored in MySQL database after security check.
The main part of the functionality is provided by the esp32_post.php script, change the secret value and mysql credentials and then upload it to your webserver.
|