I would need so help. I am trying to send data to a php page using an arduino with Ethernet Shield.I manage to send data using the GET method but it is not a safe way. So I am now trying the POST method but I have no idea why it won't work.

The place to start debugging is the access and error logs for the web server that is serving the PHP page.

The URL in the code uses mixed upper and lower case. Not all file systems support this correctly, and for this reason URLs are usually not mixed case. This is one possible cause of bugs like the one you are seeing.

Webmaster that owns 40 dot coms. Prepper living off grid in a camper with 400watts of solar panels charging 9 AGM 12V batteries. i am an absent minded evil genius, a high functioning aspie and dont get sarcasm.

Is now looking for a HTML element that has the name "Data", which doesn't exist.Try writing your data into a separate text file from the arduino (remember to chmod the file) and then do something like;

iDroid wrote:$_POST is used to get values from a HTML form element with a name that corresponds to the value inside the square brackets.

This is partly true, in that what you say is a method often used, but it is not the definition of the POST method.

Using the POST method, you simply place the data, not on the url, but within the body of the http request, whether that be a html form, or for example, json encoded data from an external server/client system like an Arduino. And as such it is possible to send what ever data you have from the Arduino to a server using this method. Using the POST method also allows you to send more data than the GET method.

Quote

royalldonkey wrote:I manage to send data using the GET method but it is not a safe way

How is using the GET method an issue with safety when using an Arduino?I can understand the safety issues using the GET method from a html request from a browser on a computer, but I am not sure that you have this issue when sending data using the GET method from the Arduino?How could the data be intercepted and viewed if it is sent from the Arduino?If there is any chance of data snooping, the POST method I believe offers no extra protection, as the data is simply shifted to a different location in the http request.

I have taken a section of my Arduino code out that deals with the transfer of data from my Arduino to my SQL database on my hosted site.I use the Eclipse IDE, and make use of headers files, so file.cpp and header.hThe code below is part of an include file I use.

void postLive(), simply pre-formats some real-time data into json formatted style. You can do this a different way as you please. You just need the php script on your server to understand your format. It then calls the main posting routine below, if successful, it increments a success counter else increments a un-successful counter which I use for debug stats.I have other functions for other data.

bool postPage(char* thisData), does the hard work of actually using the POST method to send data to my host, where a php script pulls out the data and puts it into a SQL database.

iDroid wrote:$_POST is used to get values from a HTML form element with a name that corresponds to the value inside the square brackets.

This is partly true, in that what you say is a method often used, but it is not the definition of the POST method.

Using the POST method, you simply place the data, not on the url, but within the body of the http request, whether that be a html form, or for example, json encoded data from an external server/client system like an Arduino. And as such it is possible to send what ever data you have from the Arduino to a server using this method. Using the POST method also allows you to send more data than the GET method.

Oh, never knew that. Thanks.If that isn't the problem... Then what is?

client.println(DatatoSend.length());I am unsure if that will work, it looks like nice oop style, but I think you need to use the length function.Also, the use of the 'String' data type is discouraged due to some issues, use a char array instead.

The code I have placed above is in my working Arduino and POST's to my sql database each 60 seconds.The code I used is based on code developed by SurferTim.

@H2SO4I will post a section of php with sql code up here shortly, just having first morning coffee

I have tried changing SnSR::ESTABLISHED to have a value of 21 but still no luck getting connected. Looking deeper, I can see the SPI code in W5100Class::read(uint16_t _addr) is indeed reading '21' from the W5100.

Looking at WireShark traces, there is evidence of the DHCP request being fufilled and an IP address being handed out. THEN, a couple 'blackjack' port 1025 messages are sent from the arduino and that's it.

What are you attempting to do, to issue a GET or a POST to push data to a server?From what you say, it seems you are using DHCP, and that the Arduino seems to be getting an IP address and then falls over, but have you tried not using DHCP and instead, specifying the IP parameters?Could putting debug points (serial prints) in at strategic places help you, even in the library?Could it be something in your router's configuration?

Are you using the latest version of the IDE together with the supplied libraries, not mixing compiler version with library versions?

It appears you have delved deeply into the problem and have an understanding of the EthernetClient library.You mention;

Quote

Accepting incoming connections from my browser

Can you explain this more clearly, as I don't really understand what you mean here?

Firstly, royalldonkey can you let us know of your progress, have you some success as yet?@JohnHoward, please be mindful not to highjack the thread of royalldonkey, but if some of this helps out for you, that is good.

Here is a little bit of the php script I use to collect the data sent by the Arduino with the code posted a few posts up.It listens with a switch statement depending on the type of http request, POST, GET, PUT or DELETE methods.

The following code details the workings for a POST message and decodes the JSON formatted data as sent by the Arduino and stores certain values to a real time single record database table as well as storing other values to a standard mult-record incrementing database table. Again, you don't need to use JSON, it is just that I do for pushing data around. I use CSV for pulling the data out for trends on the client side of things.

I have altered any specific information, and as such you need to specify SQL username, password and database and table names as for your own configuration.

// Here we work out if we received a POST, GET, PUT or DELETE request from the client:switch($_SERVER['REQUEST_METHOD']) { case 'POST':// post methodPOST_sql(); break; case 'GET':// get methodbreak; case 'PUT':// update methodbreak; case 'DELETE':// delete methodbreak; }//-------------------------------------------------------------------// Arrive here if we received a POST message from the client:// And decide which POST message we received from the Arduino:// Data from Arduino is JSON encoded, so use php JSON decode://function POST_sql() {$rawdata = file_get_contents('php://input');$data = json_decode($rawdata, true);// echo "Raw: ", $rawdata,"\r\n"; // we can echo back the raw data received from Arduino:

Royalldonkey, and others: I continued to play with this, using the code from zoomkat to build something that would POST as you were POSTing. I came up with this, which does work -- with a caveat (see below):

if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: while(true); }

Serial.begin(9600); Serial.println("Even better client test 02/03/13"); // so I can keep track of what is loaded Serial.println("Send a g to GET or a p to POST in serial monitor to test"); // what to do to test}

What I could never do was talk to a webserver on the same subnet as my Arduino. It has to be a configuration issue, but I can't figure it out. I have my Arduino on 192.168.0.11 and webserver on 192.168.0.13. The Arduino never connects to it. If I simply change the address of the webserver to 192.168.100.1, it works like a champ. If I use a serverName and reference something outside my local network, it works fine.

So other than that, my POST above should do what you are trying to do.

I hope someone can chime in a explain the wierdness with same-subnet connections. I have verified the webserver is running and working. It is just a normal apache 2.2 server. Deep inspection of the code and the WireShark traces shows me the wiznet library simply never talks to the same-subnet server.