ESP32 php MYSQL

Bonjour
L'ESP32 capture temperarure, pression, humidité et l'envoie au php qui maj la base de donnée mysql
Malgré un retour http code =200 la bdd n'est pas mise à jour.
Avec ce même fichier php, je lui envoie un formulaire html : la bdd est maj:
voici la partie code arduino :slight_smile:

    WiFiClientSecure *client = new WiFiClientSecure;
    client->setInsecure(); //don't use SSL certificate
    
    HTTPClient https;
    
    // Your Domain name with URL path or IP address with path
    //https.begin(*client, serverName);
    https.begin(*client, serverName);
    // Specify content-type header
    https.addHeader("Content-Type", "application/x-www-form-urlencoded");
    // Prepare your HTTP POST request data
    String httpRequestData = "api_key=" + apiKeyValue + "&TEMP_BURO=" + String(temp)
                          + "&HUM_BURO=" + String(hum) + "&PRESS_BURO=" + String(pres) + "";
    Serial.print("httpRequestData: ");
    Serial.println(httpRequestData);
    
    // Send HTTP POST request
    int httpResponseCode = https.POST(httpRequestData);
    Serial.println("POST POST POST");
    
    if (httpResponseCode>0) {
      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);
    }
    else {
      Serial.print("Error code: ");
      Serial.println(httpResponseCode);
    }
    // Free resources
    https.end();
  }
  else {
    Serial.println("WiFi Disconnected");
  }
  //Send an HTTP POST request every 5 seconds
  delay(15000);  
  
  WiFi.disconnect();
  Serial.println("----------------------");
  Serial.println("Rentre en mode Deep Sleep");
  Serial.println("----------------------");
  esp_deep_sleep_start(); 
 
}

Voici la sortie serie :

Connected to WiFi network with IP Address: 192.168.1.35

temperature :20.00

humidité :50.50

Pression :1024.04

httpRequestData: api_key=jghghghghghghghgh&TEMP_BURO=20.00&HUM_BURO=50.50&PRESS_BURO=1024.04

POST POST POST

HTTP Response code: 200

Voici le code du php :

if   (isset($_POST["api_key"]) && isset($_POST["TEMP_BURO"]) && isset($_POST["HUM_BURO"]) && isset($_POST["PRESS_BURO"])) {
    $api_key = test_input($_POST["api_key"]);
    if($api_key == $api_key_value) {
        echo 'Api Key OK<br>';
        $TEMP_BURO = test_input($_POST['TEMP_BURO']);
        $HUM_BURO = test_input($_POST['HUM_BURO']);
        $PRESS_BURO = test_input($_POST['PRESS_BURO']);
        
        $servname = "localhost";            
        $dbname = "my_dbname";            
        $user = "my_user";            
        $pass = "passxxxxxxxxxxxxxxxx";
        
        try{
             $dbco = new PDO("mysql:host=$servname;dbname=$dbname", $user, $pass);
             $dbco->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             echo '2222222222<br>';
             $sql = "INSERT INTO SENSOR_BURO ( TEMP_BURO, HUM_BURO, PRESS_BURO)
            VALUES ('" . $TEMP_BURO . "', '" . $HUM_BURO . "', '" . $PRESS_BURO . "')";
                      
             $dbco->exec($sql);
             echo 'Entrée ajoutée dans la table';
             $dbco = null;
         }
            
         catch(PDOException $e){
              echo "Erreur : " . $e->getMessage();
         }
        
        
     }
function test_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;

Où est l'erreur ?
Merci de votre aide
Daniel

Personne ?

Bonjour,
Pour tester c'est bien d'avoir le code complet...