“Which one should I use?” This is a common question for anyone interested in connecting their Arduino to the internet. There is no right answer, but I’ll do my best to explain the pros and cons of each. I don’t consider myself an expert in this area, so feel free to add your opinion in the comments.
Let’s start off with some basics: A web client is any machine that requests information, while the web server stores the information.
The web client can be any device that can connect to the server and send or receive data. The client could be a PC, an iPad, a mobile phone, or an Arduino. The client just needs a way to connect to the internet. This connection could be through a browser, Ethernet, or a WiFi connection. Arduino Client code for Ethernet or WiFi can be found in the Arduino libraries.
The web server can be a PC , a hosted server, or an Arduino. The server is generally connected to the internet via Ethernet or WiFi. I prefer using a hosted server because I already have a hosted website and I can use it as a web server for my Arduino web client. Arduino Server code for Ethernet or WiFi can be found in the Arduino libraries.
If you want a stand-alone server, not necessarily connected to the internet, it’s relatively simple to install an Apache server on your PC or Mac using WAMPServer or MAMP. These servers also come with PHP and MySQL — very powerful tools in server development. These are generally called AMP servers (an acronym for Apache, MySQL and PHP).
Figure 1 below shows a network with the Arduino as a client, whereas Figure 2 shows the Arduino as a server. As you can see there isn’t much difference in the network topology. Whether your Arduino should be configured as a client or server really depends on how you intend to use it, how much data you’ll be storing, and how you want the results to be displayed.
The Arduino Server
Pros:
- The Arduino Server is usually quite simple to program and configure. You just need to assign it an IP address and connect it to the internet with an Ethernet or WiFi shield.
- It can be connected directly to your internet router making it accessible from any browser (assuming the router is configured to pass through the IP address and port assigned to the Arduino).
- You can acquire data with the Arduino and view that information from any client.
- The Arduino Server can read commands from a client to perform specific tasks.
- The Arduino Server can stand alone. It does not need to be connected to a PC except to load the sketch.
- You don’t need to know PHP, MySQL or much HTML with an Arduino Server. It can simply serve data and communicates to the client through a browser.
Cons:
- The Arduino has a limited amount of memory. After your server and application software is installed, there is not a lot of memory left for storing data.
- The Arduino Server interface is pretty much limited to displaying text.
The Arduino Client
Pros:
- The Arduino Client code is simple to load and configure. You just need to connect it to your router through an Ethernet or WiFi shield.
- You generally don’t need to worry about configuring your router.
- It’s easy to connect to and read the content of any web server.
- The content on a server can be stored data that the Arduino Client acquired and posted to the server.
- The Arduino Client can read commands from the server containing data that the Arduino can interpret in order to perform a specific task.
- The Arduino Client can stand alone. It does not need to be connected to a PC except to load the sketch.
- The server can have an unlimited amount of storage for data acquired by the Arduino Client.
- The graphical user interface on the server can be very user friendly. The possibility for displaying data from the Arduino is only limited by the web programming language you use. The same goes for generating buttons and sliders to perform tasks with the Arduino Client.
- If available on your server, you can build powerful applications and manipulate data using PHP, HTML, Java, and MySQL, Processing, Curl, or any other language that can be loaded on the server.
Cons:
- You need to know more complex programming languages to store data on the server or to create a graphical user interface.
- You need a to “refresh” the web client whenever new data is submitted.
Summary
So, if you just want to display the data from a few sensors, or trigger a few relays, and a simple text interface will work, the Arduino Server is definitely the way to go.
But if you want to store an extensive amount of data in a database or want a graphical user interface to display tables, graphs and switches, you’re probably better off using an Arduino Client to feed data to, or get the data from, an external web server.
Here are sample displays; first from a simple Arduino Server, then from a simple webpage that interfaces with my Arduino Client (I’m using WordPress and imbedding PHP code in sidebar widgets).
_________________________________
Analog and digital values. Number of queries: 17
Analog input (photocell in room) is 465
Motion Sensor = 0
Entry Door = 0
Family Room Door = 0
Shop Door = 0
Events:
Motion Sensor Count = 0
Entry Door Count = 0
Fam Room Door Count = 0
Shop Door Count = 0
________________________________