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
    Serial.println("connected");
    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.print("&lower=");
    client.print(lowerin);
    client.print("&upper=");
    client.print(upperin);
    client.print("&rayburn=");
    client.print(rayburnin);
    client.println(" HTTP/1.0");// add to end of GET send with println
      
    client.println("Host: stevehomecontrol.ddns.net");// 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
    Serial.println();
    return;
  }

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: http://86.173.99.233:8080/update_db.php?panel=9&lower=26&upper=41&rayburn=49 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 192.168.1.99 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

http://86.173.99.233:8080/update_db.php?panel=10&lower=10&upper=10&rayburn=10

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

http://stevehomecontrol.ddns.net/update_db.php?panel=10&lower=10&upper=10&rayburn=10

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.

http://en.wikipedia.org/wiki/HTTP_302 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.

cheers

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

www.stevehomecontrol.ddns.net

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.