Hello,
I have working webclient now, but I have problem with code:
#include <UIPEthernet.h>
#include <SPI.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//byte ip[] = { 10, 0, 0, 177 };
char server[] = { "www.jakubmiga.eu"}; // Google
EthernetClient client;
void setup()
{
Serial.begin(9600);
Serial.println("Start...");
Ethernet.begin(mac);
client.connect(server, 80);
delay(1000);
Serial.println("connecting...");
if (client.connected()) {
Serial.println("connected");
client.println("GET /add_temp.php?temp=");
client.print(analogRead(0));
client.println("HTTP/1.1");
client.println("Host: www.jakubmiga.eu");
client.println();
} else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()>0) {
char c = client.read();
Serial.print(c);
}
if (0 == (millis()%1000))
Serial.println(millis()); //debug output
if (!client.connected()) { //never true
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}
}
My add_temp.php is correct, because when I try manually set
http://jakubmiga.eu/add_temp.php?temp=2
It works good, temperature 2 is in MySQL
BUT when i'm trying do it with Arduino, it gives me:
Start...
connecting...
connected
6000
6000
6000
HTTP/1.0 400 Bad Request
Connection: close
Content-Type: text/html
Content-Length: 349
Date: Thu, 08 May 2014 09:21:08 GMT
Server: lighttpd/1.4.19
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>400 - Bad Request</title>
</head>
<body>
<h1>400 - Bad Request</h1>
</body>
</html>
disconnecting.
So as you can see, error is Bad Request, so it gives bad command to PHP.
Can somebody help me? Thank you