Arduino Ethernet Shield and PHP

Asked

Viewed 970 times

1

Hello I am developing a code for Arduino + ethernet that triggers GET (PHP) methods, and PHP sends the received data from Arduino to Mysql.

The code in php works perfectly, the ethernet can connect to the server by port '8095' but can not trigger the GET parameters. I’m not sure if the problem is in the code, or in an area related to the network.

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
byte ip[] = {192,168,1,60};                         //IP DO ARDUINO (WEB CLIENT)
byte servidor[] = {192,168,1,8};                   //IP DO SERVIDOR 

EthernetClient cliente;

void setup() {   
            Serial.begin(9600);  
            Ethernet.begin(mac, ip);
         }

void loop() {

 if (cliente.connect(servidor, 8095))  //Se o arduino se conectar ao servidor
{
     cliente.print("GET /programas/Query.php?a=2"); //Envia  $_GET['a'] = 2;
     cliente.print(" HTTP/1.1");
     cliente.stop();
     Serial.println("Informação enviada com sucesso!"); 
} 
else {Serial.println("Falha na conexão");}
}
  • First, don’t post your codes in image form; [pt.so] supports them in both the question and the answer, then edit your question accordingly. Second, wouldn’t it be lack of HTTP headers? Or just the line break indicating that all headers have been sent.

  • I tried but unfortunately it didn’t work, Arduino can connect to webserver (Apache) but can not execute the GET parameters hosted on this server.

  • Have some server return after the request?

  • No, nothing happens... If the code worked PHP would send the value '2' to a table in a Mysql database, but this does not happen. .

2 answers

1

I found the answer to this problem in stackoverflow(English) the problem was in HTTP1.1 extrusion

Below is the correct extrusion.

"GET /programas/Query.php?a=2\r\nHost: 192.168.1.8\r\n\r\n"

0

Another question for this same code how do I return and print what was processed on the server side on the serial monitor?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.