send data to MySql

Hello wondering if you can help.

I have a Arduino uploading data to a MySql database but the data is not getting through. The code to upload the data is a client code sending a GET HTML link to a file called updat_db.php. the code is below.

void sendGET() //client function to send/receive GET request data.
  Serial.println ("send data");
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    client.print("GET /update_db.php?panel=");//send panel = to server
    client.print(panelin);//add panelin temperature to above line note no println in code
    client.println(" HTTP/1.0");// add to end of GET send with println
    client.println("Host:");// my web host address
    client.println(); //end of get request
    Serial.println ("end send data");
  else {
    Serial.println("connection failed"); //error message if no client connect

what i get back from the serial terminal is below

send data connected end send data HTTP/1.1 302 Found Date: Mon 05 Jan 2015 09:41:41 GMT Server: Apache/2.2.3 (CentOS) X-Powered-By: PHP/5.1.6 Location: content-Length: 0 Connection: close Content-Type: text/html; charset=UFT-8 disconnected

Now if i type the above http:// address in a browser the update-db file is called and mySql is up dated correctly, so the address and php file are all correct. According the the serial feed back the arduino is outputting this address but the data base is not updating when the arduino does this.

Any one got any ideas why this does not work. If you need more information please let me know.

Just to note the address in the arduino code goes to a no-ip DNS account which then send the data to a raspberry pi which is running apache2 server. The ip address changing.

Ive tried changing the web address to the ip address of my server but this just did not connect. My port is on 8080 so i assume I need to change this is the arduino code.

If i connect through the local ip address it does not connect but i know it needs 8080 on the address to bring up the index page.

Can any one tell me is the client.print making up the web page address. if so then on the 6th line of the code why is GET in there, could i change this with my web address

any one got any ideas as ive tried a lot now and may need to redo all this another way

Just done a lest on my laptop through a dongle.

If I type

into the explorer adrress line the data dase is updated with the correct reading. and if I type

again it works ok.

So if the arduino is outputting this address line which looking at the serial print out seems to be doing so, then why is the database not updating.

My server is a linux apache2 on a Raspberry pi connected to port 8080. Is this something I need to consider.

I did have this all working when updating the same file on a LCN HOST server. I might have to go back to this.

Try POST instead of GET

Thanks for the reply.

Not sure this will make a difference, I can give it a go. Post is just another way to send the data which is not visual in the address line. GET should work the same way.

Seeing as GET function works when i put the address direct in my browser address line, I would expect the GET function in the arduino code to work the same.

I also used this exact code to upload data to a different online HOST with worked all ok.

Im thinking the problem could be with either the Pi running Linux and apache, or the ports are 8080 not 80. or it could be I need to register a proper Domain name. however the last theory should not be a problem.

I've been doing a lot of google searching and I cant see where anyone has done this. should whack you with a clue by four.

Hello Paul

Thank you for pointing this out, At least now i can see there is a problem. I have read the Wiki page. not completely understanding this yet,

If i’m understanding it this means my server does not support the HTTP / 1.0 or do i change the code to HTTP/1.1

I will do some more digging on this.


So reading up on this 302. this is a redirection code.

My arduino is sending out the address to a web program called noip. the address is

this then redirects this to my ip address of my home router.

could this by why the 302 code is coming up.

if so then this is normal the redirect ip address sent back is correct.

or is it saying it cannot find the update file. if so why as it works through a normal browser.

looking at the 302 code I could have a big problem. From what I have read this is where the original HTTP address sent by the Arduino has been redirected, I assume to my ip address which is what is being sent back in the serial data.

when this happens i loose the data in the GET HTTP line. would POST stop this?

or I have a problem with the server which i can't find any way around.

Any one had this problem

would POST stop this?

No. You are not connecting to the server or sending the right host information/ Without seeing all of your code, we'd only be guessing what you are doing wrong. I, for one, am not into guessing games.

steve, have you made any progress? I am eager to see how this turns out for you.