Go Down

Topic: PHP question: controlling Arduino over Ethernet using LAMP (Read 1 time) previous topic - next topic

R. Jacobson

I'm working on a data-logging project that connects an Arduino based weather-station to a linux server via ethernet. I'm using the LAMP stack on my server and am calling a PHP script to transfer sensor data from the Arduino to the server and store it in a MySQL database, and then another PHP script and Open Flash Chart v2 to to display the data in graphs. That part works pretty well.

Right now the weather station is programmed to automatically send its data to the server at a fixed interval. In addition to that, what I would like to be able to do is execute a PHP script on the linux server that tells the Arduino to take a current reading of all its sensors and send the data back to the server: I want to be able to remotely trigger a sensor poll.

I'm not very experienced with PHP. I can get the Arduino to wait, look, and interpret data coming from the server, but I have no idea what the PHP script to send data back over TCP/IP to the Arduino looks like. I imagine I have to define the Arduino's IP address, port, then initialize some sort of handshake with the Arduino, and send my data packet.

I don't really understand how to do that in PHP, or if it is even possible. Any suggestions, ideas, or example/pseudo code would be greatly appreciated!

Yours Truly.

R. Jacobson

If this wasn't the right forum to find help in, maybe a moderator could move my thread into the "Networking, Protocols, and Devices"-Forum?   

Much appreciated!


Here is another thread that covers php with an Arduino.
Code examples for both the Arduino and the server there.


The way you can do it is change a SQL variable in database and conitnously just poll the script in arduino with a GET element and put that variable from your webserver to the similar variable defined in your uC programme and then utilise a IF statement to take action that's , What you have done already I have done that with both Ethernet ,WiFi and GPRS as well, I personally like to develop Internet of things systems with GPRS internet.
"Real Men can Accomplish  Anything"

- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੁਂ!

R. Jacobson

Thx SurferTim, but I got that part figured out pretty well!

Unfortunately polling the sensor is just the first step, a test to establish communication from the apache server to the arduino; the end goal is much more sophisticated: ultimately I want to be able to have a network that can handle dozens of sensor stations, with potentially hundreds of individual sensors. I want to be able to remotely adjust all kinds of settings on the sensor stations: recalibrating sensors, changing sensors poll intervals, setting clock chips, downloading/clearing micro sd backup data to name just a few. I don't know if the continuous polling method is suitable for a scenario where I want a large and growing number of sensor stations, that just seems like it would spell out trouble; wouldn't I essentially be doing a DDOS attack on my own server?

Is there a way that I could just execute a php GET on the server that contains a predefined data (maybe just a single character) and targets the IP of the Arduino sensor station? Does the Arduino have to answer in a specific way for the transaction to be completed?

I think what I am trying to do is possible, I just can't quite wrap my head around the actual coding part of it. I've been looking for some kind of example code, even if it were just some one who turned a LED on and off using a PHP script on an apache server with the arduino connected ethernet. Anyways, I appreciate all ideas and suggestions :)


Sep 27, 2012, 12:55 am Last Edit: Sep 27, 2012, 01:01 am by SurferTim Reason: 1
I don't see a problem with what you want to do, but working out the details of each transaction will be your challenge. You may need to send more variables with the GET, and return more data from the server to the arduino and parse that out for your settings.

At 30 seconds per request, a couple dozen units should not be a problem. The exact number will depend on the server speed.

edit: I have added more code to the other thread in the link I posted above. I have the code sending a value every 30 seconds and inserting it into a database, and both are working well together. I recommend getting that working first, then go from there.

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