gonium / esp8266-dht22-sensor

MIT License
131 stars 24 forks source link

src/main.cpp:17:17: fatal error: DHT.h: No such file or directory #1

Open lfrancois opened 7 years ago

lfrancois commented 7 years ago

It's my first experience with platformio and with the esp8266 so I am very new to it. When I try to run a platformio run, I got this issue.

ludo@idefix:~/repos/esp8266-dht22-sensor % platformio run                                                                 
[Fri Feb 24 19:31:40 2017] Processing esp01 (targets: upload, platform: espressif, board: esp01, framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------
Warning! Platform `espressif` is deprecated and will be removed in the next release! Please use `espressif8266` instead.
Verbose mode can be enabled via `-v, --verbose` option
Collected 25 compatible libraries
Looking for dependencies...
Library Dependency Graph
|-- <ESP8266WiFi> v1.0
|-- <running-average>
|-- <ESP8266WebServer> v1.0
|   |-- <ESP8266WiFi> v1.0
|-- <ESP8266mDNS>
|   |-- <ESP8266WiFi> v1.0
Compiling .pioenvs/esp01/src/main.o
Archiving .pioenvs/esp01/libFrameworkArduinoVariant.a
Indexing .pioenvs/esp01/libFrameworkArduinoVariant.a
Compiling .pioenvs/esp01/FrameworkArduino/Esp.o
Compiling .pioenvs/esp01/FrameworkArduino/FS.o
Compiling .pioenvs/esp01/FrameworkArduino/HardwareSerial.o
src/main.cpp:17:17: fatal error: DHT.h: No such file or directory
#include <DHT.h>
^
compilation terminated.
*** [.pioenvs/esp01/src/main.o] Error 1
===================================================== [ERROR] Took 10.91 seconds =====================================================
ludo@idefix:~/repos/esp8266-dht22-sensor % 
lfrancois commented 7 years ago

Installing the library doesn't sound to help.

ludo@idefix:~/repos/esp8266-dht22-sensor % platformio lib install "DHT22"                                                 
Library Storage: /Users/ludo/repos/esp8266-dht22-sensor/.piolibdeps
Looking for DHT22 library in registry
Conflict: More than one library has been found by request {"name": "DHT22"}:
[ ID  ] Name            Compatibility        "Authors": Description
--------------------------------------------------------------------------------------------------------------------------------------
[ 115 ] DHT22            arduino, atmelavr    "Ben Adams, Craig Ringer": Digital-output relative humidity & temperature sensor/module DHT22
[ 58  ] DHT22            energia, timsp430    "Eugene Mamin": Digital-output relative humidity & temperature sensor/module DHT22
Automatically chose the first available library (use `--interactive` option to make a choice)
Found: http://platformio.org/lib/show/115/DHT22
LibraryManager: Installing id=115
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
DHT22 @ 837124f0ce has been successfully installed!
ludo@idefix:~/repos/esp8266-dht22-sensor %  

Trying to make progress with these changes


ludo@idefix:~/repos/esp8266-dht22-sensor % git diff                                                                           20:26 #4344
diff --git a/src/main.cpp b/src/main.cpp
index e39cffa..e751794 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,10 +14,10 @@ OneWire ds(ONE_WIRE_BUS);
 #endif

 #ifdef SENSOR_DHT22
-#include <DHT.h>
+#include <DHT22.h>
 #include "../config.h"
 #define DHTPIN  2
-DHT dht(DHTPIN, DHTTYPE, 11); // 11 works fine for ESP8266
+DHT22 dht(DHTPIN); // 11 works fine for ESP8266
 #endif

 MDNSResponder mdns;
@@ -174,8 +174,8 @@ int ICACHE_FLASH_ATTR read_sensors(byte bus_idx, float& temp, float& humidity) {
 #ifdef SENSOR_DHT22 // Read temp&hum from DHT22
                // Reading temperature for humidity takes about 250 milliseconds!
                // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
-               humidity = dht.readHumidity();          // Read humidity (percent)
-               temp = dht.readTemperature(false);     // Read temperature as Celsius
+               humidity = dht.getHumidity();          // Read humidity (percent)
+               temp = dht.getTemperatureC();     // Read temperature as Celsius
 #endif

                //Serial.print("Free heap:");
ludo@idefix:~/repos/esp8266-dht22-sensor %   
lfrancois commented 7 years ago
ludo@idefix:.../esp8266/esp8266-dht22-sensor % git diff      
diff --git a/platformio.ini b/platformio.ini
index 123995e..29f0fe5 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -18,9 +18,10 @@
 # targets = upload

 [env:esp01]
-platform = espressif
+platform = espressif8266
 framework = arduino
 board = esp01
 targets = upload
 # Optimize for binary size
 #build_flags=-Os
+lib_deps = 19
ludo@idefix:.../esp8266/esp8266-dht22-sensor % 
battlezone100 commented 7 years ago

The project works as is, but you need to manually install the right DHT library. I installed this one in the .platformio/lib folder and then it build just fine: https://github.com/adafruit/DHT-sensor-library