Get one value mysql to arduino variable

Hi,

Since 1 week, i'm looking for a simple code, but every time, too difficult to understand. Maybe you can help me.

I have a mysql database. With some value.

I wan't take one of them, and put it in a value arduino.

Simple no? Not really...

I use an ethernet shield. My code start like this:

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xF9, 0x6D };
IPAddress ip(192,168,1,89);
EthernetServer server(80);

void setup() {
 // Open serial communications and wait for port to open
 
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();

}

My aim is: connect to my database (on OVH webserver)
Use a sentence like in php "SELECT name FROM listname WHERE id=1"
and put this value une an arduino value.

Somebody have an exemple of simple code like this to help me?

Thank you very much for this!

Have the arduino call a php that select the MySQL table. Echo the value or if you have multiple values, echo as normal key value pair query string. Then have the arduino parse the value.
Pretty easy :slight_smile:

All right, it was the good solution.

So I have 1 php page, looking for value of my mysql.
I print my page like this:

<html>
<head></head>
<body>
<info1>23</info1>
<info2>0</info2>
<info3>245</info3>
<info4>10</info4>
<info5>5</info5>
</body>
</html>

And with my arduino, i'm going on this page, then arduino parse the page.

Like this I have value, but string value.
So after I use a script to put it in int value...

int myStringLength = message.length()+1;
    char myChar[myStringLength];
    message.toCharArray(myChar,myStringLength);
   int messa = atoi(myChar);

And it works.

So thank you very much :wink:

But "pretty easy"??? no way... :smiling_imp:

Thanks again

You could simply print on the php page

info1=23&info2=0&info3=245&info4=0&info5=24

Have the arduino parse that too. It would be smaller.