Go Down

Topic: Arduino + ethernet shield: read information from the database (Read 1 time) previous topic - next topic



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?


May 05, 2012, 03:51 pm Last Edit: May 05, 2012, 04:05 pm by VMwareUser Reason: 1
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).
Quote"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.
<myTag data=1234>


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


You must modify your client.read() 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.

Code: [Select]
// 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 client.read () 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.



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.

Code: [Select]

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

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131