Go Down

Topic: arduino+ethernet shield+php (Read 8865 times) previous topic - next topic


i am doing a 2 two communication between arduino and php server.
right now, i am using arduino as a client and successfully send data to my remote php server through ethernet shield.
but i am not sure how i can using php control arduino through Ethernet shield.

anyone can help me?

thanks a lot!


have the ethernet shield regularly poll the server for information.


I hope your projecct is going well,
I'm new to the ethernet sheild, would you be able to point me in the direction of example php and sketches to get the data transfer working please? I'm a bit lost at the minute!





I am interested in this also, as i am trying do do two way communication.

For the Moment i can post data via php to a mysql server, but i am not able to control the arduino through php and the ethernet shield.

Do some of you have some code examples i could look into?

Thanks! - Kedde


could you post your code on having the Arduino be a client to your PHP server?  this is exactly what i'm trying to do with the Arduino Ethernet shield with no success with


It is also posted here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1268504939   - post 7

But i assume that Danish isnt your 2. language so i have translated the comments:

The Arduino Code:
Code: [Select]

#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 88 };
byte gw[] = {192,168,1,1};
byte server[] = { xxx, xxx, xxx, xxx  }; // Server IP
byte subnet[] = { 255, 255, 255, 0 };
int data = 0;
int tempPin = 2;  // In This case the temperature is taken from pin 2 and sent to a sql server

void setup()

pinMode(tempPin, INPUT);
Serial.begin(9600);               // Used for serial debugging

void loop()

Serial.println("Program running...");

senddata();                                 // Data is sent every 5 seconds

void senddata()

data = analogRead(tempPin);           //Reading analog data

Ethernet.begin(mac, ip, gw, subnet);
Client client(server, 80);
delay(1000);                                    //Keeps the connection from freezing

if (client.connect()) {
client.print("GET http://server.com/script.php?vaerdi=");
client.println(" HTTP/1.1");
client.println("Host: www.server.com");

Serial.println("Connection unsuccesfull");
//stop client
while(client.status() != 0)

PHP Code:
Code: [Select]



//Connect to database
$opendb mysql_connect("xxx.xxx.xxx.xxx""database""password") or mysql_error("Could not connect to database");
     if (
mysql_query(" INSERT INTO tabel (Dato, DATA) VALUES ( NOW() , $DATA )");


In the MySql server there are 1 table with 2 datasets, one with the name DATA (Integer) and one with the name DATO (DATETIME)

I am not really good with mysql so if someone could tell how to get the MySql server to delete the oldest data i would be very happy :)

Also, this is not all my work, i modified it to my needs, but unfortunately i dont remember where i got if from..

:) - Christian


Thanks Christian I think you solved my problem.  Going to tinker with it tonight.


To delete the latest use DELETE FROM table ORDER BY DATO DESC LIMIT 1

That command will delete one row (limit 1), and it might be the oldest one. I say might because I can't remember how dates are treated - if it deletes the lowest one change DESC to ASC (ascending or descending).

I'd recommend adding an auto-incdement ID field as a primary key.


Team SCC, Kyle is right - the easiest way is to have your arduino poll a dynamic page which feeds the arduino the latest command.

I've used that technique on my physical hit counter, code available here: http://cowjam.net/


Hi Cowjam

I am very interestet in this topic, but I can see your link does'nt point to the code anymore, could you please post the code again.

Thank you.  :)

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