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);
}