DHT22 problem with Ethernet Shield

Hello all,

I have a code that works fine that just displays the value on the screen of a DHT22 every x seconds. When I try to integrate it with the Ethernet library, the sensor stops working after a few seconds and fails to read data. I’ll post both codes below. The first one doesn’t work, even though the second one works perfectly. It might be worth mentioning that this ONLY happens with this sensor. I have a luminosity sensor for example, that works completely fine in both scenarios.

#include <SPI.h>
#include <Ethernet.h>
#include <DHT.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192,168,0,940);
EthernetClient client;
char serveur[] = "chatocn.000webhostapp.com";

char carlu = 0;
long derniereRequete = 0;
const long updateInterval = 2000;
bool etaitConnecte = false;

#define DHTPIN 10
#define DHTTYPE DHT22 
DHT dht(DHTPIN, DHTTYPE); 

void setup() {
  Serial.begin(9600);
  dht.begin();
  char erreur = 0;
  erreur = Ethernet.begin(mac);
  if (erreur == 1){
    Serial.println("Deu certo setup");
  }
  if (erreur == 0) {
    Serial.println("Parametrage avec ip fixe...");
    Ethernet.begin(mac, ip);
  }
  Serial.println("Init...");
  delay(1000);
  Serial.println("Pret !");
}

void loop()
{  delay(500);
    while(client.available()) {
    carlu = client.read();
    Serial.print(carlu);
  }
  if (etaitConnecte && !client.connected()) {
    Serial.println();
    Serial.println("Deconnexion !");
    // On ferme le client
    client.stop();
  }
  if(!client.connected() && ((millis() - derniereRequete) > updateInterval)) {
    Serial.println("entrou");
    requete();
  }
  etaitConnecte = client.connected();
}

void requete() {
  Serial.println("antes");
  char erreur = client.connect(serveur, 80);
  Serial.println(erreur);
  if(erreur == 1) {
      Serial.println("Connexion OK, envoi en cours...");
      client.print("GET /arduino.php?");
      client.print("temperature="); 
      client.print(getTemp("c")); 
      client.println(" HTTP/1.1");
      client.println("Host: chatocn.000webhostapp.com");
      client.println("Connection: close");
      client.println();
      
      derniereRequete = millis();
  } else {
    client.stop();
    Serial.println("Echec de la connexion");
    switch(erreur) {
      case(-1):
        Serial.println("Time out");
        break;
      case(-2):
        Serial.println("Serveur invalide");
        break;
      case(-3):
        Serial.println("Tronque");
        break;
      case(-4):
        Serial.println("Reponse invalide");
        break;
    }
  }
}

float getTemp(String req)
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);
  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // Compute heat index in Kelvin 
  float k = t + 273.15;
  if(req =="c"){
    return t;//return Cilsus
  }else if(req =="f"){
    return f;// return Fahrenheit
  }else if(req =="h"){
    return h;// return humidity
  }else if(req =="hif"){
    return hif;// return heat index in Fahrenheit
  }else if(req =="hic"){
    return hic;// return heat index in Cilsus
  }else if(req =="k"){
    return k;// return temprature in Kelvin
  }else{
    return 0.000;// if no reqest found, retun 0.000
  }
 
}

Code that works perfectly:

#include "DHT.h"
#define DHTPIN 10
#define DHTTYPE DHT22 
DHT dht(DHTPIN, DHTTYPE); 

void setup() {

  Serial.begin(9600);
  dht.begin();


}

void loop() {

  delay(500);
  Serial.println(getTemp("c"));
}

float getTemp(String req)
{

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // Compute heat index in Kelvin 
  float k = t + 273.15;
  if(req =="c"){
    return t;//return Cilsus
  }else if(req =="f"){
    return f;// return Fahrenheit
  }else if(req =="h"){
    return h;// return humidity
  }else if(req =="hif"){
    return hif;// return heat index in Fahrenheit
  }else if(req =="hic"){
    return hic;// return heat index in Cilsus
  }else if(req =="k"){
    return k;// return temprature in Kelvin
  }else{
    return 0.000;// if no reqest found, retun 0.000
  }
 
}

Instead of continuing the loop as expected, the code with the Ethernet fails to read the data when asked to upload it to the server. This is the output: (it gives an error and freezes the program on the next loop)

18:21:09.687 -> Deu certo setup
18:21:09.687 -> Init...
18:21:10.675 -> Pret !
18:21:11.181 -> entrou
18:21:11.181 -> antes
18:21:11.498 -> 
18:21:11.498 -> Connexion OK, envoi en cours...
18:21:11.752 -> Failed to read from DHT sensor!
18:21:13.769 -> entrou
18:21:13.769 -> antes

The Ethernet shield uses pin 10 for its chip select pin. Please use a different pin for your DHT22.

I cannot believe something so simple took me so long to fix... Thank you so much, I really should read the documentation of the hardware I'm using.

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per