|
Post by papa on Oct 27, 2022 18:49:44 GMT
ESP32 Node + DHT (Temp-Humidity) Sensor
Needed besides the ESP32 board:
A DHT Sensor: an individual DHT11 or DHT22 or either on a breakout board. The DHT22 sensor has a better resolution & a wider temperature & humidity measurement range. The DHT11 has a smaller range & is less accurate. It’s also cheaper. The DHT11 is probably adequate for most uses. That's what I use so far. An individual sensor has 4 pins & a breakout board has only 3.
Planning: Make your ESP32 pin choices & your connection choices based on your ESP32 board & the following.
Ways to connect ESP32 pins to the sensor's 3 male pins: 1) Solder at least 1.5 inches of color coded insulated wire to the 3 used DHT pins, bare the wire ends & plug into female headers on ESP32 board. OR 2) from the shortest male to female dupont cable, remove the plastic end of the female side. Put some heat shrink tubing on the cable. Crimp a dupont female end onto a DHT pin. Move the heat shrink tubing over the crimped female end/DHT pin. Shrink the tubing with heat. Method 1 creates a more compact node. Method 2 allows more distance between ESP32 pins used. I used method 1 & as shown below, I chose 3 pins near each other on my HiLetgo OLED ESP32 board. For me, powering the sensor with ESP32 pin 13 worked better than with a 3.3v pin
<< Click on pic for larger view.
Use the following as hints to connecting: DHT pin
| Function
| ESP32 pins, General Guide
| ESP32-papa | 1
| Power pin
| 3.3v or GPIO pin as output on high | 13 | 2
| Data
| GPIO pin | 15
| 3
| not used |
|
| 4 | GND | GND | GND
|
The provided software sketch uses ESP32 pin 15 for sensor data & pin 13 to power the sensor . You can change those, but avoid ESP32 pins 6-11 Next, Software & Initial Customization
|
|
|
Post by papa on Oct 27, 2022 18:59:15 GMT
ESP32 DHT Node Software, Initial & Node Customization Use this thread for the latest software & initial customization. Software Customization for DHT Node:
At IDE/tools/Manage Libraries, search for DHT & install Adafruit version
At Arduino IDE/tools/Manage Libraries, search for Adafruit Unified Sensor & install the library with that exact name near list's end
In the software sketch, deactivate #define lines from previous nodes (have // at line's start). Change the nodeId if you have another node with that ID.
// [By comment / uncomment], ACTIVATE ONLY ONE of these two for your Temperature Scale: // #define FAHR // Fahrenheit << remove // to activate this line // #define CELS // Celsius
In the software sketch, find & activate these #define lines (delete // at the start) if needed, change pin assignments: // #define DHTPIN 15 // DHT data pin, uses internal pullup // #define DHTpower 13 // pin to power DHT sensor
// type of DHT sensor. Activate ONLY ONE of these two lines: // #define DHTTYPE DHT11 // #define DHTTYPE DHT22
Upload the customized software to the ESP32 board. Next, Expected results
|
|
|
Post by papa on Oct 27, 2022 19:09:09 GMT
ESP32 DHT Node on HiLetgo OLED ESP32, Expected Results When the upload finishes, open the Arduino IDE Serial Monitor (SM). At the SM's lower right, make sure the SM's baud matches that in the sketch line #define SERIAL_BAUD 115200. It may help to press the ESP32 board's reset button. Then the SM will display boot info from the board.
The SM should show typical Node output (my notes in [ ] ) : Node 36 Version ESP32_nodes_nxxx MQCON 25 DHT 15 pwr 13 Fahr [Node ID #, code version, MQTT indicator is on pin 25, DHT data on pin 15 powered by pin 13 Fahrenheit Connecting to XXX [connecting to WiFi station named in sketch] .... [several dots may show while WiFi is connecting] WiFi connected IP address: 192.168.10.140 [Your IP will differ.]
Connect to MQTT broker...connected topic home/esp_gw/nb/node36/dev99 value:NODE 35 WAKEUP: ESP_36 [wakeup reported via MQTT broker
topic home/esp_gw/nb/node36/dev02 value:-66 [Radio Signal strength device 2, closer to zero the better] topic home/esp_gw/nb/node36/dev10 value:192.168.10.140 [IP device 10] topic home/esp_gw/nb/node36/dev48 value: 73.40 [73.4 degrees Fahrenheit] topic home/esp_gw/nb/node36/dev49 value: 34.00 [34% humidity] OR topic home/esp_gw/nb/node36/dev48 value: 23.00 [23 degrees Celsius]
Next, Configure OpenHAB for a ESP32 DHT Node
|
|
|
Post by papa on Oct 27, 2022 20:04:51 GMT
Create Node36 Channel for a Node's Devices 48 (DHT temp) & 49 (DHT humidity) [Your node ID may differ.]I'm adding a channel to a previously created Thing Node36. To create a different Thing, see here. See this post. We're making a channel for the MQTT topic: home/esp_gw/nb/node36/dev48
Logged in to your openHAB configuration, go to localhost:8080/settings/things/In the listed Things, click Node36. Then click the [channels tab] near the top. Near the bottom, click Add Channel. In the Add Channel Window, fill the fields with configs: Channel identifier Node36Channel48 ^^ arbitrary ? as long as we match it in a linked Item later (see below) Label Node36_Temp ^^ arbitrary ?, make it useful for yourself, but not too long Channel type Number Value ^^ choose type compatible with the device/channel data type MQTT State Topic home/esp_gw/nb/node36/dev48MQTT Command Topic [leave blank] Click [Create] to save your configs Next: Create Node36 Channel for Device 49 (Humidity)
|
|
|
Post by papa on Oct 27, 2022 20:07:31 GMT
Create Node36 Channel for Device 49 (Humidity)
A Node36 with DHT sensor also publishes air humidity (per cent). Configure its channel like the Temperature channel.
In the Add Channel Window, fill the fields with configs:
Channel identifier Node36Channel49 ^^ arbitrary ? as long as we match it in a linked Item (see below)
Label Node36_humidity ^^ arbitrary ?, make it useful for yourself, but not too long
Channel type Number Value ^^ choose type compatible with the device/channel data type
MQTT State Topic home/esp_gw/nb/node36/dev49 << corrected Oct. 28, 2022 MQTT Command Topic [Leave blank]
Click [Create] to save your configs
Next: Create Items to Link to Node36's Channel 48 & 49
|
|
|
Post by papa on Oct 27, 2022 21:19:35 GMT
Create Items to Link to Node36's Channels 48 & 49, My Preference: Text Config File
Remember: Use only one method to create & edit an Item (Dashboard OR .items file) NOT BOTH. This method both creates the Item AND links it to the Node36 Thing's Channel 41. [Your node & Thing may differ.]
In openHAB's items folder (Linux /etc/openhab/items), have an .items file to hold the Item. Mine is called ESP32.items, but the name before the .items tag is up to you. The channels' Item takes the form: [ Your Item's Name & Label could differ.] Number Name "Label [%s]" { channel=" Node36channelUID" } Go to localhost:8080/settings/things/ Click on the listed Node36 Thing Click on the [ channels] tab After the Node36_RSSI channel is a small stacked pages icon. Click on that icon to copy the channel UID Into the Item, paste that channel UID in place of Node36channelUID color-coded above. For example, my channel's UID is mqtt:topic:c08f02ca8d:3f938be488:Node36Channel41
So my Items (your channel UID & perhaps your nodeID for the Item will be different) are
Number Temp_Node36 "Temp_Node36 [%.1f °F]" { channel="mqtt:topic:c08f02ca8d:3f938be488:Node36Channel48" } Number Humidity_Node36 "Node36_Humidity [%d %%]" { channel="mqtt:topic:c08f02ca8d:3f938be488:Node36Channel49" } ^^ corrected Oct. 28, 2022
For display purposes only, go to localhost:8080/settings/items/Temp_Node36 & localhost:8080/settings/items/Humidity_Node36 Look at the field just below the top brightly-colored rectangle. If our Node is programmed & powered, those fields should display the Node36's Temperature & Humidity states.
Next: ESP32 DHT Sensor Node, Correcting Errors & Problems
|
|
|
Post by papa on Oct 28, 2022 22:58:30 GMT
ESP32 DHT Sensor Node, Correcting Errors & ProblemsThe software sketch here has changed to avoid sending Temp & Humidity values with leading spaces. Those don't play well with an openHAB Number Item. In the above posts, see " corrected Oct. 28, 2022" for other necessary changes. Next, Display Node36's DHT Data on HABPanel
|
|
|
Post by papa on Oct 31, 2022 15:42:26 GMT
Display a Node's DHT Data on HABPanelGo to the browser address localhost:8080. At the upper right are two small icons, a pencil & a "page." Hovering the mouse pointer over the pencil shows "Edit Home Page." Over the "page," shows "Other apps." Click on the "Other apps" icon & then click on HABPanel. The browser address becomes " http://localhost:8080/habpanel/" The first time you use HABPanel, click the gear icon at the upper right. At the middle left, click on "Add new dashboard." For the new dashboard, enter a Name, perhaps "Main" & click OK. (I assume Node36 & a dashboard named "Main." Yours may differ.) Hover the mouse pointer over "Main" at the upper left. Click on the small pencil icon (edit dashboard) that appears. At the upper right, click on the [Add Widget] button. In Add Widget, choose Dummy (useful for text). In the new widget window at the upper right, click the 3 stacked dots. Choose Edit. Enter a Name, perhaps Node36temp. In the openHAB Item field, choose the desired Item to link. You can click the drop down icon & scroll down to the Item named Temp_Node36. OR you can enter Temp_Node36 in the search box. Either way, click on the Temp_Node36 Item listed. For the Unit (suffix) field, enter °F or °C. Scroll to the bottom of the Edit Widget Window & click [ Save]. Add another Dummy widget. Edit it. Enter a Name like Node36humid. In the openHAB Item field, choose the related Item like Humidity_Node36 For the Unit (suffix) field enter %. Save.
Click the [Run] button to see "Node36temp" & "Node36humid" widgets in the Main dashboard. If the node is programmed & powered, the DHT temperature & humidity readings should be displayed on the widgets. Note: There is a way to combine the temp & humidity readings in one widget. I may add that later.
|
|