Sending DHT11 Sensor Data to Consentium IoT Cloud
This documentation explains how to read data from a DHT11 sensor using an digital pin and send the data to the Consentium IoT cloud using the ConsentiumThings library. The code also facilitates Over-The-Air (OTA) firmware updates for easy firmware management.
Dependencies
The code leverages the ConsentiumThings.h library for communication with the Consentium IoT platform and the DHT.h library for reading data from the DHT11 sensor.
Features
Connect to a WiFi network to send data to the cloud.
Read temperature and humidity from the DHT11 sensor.
Send sensor data to the Consentium IoT platform.
Enable Over-The-Air (OTA) firmware updates.
Automatically check for updates after 100 loop cycles.
Constants
Firmware Version: The firmware version of the board is set to
0.1.Interval: The main loop runs every 5 seconds (5000 ms).
Update Interval: The firmware checks for updates after 100 cycles of the main loop.
Code Overview
1. Initialization
The program begins by creating a ConsentiumThingsDalton object to manage communication with the Consentium IoT platform. The initialization requires the firmware version, WiFi credentials, and API keys.
The following variables are set for WiFi credentials and API keys (hidden for security):
Additionally, a DHT object is initialized to interface with the DHT11 sensor:
2. Setup
The setup() function initializes the WiFi connection, data transmission, OTA updates, and the DHT11 sensor.
3. Main Loop
The loop() function reads the temperature and humidity from the DHT11 sensor, and then sends this data to the Consentium IoT platform.
a. Reading Data from DHT11
The temperature and humidity values are read using the dht.readTemperature() and dht.readHumidity() functions.
b. Sending Sensor Data
The temperature and humidity data are sent to the Consentium IoT cloud using the sendData function. The code is designed to handle multiple sensor values.
c. OTA Updates
The firmware checks for available updates every 100 cycles. If an update is available, it will automatically perform the update.
4. Loop Control
The loop repeats every 5000 milliseconds (5 seconds), allowing for periodic data sending and firmware update checks.
Error Handling
If the sensor fails to read valid data, you can add error checking to ensure the system handles faulty sensor readings gracefully.
6. Final code
Summary
This code reads temperature and humidity data from a DHT11 sensor and sends it to the Consentium IoT cloud for monitoring. The system also checks for OTA updates, ensuring the firmware remains up-to-date. The design is flexible, allowing for multiple sensors to be added easily.
Last updated
Was this helpful?