I have been unable to find anything about sending data from the Arduino (with Ethernet shield) to an external database (on the internet). Does anyone know of any resource about sending data out to the internet? Thank you in advance for your help.
You haven't been looking hard enough. This is the Arduino end of the code.
http://playground.arduino.cc/Code/WebClient
You can use PHP on the server end.
Thanks for the link.
The code does not appear to enter username or password anywhere...
Are you sure this is for sending to a database?
elarpa:
Thanks for the link.The code does not appear to enter username or password anywhere...
Are you sure this is for sending to a database?
What user name and password are you talking about?
That code is for invoking a php script on a server. It is up to you to make the php script stuff the data in a database.
Any server, database or website hosting requires a password for uploading on them.
But I guess your answer confirms my suspicion that it is not for sending data to a database...
Can anyone refer to a resource about sending data to a database? Thank you in advance for your help.
It confirms my suspicion that you don't know much about authentication. The Arduino ethernet library doesn't support SSL, so security will be a bit lax when sending a user/password.
You can use basic auth with that code. You mentioned nothing about the server's security requirements.
OK, thanks! I will try to see if it works with that.
Apparently the correct command for connecting to my database is this one:
mysql -u USERNAME -pPASSWORD -h HOSTNAMEORIP DATABASENAME
Can it be used with this code?
If you are interfacing to TCP port 3306, there is a way to do that, but it requires a mySQL library last I checked. I use PHP on port 80 and use it to interface with mySQL.
Thanks for your feedback. But the PHP is not working for me....
char serverName[] = "mydbb4.surf-town.net";
char pageName[] = "ElArpa_batteries/NEW";
also not if I add .php after... What am I doing wrong?
So what is the error? Unable to connect or a 404 error?
400 Bad Request
Your browser sent a request that this server could not understand.
Then you are sending a malformed request.
The only thing I changed in your code (the POST method) is the server and page name - the rest is unchanged.
But are you saying that the connection is correct - only the request is bad?
I have been testing....
If I remove the header part:
// send the header
sprintf(outBuf,"POST %s HTTP/1.1",page);
client.println(outBuf);
sprintf(outBuf,"Host: %s",domainBuffer);
client.println(outBuf);
client.println(F("Connection: close\r\nContent-Type: application/x-www-form-urlencoded"));
sprintf(outBuf,"Content-Length: %u\r\n",strlen(thisData));
client.println(outBuf);
and only try to send variables:
long thisData1;
float thisData2;
thisData1 = 14052016;
thisData2 = 12.6;
// send the body (variables)
client.print(thisData1, thisData2);
I get no error message. It looks like it is connecting correctly. The serial monitor only returns 'timeout'.
BUT: It is not writing anything to the database.... What am I doing wrong?
This won't work.
client.print(thisData1, thisData2);
What will work, then?
I need to send the time (date&time) and the voltage reading (with 2 decimals, e.g. 12.54) to the database frequently - nothing else. Just those two data for every reading. How do I send those two values to the database?
In the database I have prepared a table called "NEW" with 2 columns formatted for date&time and a float reading (voltage) respectively. So the Arduino simply has to send the two data en the right format to the "NEW" table. How do I program that?
Maybe the date&time is not even necessary, since the database may possibly register the time and date of each entry itself. In that case I would only need to send the voltage reading - nothing else.
Thank you in advance for your help.
If you are using my example from the playground, then...
// params must be url encoded.
sprintf(params,"thisData1=%i&thisData2=%i",thisData1,thisData2);
Insure the params variable is big enough to handle your entire array.
Thanks for your suggestion.
I am afraid that it is still not writing anything to the database...
I made sure that it is big enough:
// insure params is big enough to hold your variables
char params[128];
It keeps connecting and giving timeout - but nothing happens in the database:
connecting...connected
Timeout
disconnecting.
If I print out params I get this rather strange result:
thisData1=9230&thisData2=4
Any suggestion?
Any suggestion?
Yes, but I'm not going to post it.
Instead, I'll just say POST YOUR CODE.