Arduino Forum

Forum 2005-2010 (read only) => Software => Troubleshooting => Topic started by: tehjrow on Jul 10, 2010, 05:36 pm

Title: Ethernet shield / php help
Post by: tehjrow on Jul 10, 2010, 05:36 pm
Ok, here's my arduino code:
Code: [Select]

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 30 };
byte server[] = { 192, 168, 1, 31 };
Client client(server, 80);

void setup()
{
 Ethernet.begin(mac, ip);
 Serial.begin(9600);
 
 delay(1000);
 
 Serial.println("connecting...");
 
 if (client.connect()) {
   Serial.println("connected");
   client.println("GET /script.php?getdata=1");
   client.println(" HTTP/1.1");
   client.println("Host: 192.168.1.31");
   client.println();
 } else {
   Serial.println("connection failed");
 }
}

void loop()
{
 if (client.available()) {
   char c = client.read();
   Serial.print(c);
 }
 
 if (!client.connected()) {
   Serial.println();
   Serial.println("disconnecting.");
   client.stop();
   for(;;)
     ;
 }
}



Here's my php code:
Code: [Select]

<html>

<?php

if ($_GET[getdata] == "1") &#123;

echo "it works";

&
#125; else &#123;

echo "no var";

&
#125;

?>


</html>



When I run that, on the arduino console i get 400 - Bad request.
However if, in a web browser I do
http://192.168.1.31/script.php?getdata=1
I get the output expected.  What am I doing wrong?
Title: Re: Ethernet shield / php help
Post by: tehjrow on Jul 10, 2010, 05:48 pm
Changing the line to
Code: [Select]
client.println("GET /script.php?getdata=1 HTTP/1.0");
works now