Ethernet : How to get the response from a php?

I m trying to save data in mysql

and this is my code

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

byte MAC = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

byte IPADDR = { 192, 168, 1, 4 };

byte GATEWAY = { 192, 168, 1, 1 };

byte SUBNET = { 255, 255, 255, 0 };

EthernetClient client;

void setup()
{

Serial.begin(9600);

Ethernet.begin(MAC, IPADDR);

delay(1000);
}

void ContactWebServer(float bend_value, float bend_state)
{
Serial.println(“Connecting to the web server to send alert…”);
if (client.connect(“http://base-colap.rhcloud.com”,80))
{
Serial.println(“Connected to PHP server”);

client.print(“GET /wateralert1.php?alert=”);
client.print(bend_state);
client.print("&flex=");
client.print(bend_value);
client.println(" HTTP/1.1");
client.println();
client.stop();
}
else
{
Serial.println(“Failed to connect to the web server”);
}
}

void loop()
{
float sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (100.0000 / 1023.0000);
float cur = sensorValue * (20.0000/1023.0000) * 1.999;
// print out the value you read:
Serial.print(cur);
Serial.print(" mA \t");
Serial.print(voltage);
Serial.println(" %");
delay(3000);

ContactWebServer(voltage,cur);
delay(5000);
}

It gets connected to the url . but there is no data in the database

How to get the response of the php ?

Hi,

I did something similar recently. Altough I didn't implement getting the response yet, I will show you what I did:

  if (client.connect(base-colap.rhcloud.com, 80) > 0) {
     Serial.println("Connected to PHP server");
    client.print("GET http://base-colap.rhcloud.com/wateralert1.php?alert=");
    client.print(bend_state);
    client.print("&flex=");
    client.print(bend_value);
    client.println(" HTTP/1.1");
    client.println("Host: base-colap.rhcloud.com");
    client.println();
    client.println("User-Agent: Arduino");;
    client.println("Connection: close");
    client.println();
    client.println();

  }

What came across is, that at some points you might not want to use the "http://" header, and at others you will.

If I get the response to work, I will report back.

Hope that helps! :)

Jonathan

Maybe if you displayed what the server sends in the response would help you troubleshoot this. I also changed the GET to HTTP/1.0.

Serial.println("Connected to PHP server");

client.print("GET /wateralert1.php?alert=");
client.print(bend_state);
client.print("&flex=");
client.print(bend_value);
client.println(" HTTP/1.0");
client.println();

while(client.connected()) {
  while(client.available()) {
    Serial.write(client.read());
  }
}
Serial.println("disconnected");
client.stop();