 
 // functions used internally
 
-//used to set the links at the bottom of the pages (ran at setup and on /setup changes)
+//used to set the links at the bottom of the pages (ran at setup() and on /setup changes)
 void lesliens() {
+  int usesenseur = 0;
+  if (usesenseurdallas == 1) {
+    usesenseur = 1;
+  }
+  if (usesenseurdht == 1) {
+    usesenseur = 1;
+  }
   liens = "<a href=\"/\">Acceuil</a>";
   if (usesenseur == 1) {
     liens += " - <a href=\"/temp\">Temp&eacute;rature</a>";
   }
   liens += " - <a href=\"/version\">Version</a> - <a href=\"/setup\">Setup</a>";
   if (usesenseur == 1) {
-    liens += " - <a href=\"https://thingspeak.com/channels/";
-    liens += thingchanel;
-    liens += "\">Temp stats</a>\n";
+    if (thingchanel != "none") {
+      liens += " - <a href=\"https://thingspeak.com/channels/";
+      liens += thingchanel;
+      liens += "\">Temp stats</a>\n";
+    }
   }
 }
 

// function executed in main loop every minute to update sensors data to thingspeak.com
void latemp() {
  if (thingkey != "none") {
    sensors.requestTemperatures();
    float thetemp = sensors.getTempCByIndex(0);
    char buffer[10];
    String tempC = dtostrf(thetemp, 5, 2, buffer);
    delay(400);
    float t = 0;
    float h = 0;
    int err = SimpleDHTErrSuccess;
    if ((err = dht22.read2(pinDHT22, &t, &h, NULL)) != SimpleDHTErrSuccess) {
      Serial.print("Read DHT22 failed, err=");
      Serial.println(err);
      h = 0;
    }
    if (tempC != "-127.00") {
      if (tempC != "85.00") {
        Serial.print("Envoi de température et humidité: ");
        Serial.print(tempC);
        Serial.print(" - ");
        HTTPClient http;
        String webadd = "http://api.thingspeak.com/update?key=";
        webadd += thingkey;
        webadd += "&field1=";
        webadd += tempC;
        if (h != 0) {
          webadd += "&field2=";
          webadd += h;
          Serial.print(h);
          webadd += "&field3=";
          webadd += t;
        }
        Serial.println("");
        http.begin(webadd);
        int httpCode = http.GET();//Send the request
        if (httpCode > 0) {
          Serial.println("Envoit réussit !");
          tstrouteur = 0;
        } else {
          if (tstrouteur == 10) {
            Serial.println("10 Erreur envoit ! REBOOT !");
            ESP.restart();
          } else {
            Serial.println("!!! Erreur envoit !!!");
            tstrouteur++;
          }
        }
        http.end();   //Close connection
      }
    } else {
      Serial.println("Dallas error !");
    }
  } else {
    Serial.println("Pas de API KEY donc pas d'envoi");
  }
}

// web page for showing sensors data
void handleTemp() {
  sensors.requestTemperatures();
  float latemp = sensors.getTempCByIndex(0);
  delay(250);
  float t = 0;
  float h = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht22.read2(pinDHT22, &t, &h, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("Read DHT22 failed, err=");
    Serial.println(err);
  }
  String addy = server.client().remoteIP().toString();
  String contenu = "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\" class=\"client-nojs\">\n<head>\n";
  contenu += "<meta charset=\"UTF-8\" />\n<title>Quel chaleur</title>\n"
             "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";

    }
    if (lechan == "") {
      ouireset = 3;
    }
  }
  if (ouireset == 1) {
    Serial.println("Réglages changé");
    if (noupass != resetpass) {
      preferences.putString("resetpass", noupass);
      resetpass = noupass;
      Serial.print("NOUVEAU Password : ");
      Serial.println(resetpass);
    }
    if (lakey != thingkey) {
      preferences.putString("thingkey", lakey);
      thingkey = lakey;
      Serial.print("NOUVEL API KEY : ");
      Serial.println(thingkey);
    }
    if (leusedallas != usesenseurdallas) {
      preferences.putUInt("usesenseurdal", leusedallas);
      usesenseurdallas = leusedallas;
      lesliens();
      Serial.print("NOUVEAU use dallas : ");
      Serial.println(usesenseurdallas);
    }
    if (leusedht != usesenseurdht) {
      preferences.putUInt("usesenseurdht", leusedht);
      usesenseurdht = leusedht;
      lesliens();
      Serial.print("NOUVEAU use dht : ");
      Serial.println(usesenseurdht);
    }
    if (lechan != thingchanel) {
      preferences.putString("thingchanel", lechan);
      thingchanel = lechan;
      lesliens();
      Serial.print("NOUVEAU channel : ");
      Serial.println(thingchanel);
    }
  }
  String contenu = "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\" class=\"client-nojs\">\n<head>\n";
