http request not working correctly...

trouble writing to a mySql database

The following code doesn't seem to work. I cant figure out why.

If I send the commands to serial.print, I can copy and paste the url into a browser which works and creates a database entry.

something here must be incorrect..

// if you get a connection, report back via serial:
(client.connect(server, 80));
Serial.println("connected");
// Make a HTTP request:
client.print("GET http://example.com/data.php?Temperature="); //place your server address here
client.print(temperature);
client.print("&Setpoint=");
client.print(Setpoint);
client.print("&Input=");
client.print(Input);
client.print("&Kp=");
client.print(Kp);
client.print("&Ki=");
client.print(Ki);
client.print("&Kd=");
client.print(Kd);
client.print("&Heater=");
client.print(Output/WindowSize*100);
client.println(" HTTP/1.0");
client.println("Host: http://example.com");
client.println();
client.stop();

the url that works via browser looks like this

GET http://example.com/data.php?Temperature=30.1&Setpoint=32$Input=34$Kp=5$Ki=5$Kd=5$Heater=10 HTTP/1.0

Try no protocol on the GET.

client.print("GET /data.php?Temperature=");

still no luck I’m afraid…

I created a new program and made it as simple as I could, sending static data to the data.php page…

#include <SPI.h>
#include <Ethernet.h>
byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 177);
EthernetClient client;

void setup()
{
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
Ethernet.begin(mac, ip);
}
delay(1000);
}

void loop()
{
Serial.println(“connecting…”);
if (client.connect(“www.hopwarriorbrewing.uk”, 80))
{
Serial.println(“connected”);

client.println(“GET /data.php?Temperature=25.06&Setpoint=28.00&Input=25.09&Kp=200.00&Ki=50.00&Kd=0.00&Heater=100.00 HTTP/1.1”);
client.println(“Host: www.hopwarriorbrewing.uk”);
client.println(“Connection: close”);
client.println();

Serial.println(“GET /data.php?Temperature=25.06&Setpoint=28.00&Input=25.09&Kp=200.00&Ki=50.00&Kd=0.00&Heater=100.00 HTTP/1.1”);
Serial.println(“Host: www.hopwarriorbrewing.uk”);
Serial.println(“Connection: close”);
Serial.println();
}
else {

Serial.println(“connection failed”);
}
}

copy/paste the part in bold into a browser and it works…

here is that page that should update…

http://www.hopwarriorbrewing.uk/dashboard.php

and the

code in data.php, although I’m confident this part is ok, because it works when you paste the url in a browser.

<?php $dayz = time(); $aa = (($_GET['Temperature'])); $ab = (($_GET['Setpoint'])); $ac = (($_GET['Input'])); $ad = (($_GET['Kp'])); $ae = (($_GET['Ki'])); $af = (($_GET['Kd'])); $ag = (($_GET['Heater'])); $db="hopwarri_homebrew"; $link = mysql_connect('', 'xxxx', 'xxxx'); if (! $link) die(mysql_error()); mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error()); $queryResult = mysql_query("INSERT INTO temp (Time, Temp, Setpoint, Input, Kp, Ki, Kd, Heat) VALUES ('$dayz', '$aa', '$ab', '$ac', '$ad', '$ae', '$af', '$ag')"); ?>

the serial output is

Wrong!

GET http://www.hopwarriorbrewing.uk/data.php?Temperature=25.06&Setpoint=28.00&Input=25.09&Kp=200.00&Ki=50.00&Kd=0.00&Heater=100.00 HTTP/1.1

The protocol and server name are NOT part of the GET request.

You do NOT call Ethernet.begin() in loop(). You do not connect to http://anything. You connect to a server. The ONLY protocol you can use is http://, so it is never necessary to say that.

Is that website hosted by a hosting company? If so, you must include a "Host: my domain.com" in the request header.

yes it is, just free hosting that offers mySQL.

when I log into the web control panel I can see this..

https://host36.qnop.net:2083/

Server Name host36
Architecture x86_64
Operating System linux
Shared IP Address 82.147.19.106

PaulS:
Wrong!
The protocol and server name are NOT part of the GET request.

You do NOT call Ethernet.begin() in loop(). You do not connect to http://anything. You connect to a server. The ONLY protocol you can use is http://, so it is never necessary to say that.

I've edited my code above, looking better?

its working with the code in post #2 :slight_smile:
I guess it was "http://" that was stopping it.

surferTim, yes I am using a hosing company. www.5quidhosting.co.uk. I chose them because the free hosing they offer is enough to get this up and tested. I guess I don't need to include "Host: my domain.com" in the request header?!

thanks for your help!

You already were using it. I didn't see it in your code.

client.println("Host: http://example.com");

You really should read the response from the server though.