Compilation error: 'dht' does not name a type; did you mean 'id_t'?
Seseems the "dht" library has been changed to dhtnew"
C:\Users\smith\AppData\Local\Temp\.arduinoIDE-unsaved2026010-19952-18o3fm6.ayoai\sketch_jan10b\sketch_jan10b.ino:26:1: error: 'dht' does not name a type; did you mean 'id_t'? dht DHT; ^~~ id_t C:\Users\smith\AppData\Local\Temp\.arduinoIDE-unsaved2026010-19952-18o3fm6.ayoai\sketch_jan10b\sketch_jan10b.ino: In function 'void loop()': C:\Users\smith\AppData\Local\Temp\.arduinoIDE-unsaved2026010-19952-18o3fm6.ayoai\sketch_jan10b\sketch_jan10b.ino:130:20: error: 'DHT' was not declared in this scope int readData = DHT.read22(DHTPIN); // Reads the data from the sensor ^~~ C:\Users\smith\AppData\Local\Temp\.arduinoIDE-unsaved2026010-19952-18o3fm6.ayoai\sketch_jan10b\sketch_jan10b.ino:130:20: note: suggested alternative: 'DWT' int readData = DHT.read22(DHTPIN); // Reads the data from the sensor ^~~ DWT exit status 1 Compilation error: 'dht' does not name a type; did you mean 'id_t'?
AAAny idea on how to fix this
There's not enough information for a definitive diagnosis here. You should post the code being compiled. There's more than one DHT library. Which one (and version) are you using?
So I have to speculate. I think you're using the Adafruit DHT Sensor Library. The current version is 1.4.6.
The compiler error, "'dht' does not name a type" is in reference to the declaration
dht DHT;
The Adafruit library defines the type DHT, so this declaration is invalid. It looks like is should be
DHT dht;
This defines the variable dht that is of type DHT
The DHT constructor requires parameters that specify the sensor pin and the sensor type. These are missing and I can't supply them. So this definition should fail to compile but at least it has the order correct.
The subsequent errors are related to the defective variable declaration that use the type name DHT to access the member functions rather than the variable.
The one who has the most fun, wins!
Many thanks for looking at this, code follows: Using Library DHTlib by Rob Tillaart
/*
LoRa Multi-Sensor Temperature & Humidity Monitor - Sensor
lora-temp-humid-sensor.ino
Remote Node for LoRa Temperature and Humidity Monitor
Uses Arduino Uno, Adafruit RFM9x LoRa Module & DHT22 Temp/Humid sensor
Sends Temperature and Humidity data to central controller
Requires LoRa Library by Sandeep Mistry - https://github.com/sandeepmistry/arduino-LoRa
Requires DHTlib Library by Rob Tillaart
DroneBot Workshop 2023
https://dronebotworkshop.com
*/
// Include required libraries
#include <SPI.h>
#include <LoRa.h>
#include <dht.h>
// DHT22 Connection
#define DHTPIN 9
// LED connection (if used)
const int ledPin = 5;
// DHT Temp/Humid sensor object
dht DHT;
// Define the pins used by the LoRa module
const int csPin = 4; // LoRa radio chip select
const int resetPin = 2; // LoRa radio reset
const int irqPin = 3; // Must be a hardware interrupt pin
// Outgoing message variable
String outMessage;
// Controller data variable
String inMessage;
// Previous value Controller data variable
String inMessageOld;
// Outgoing Message counter
byte msgCount = 0;
// Source and destination addresses
byte localAddress = 0xAA; // address of this device (must be unique, 0xAA or 0xBB)
byte destination = 0x01; // destination to send to (controller = 0x01)
// Receive Callback Function
void onReceive(int packetSize) {
if (packetSize == 0) return; // if there's no packet, return
// Read packet header bytes:
int recipient = LoRa.read(); // recipient address
byte sender = LoRa.read(); // sender address
byte incomingMsgId = LoRa.read(); // incoming msg ID
byte incomingLength = LoRa.read(); // incoming msg length
String incoming = ""; // payload of packet
while (LoRa.available()) { // can't use readString() in callback, so
incoming += (char)LoRa.read(); // add bytes one by one
}
if (incomingLength != incoming.length()) { // check length for error
Serial.println("error: message length does not match length");
return; // skip rest of function
}
// If the recipient isn't this device or broadcast,
if (recipient != localAddress && recipient != 0xFF) {
Serial.println("This message is not for me.");
return; // skip rest of function
}
// If we are this far then this message is for us
// Update the controller data variable
inMessage = incoming;
}
// Send LoRa Packet
Many thanks for looking at this, code follows: Using Library DHTlib by Rob Tillaart
Aha! Now everything makes sense!
You're reproducing the project from Bill's article "LoRa – Long-Range Radio for IoT | Arduino, ESP32, RPI Pico." Specifically, "11.4 Remote Sensor Sketch (Arduino Uno & DHT22" and the sketch lora-temp-humid-sensor.ino. The article states the sketch uses DHTLib by Rob Tillaart, which you need to install.
The good news is that project still successfully compiles.
But then (through some nefarious means) you discover a note,
For latest version for the DHT, check https://github.com/RobTillaart/DHTNEW
and, throwing caution to the winds, decide to install DHTNEW instead of DHTLib...
...with predictable results.
This is a library update, and the Good News is it isn't too difficult, but is disruptive.
The header, class name, and the API's changed. But it isn't as bad as it sounds at least to get the code to compile again.
You need to change the header name
// Include required libraries #include < SPI.h> #include < LoRa.h> #include < dhtnew.h> // update: library header //...
Then change object definition
// DHT Temp/Humid sensor object //dht DHT; DHTNEW DHT(DHTPIN); // update: new class; ctor
The ctor now requires the pin number.
Then you have to use the new API's
void loop() {
// Run only if requested
if (inMessage != inMessageOld) {
// New message variable, take reading and send to controller
//int readData = DHT.read22(DHTPIN); // Reads the data from the sensor
int readData = DHT.read(); // update: API change; Reads the data from the sensor
//float t = DHT.temperature; // Gets the values of the temperature
float t = DHT.getTemperature(); // update: API change; Gets the values of the temperature
//float h = DHT.humidity; // Gets the values of the humidity
float h = DHT.getHumidity(); // update: API change; Gets the values of the humidity
//...
}
}
That's all I needed to do to get the code to compile again.
I do not know if it still works. That's for you to determine.
I've attached my copy of the modified sketch.
Good Luck!
The one who has the most fun, wins!
AI Addendum: CoPilot
Because we live on the cutting edge of technology, let's give CoPilot a shot at the update.
Query: "In the sketch lora-temp-humid-sensor.ino, how can I upgrade the library from DHTLib to DHTNEW?"
CoPilot:
Install the DHTNEW library (Library Manager or clone https://github.com/RobTillaart/DHTNEW /a>), remove/disable the old DHTLib to avoid conflicts, then update the sketch: change the include, construct the new DHTNEW object with the pin, and use the new APIs (read(), getTemperature(), getHumidity()).
// Replace old include #include < dhtnew.h> // from DHTNEW library // DHT Temp/Humid sensor object DHTNEW DHT(DHTPIN); // DHTNEW ctor takes the pin (and possibly sensor type in newer versions) // ... later in loop() //int readData = DHT.read22(DHTPIN); // old DHTLib API int readData = DHT.read(); // DHTNEW: read() reads sensor //float t = DHT.temperature; // old API float t = DHT.getTemperature(); // DHTNEW API //float h = DHT.humidity; // old API float h = DHT.getHumidity(); // DHTNEW API
Gotcha: DHTNEW's header/case and constructor signature can vary by version — check the library's README for exact header name and whether you must pass a sensor-type constant (e.g., DHT22) to the constructor.
Not bad, sez me. I need to use CoPilot more often.
The one who has the most fun, wins!