Arduino + ethernet shield: read information from the database


How can I read information from the Internet from a database using arduino uno r3 + ethernet shield (w5100)?

I work with mySQL + PHP.
Be happy to see a simple example how you can take the information into a variable.

Thank you.

Be happy to see a simple example how you can take the information into a variable.

Me too, but there isn't a "simple" example. Do you have the PHP/MySQL server working correctly when you try the request with a web browser?

yes, i have php + mySQL.
i have a php file return text "hello word", and i wont set this text to string variable.

Succeed to write information to a database via a link that contains querystring.
For example:"hello word"

i can make a php file return a text string.

This is a malformed URL. Spaces are not allowed (between hello and word).“hello word”

If the server is returning a text response, which it should, then you must parse the data required in the Arduino from the response and convert it to a digital value. The good thing about HTML is web browsers will ignore any HTML tags they do not understand. You could send the data back in a tag. That should make it easier to find the data among the other stuff.

Thanks for the answer,
How do I get the data to a variable?

You must modify your routine to scan for that string. The easiest way is to make the code returned from the server as short and simple as possible, and start the line with that tag. That way, when you receive a CR or LF, you save the next 16 characters (or whatever you need) in a char array, then compare the first 6 characters with the tag.

// If you copied the first characters into inBuf, then
if(strncmp(inBuf,"<myTag",6) == 0)
   // the line starts with "<myTag"

Google search for atoi, strncmp and strtok. These are helpful functions for this.

How do I use () with a specific URL?
Thank you very much

The code on this post downloads the Google home page (by ip address) every 10 seconds.

The getPage() function takes two parameters. The first is the server ip, and the second is the page you want to download from that server. Replace "/" with "/mypage.php?test=1234" or whatever your page is called.

Open the serial monitor and watch. That may give you some ideas as you watch it work.

Thank you very much
I'll try it :slight_smile:

I forgot to mention one thing. If your server is using virtual hosting, you must add the Host to the GET send in the getPage() function. If it connects, but keeps returning 404 errors, then that is normally the challenge.


    // add the Host here
    sprintf(outBuf,"GET %s HTTP/1.0\r\nHost:\r\n\r\n",page);

Thank you

It works (:
Thank you!