I am researching to find the best method to work with in order to control the arduino from a web interface (hosted on a web server using PHP) and also sending data from arduino to webserver and save to mySql.

2 methods which I have found that a lot use are save the data to a text file or in the url.

Which is the best or are there any better methods?

  • 1
    How much data are you sending back and forth?
    – sachleen
    Jul 7, 2014 at 16:26
  • If you are sending large amounts of data, you might consider sending it in chunks, and processing the data as you receive it. Feb 9, 2015 at 20:38
  • How are the server and the Arduino physically connected? Mar 11, 2015 at 21:19

5 Answers 5


I would suggest your best bet would be to pass messages back and forth via JSON, via Get/Post http request.

So to send data, you send a POST request (to the PHP server) with your data in JSON in the content. To get instructions, you send a GET request to the PHP server and get a contents field with JSON in it.

  • Upvote for technology invented after 1999
    – benathon
    May 11, 2015 at 12:13

Another method is to use MQTT. That's a protocol often used for embedded messaging. Find here the (one of the?) arduino client.

As a server you can install mosquitto either on the same system running the web server, or on a different one.

Than the communication logic with php will be done with mosqitto-php


  • decoupling the web server(s) from the arduino(s)
  • lightweight protocol for the arduino
  • easy interface with more applications (eg, storing data in mysql, independently of the web server, or any new in the future)


  • few more work setting up the mosquitto server.

It sounds like your first need is a way to send the bytes back and forth. A secondary question will be what that data should consist of (eg: text commands, binary commands, etc). Let's tackle the "how" first.

You have described two dynamics to the communication between server and Arduino:

  1. The arduino "sends data to the server" where PHP code will save it to MySQL; if your Arduino can be an internet client (eg: has an ethernet or wifi interface), it could use GET or POST (or PUT) HTTP calls to php code. GET is easiest, but normally GET calls shouldn't change the server, only query it -- but many people make exceptions for small devices and small amounts of data which can be encoded in the URL.

  2. The web server "controls the Arduino". Unless the Arduino sets up an internet server, it is going to have to poll the web server from time to time to find out what it should do (ie: to be controlled). It can pretty easily use a GET to fetch some text which it can interpret.

I'm guessing that HTTP will be the easiest path for communicating, because you probably understand that if you are a PHP programmer, and because it can often get through firewalls more easily if that matters; but a simple TCP socket or UDP datagrams are also possible.

Once you can send blocks of bytes between the server and the Arduino, you can focus on what those bytes should contain. That could be simple text commands, or some binary protocol, or even the MQTT protocol transactions that another answer references. You haven't given enough info to help select the protocol and format, so I'm assuming you are mostly looking at this time for the method of communicating, as described above. If you want to ask about the format of what to send back and forth once you have the data flowing, please make that a new question. You can test the basics by just sending a "Hello" text string between server and Arduino.


Buy a uart wifi such as WiFly series chip. You can control e chip via UART AT command. The chip capable of sending http post get to/from a server.

See this guide as an example



If it's not too much data, a textfile as a database should suffice, if you want something more scalable; I'm quite impressed with node.js: http://weworkweplay.com/play/raspberry-pi-nodejs/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.