Esp32 + enc28j60 = pas de connexion vers database

Salut à tous,
j'utilise donc un esp32 avec un module ethernet enc28j60 relié en spi.

Le code me donne bien une initialisation ok, donc selon moi pas de soucis au niveau du hardware/cablage.

Par contre, à chaque fois qu'il veut envoyer des données vers le php pour la base de données, je récupère une erreur "-1" et les données ne sont pas envoyées.

Le problème ne se pose pas en utilisant une connexion wifi.

Sauriez-vous me dire ou le problème se pose?
Ou peut-être une autre possibilité?

merci

#include <EthernetENC.h>
#include <HTTPClient.h>


                                                                                 
    uint8_t macaddress[6] = {0x1,0x2,0x3,0x4,0x5,0x6};
const char* serverName = "http://********/post-esp-data.php";
String apiKeyValue = "tPmAT5Ab3j7F9";
    void setup() {
  

    Serial.begin(115200);
    Ethernet.init(5);
    Ethernet.begin(macaddress); // Dynamic IP setup 

    delay(5000);

    Serial.print("Local IP : ");
    Serial.println(Ethernet.localIP());
    Serial.print("Subnet Mask : ");
    Serial.println(Ethernet.subnetMask());
    Serial.print("Gateway IP : ");
    Serial.println(Ethernet.gatewayIP());
    Serial.print("DNS Server : ");
    Serial.println(Ethernet.dnsServerIP());
    Serial.println("Ethernet Successfully Initialized");
    }

    void loop()
    {
    HTTPClient http;
EthernetClient ethClient;
    http.begin(ethClient, serverName);
    
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    
    // Prepare your HTTP POST request data
    String httpRequestData = "api_key=" + apiKeyValue + "&naam=" + String(millis())
                           + "&straat=" + String(millis()/10) 
                           + "&nummer=" + String(millis()/100) +"&postcode=" + String(45) +  "";
    Serial.print("httpRequestData: ");
    Serial.println(httpRequestData);
   
    int httpResponseCode = http.POST(httpRequestData);
     
    if (httpResponseCode>0) {
      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);
    }
    else {
      Serial.print("Error code: ");
      Serial.println(httpResponseCode);
    }
    // Free resources
    http.end();
  
 //Send an HTTP POST request every 30 seconds
  delay(30000);  
  
     
    }

Salut.
J'avoue ne pas connaître ENC28J60. Je préfère W5100 ou W5500, moins tributaire du software.
Si POST() retourne -1, d'après HTTPclient.h cela veut dire HTTPC_ERROR_CONNECTION_REFUSED
Il faudrait voir se qui se passe côté PHP.
L'utilisation du POST pour ce genre d'utilisation me surprend, mais pourquoi pas, si le code PHP attend un POST ...

cela fonctionne sans soucis avec une connexion wifi.
Donc le problème viendrait du Shields ethernet ou la config du Shields ou la mise en route du Shields selon moi

Oui OK, mais CONNECTION_REFUSED est un code d'erreur que le serveur renvoie, donc il reçoit bien quelque chose.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.