Web Server with W5100 device and SD-Card

A web server can be very useful in many applications to monitor statuses or to easily modify some parameters: whether stations, home automation systems, etc. Moreover, it is possible today to access it throw the Internet, using any computer or Smartphone.

This application note shows how to simply implement a web server on a very small microcontroller. It uses the W5100 Ethernet controller from Wiznet to establish the network connection and a simple SD-Card for files storage. Two DS18B20 temperature sensors will be used for demonstration.

You can download the full article and source codes using the following link:

Web Server with W5100 device and SD-Card - Revision 1.1, 2012-01-19

1. Hardware

The shield chosen for this application note is the DFRduino Ethernet Shield, and comes from DFRobot.

On this shield, the SPI interface is connected using the ICSP header of the Arduino. It needs to be corrected to use the classical SPI pins as shown on the following photos.

Two DS18B20 temperature sensors will be used for demonstration purpose and will be connected according to the following schematic.

2. Software architecture

The software architecture of the web server is given below.

The W5100 device is connected to the network. The SD-Card is used to store the pages of the web server. Both are connected to the same SPI interface. The SPI library manages the accesses to the SPI devices.

3. The web server application

The web server application uses the W5100 and FAT libraries. It simply opens a new TCP socket on port number 80 and waits for a client connection. The web server replies to the requests made by clients.

The web server architecture is very simple as shown below.

The content of the function HTTP_Server() is detailled on the following schema.

The socket status is get from the W5100 device. Three statuses are particularly interesting:

- If the socket is closed, it is opened and initialized to listen for a new client;
- When the socket is listening for clients, the web server has nothing to do;
- Finally, if a client is connected, the web server gets the data received and replies. The connection is kept alive for a few moment, permitting the client to send a new request without the need to open a new connection. The socket is closed after a small timeout.

You can notice that only a single client can be connected at the same time on the web server. It is also why the socket is closed quickly after some exchanges, in order to enable several browsers to get data from the web server.

4. DS18B20 Thermometer example

The web server application is used to display the temperature of the two DS18B20 sensors on a nice chart. A screenshot is given below.


This application note explains how to simply integrate a web server to your own applications.

The complete documentation attached to this article gives some additionnal details about the web server, particularly regarding to the way the temperature values are retrieved from the web server.