DH11 connected to NodeMCU ESP8266, problems uploading to board

What I am trying to do is load IDE code on a NodeMCU board to get data from the connected DH11 sensor. Sounds simple! It works on an UNO board.

I have been struggling for days to transfer a simple project from an Uno board to a NodeMCU esp8266 board as I want to eventually get the data on Home Assistant through the local network but one thing at a time....
The code wont load to the NodeMCU, I suspect it has to do with the included libraries but I have tried a whole range of DHT and ESP8266 libraries and not had any joy. The error code at the moment is "Error compiling for board...." but I have also had "DHT does not name a type" before.

#include <ESP8266WiFi.h>
#include <PietteTech_DHT.h>

#include "dht.h"
#define dht_apin 5 // Analog Pin sensor is connected to
dht DHT;

void setup()
{
  
  Serial.begin(9600);
  delay(500);//Delay to let system boot
  Serial.println("DHT11 Humidity & temperature Sensor\n\n");
  delay(1000);//Wait before accessing Sensor
}
 
void loop()
{
    DHT.read11(dht_apin);
    
    Serial.print("Current humidity = ");
    Serial.print(DHT.humidity);
    Serial.print("%  ");
    Serial.print("Temperature = ");
    Serial.print(DHT.temperature); 
    Serial.println("C  ");

    delay(5000);//Wait 5 seconds before accessing sensor again.
 
  //Fastest should be once every two seconds.
 
}// end loop()

I would very much appreciate any suggestions or help with this.

Please post the entire text of the error messages for the code that you post.

Thanks g. Sorry, I really should have included the full error msg in my orignal post I know. Bad form but it exceeded the maximum characters allowed so I've attached it as an attachment this time

attachment won't attach and the message is too long if I copy and paste it. It's not really working out for me this.....
below is the beginning and end of the error msg

""
Arduino: 1.8.2 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)"

...

from C:\Users\Dieter\Documents\Arduino\libraries\DHTLib\dht.cpp:30:

C:\Users\Dieter\Documents\Arduino\libraries\DHTLib\dht.cpp: In member function 'int dht::_readSensor(uint8_t, uint8_t)':

C:\Users\Dieter\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/Arduino.h:226:63: error: cannot convert 'volatile uint32_t* {aka volatile unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in initialization

#define portInputRegister(port) ((volatile uint32_t*) &GPI)

^

C:\Users\Dieter\Documents\Arduino\libraries\DHTLib\dht.cpp:116:29: note: in expansion of macro 'portInputRegister'

volatile uint8_t *PIR = portInputRegister(port);

^

Using library ESP8266WiFi at version 1.0 in folder: C:\Users\Dieter\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi
Using library PietteTech_DHT-8266-master at version 0.3.1 in folder: C:\Users\Dieter\Documents\Arduino\libraries\PietteTech_DHT-8266-master
Using library DHTLib in folder: C:\Users\Dieter\Documents\Arduino\libraries\DHTLib (legacy)
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
""

I quit using DHT11 sensors years ago. They are slow and not very accurate, in my experience. I do have a DHT22 and so wired one up to an ESP8266-12. I used a library originally written by Adafruit that I slightly modified to get dewpoint (attached zip). Place the unzipped DHT folder in your sketchbook libraries folder. The following code was uploaded and runs successfully. DHT22 wired as follows: 3.3V to Vdd, data to pin GPIO5 (next to the TX pin on my board), and GND to ESP GND. You should be able to just change the DHTTYPE DHT22 to DHTTYPE DHT11 to run with your sensor. Hope that this will get you going.

#include <DHT.h>

const byte dhtPin = 5;
#define DHTTYPE DHT22
DHT dht(dhtPin, DHTTYPE);

float temp, tempf, humi;

void setup() 
{
  dht.begin();
  Serial.begin(115200);
}

void loop()
{
  if(getTH() == true)
  {
    Serial.print("Temp  = ");
    Serial.print(tempf);
    Serial.print(" Deg F  ");
    Serial.print("  Humidity  = ");
    Serial.print(humi);
    Serial.println(" %RH");
  }

}

boolean getTH()
{
  static unsigned long timer = 0;
  unsigned long interval = 5000;

  if (millis() - timer > interval)
  {
    timer = millis();   
    humi = dht.readHumidity();
    temp = dht.readTemperature();
    tempf =  dht.readTemperature(true);
    if (isnan(humi) || isnan(temp) || isnan(tempf))
    {
      Serial.println("Failed to read from DHT sensor!");      
      return false;
    }
    return true;
  }
  else
  {
    return false;
  }
}

DHT.zip (6.43 KB)

I agree the DHT11 are a bit iffy. I have two running at the moment and the readings differ by 4'C. I have ordered some DHT22's.

Thank you for the library and code it works on the board, hurray!
I will spend some time to try and disect what you've coded to see if I can understand and maybe learn a little bit more.

Again thank you so much for taking the time to knock up that code for me, I really appreciate it.
Very frustrating this coding stuff, I can piss away hours in front of the computer getting nowhere and you come along and bang out some code in a few minutes!

I am glad that it worked for you. I will be happy to help you understand the code where you have trouble.