Bonjour à tous, Je travail actuellement avec un module ethernet breakout board enc28j60 et un arduino MEGA 2560.
je cherche à envoyer des variables par méthode POST à un script PHP.
la méthode GET marche bien mais je préférerais utilisé la méthode POST.
Je dispose du script suivant :
#include <EtherCard.h>
static byte mymac[] = {0xDD,0xDD,0xDD,0x00,0x00,0x01};
char website[] PROGMEM = "192.168.100.22";
boolean x = true;
byte Ethernet::buffer[700];
static uint32_t timer;
static void response_callback (byte status, word off, word len) {
Serial.print((const char*) Ethernet::buffer + off + 207);
}
void setup () {
Serial.begin(57600);
Serial.println("Client Demo");
Serial.println();
if (!ether.begin(sizeof Ethernet::buffer, mymac, 10))
Serial.println( "Failed to access Ethernet controller");
else
Serial.println("Ethernet controller initialized");
Serial.println();
if (!ether.dhcpSetup())
Serial.println("Failed to get configuration from DHCP");
else
Serial.println("DHCP configuration done");
ether.printIp("IP Address:\t", ether.myip);
ether.printIp("Netmask:\t", ether.mymask);
ether.printIp("Gateway:\t", ether.gwip);
Serial.println();
ether.hisip[0] = 192;
ether.hisip[1] = 168;
ether.hisip[2] = 100;
ether.hisip[3] = 22;
ether.printIp("SRV IP:\t", ether.hisip);
Serial.println("Loop :");
delay(1000);
}
void loop() {
ether.packetLoop(ether.packetReceive());
if ((millis() > timer) && x == true) {
timer = millis() + 5000;
const char postval[] = "id=422";
ether.httpPost(PSTR("/test/index2.php"), website, PSTR(""), postval, response_callback);
x = false;
}
}
et voici mon script php :
<?php
if(isset($_POST["id"]))
echo "id :" . $_POST["id"];
elseif(isset($_GET["id"]))
echo "id :" . $_GET["id"];
else
echo "nothing to show";
?>
Seulement, le problème est que mon arduino me retourne "nothing to show" au lieu de me retournée le nombre 422.
Je ne comprend pas d'où vient le problème.
Merci à tous.
Timiti29
PS : voici le prototype de la fonction httpPost :
void EtherCard::httpPost (prog_char *urlbuf, prog_char *hoststr, prog_char *additionalheaderline,const char *postval,void (*callback)(byte,word,word))