Embedded Web Server
Embedded Web Server
INSTITUTE OF ENGINEERING
PULCHOWK CAMPUS
DEPARTMENT OF ELECTRONICS AND COMPUTER
ENGINEERING
A
FINAL YEAR PROJECT REPORT
ON
“INTERNET BASED HOME MONITORING AND CONTROL USING
EMBEDDED WEB SERVER”
By:
Arun Paudyal (066bex404)
Bandana Sharma (066bex407)
Kashiram Acharya (066bex416)
Sapin Bajracharya (066bex439)
Lalitpur, Nepal
August, 2013
TRIBHUVAN UNIVERSITY
INSTITUTE OF ENGINEERING
PULCHOWK CAMPUS
A
FINAL YEAR PROJECT REPORT
ON
“INTERNET BASED HOME MONITORING AND CONTROL USING
EMBEDDED WEB SERVER”
By:
Arun Paudyal (066bex404)
Bandana Sharma (066bex407)
Kashiram Acharya (066bex416)
Sapin Bajracharya (066bex439)
The project entitled “Internet Based Home Monitoring and Control Using Embedded Web
Server” submitted by Arun Paudyal (066bex404), Bandana Sharma (066bex407), Kashiram
Acharya (066bex416), Sapin Bajracharya (066bex439) in partial fulfilment of the
requirements for the Bachelor’s degree in Electronics & Communication Engineering, has
been accepted as a bona fide record of the work carried out in our department.
Head of Department
Engineering
i
PAGE OF APPROVAL
The undersigned certify that they have read, and recommended to the Institute of Engineering
for acceptance, project entitled “Internet Based Home Monitoring and Control Using
Embedded Web Server” submitted by Arun Paudyal (066bex404), Bandana Sharma
(066bex407), Kashiram Acharya (066bex416), Sapin Bajracharya (066bex439) in partial
fulfilment of the requirements for the Bachelor’s degree in Electronics & Communication
Engineering.
________________________________ ________________________________
Internal Examiner,
Supervisor,
Mr. Jitendra Kumar Manandhar, Mr. Uttam Mali,
________________________________
________________________________
Project Coorinator ,
External Examiner,
Aman Shakya, PhD.
Mr. Om Bikram Thapa,
Deputy Head of Department
Vianet Communications Pvt. Ltd.
Department of Electronics and Computer
Lalitpur
Engineering
Pulchowk Campus, IOE.
DATE OF APPROVAL:
ii
COPYRIGHT
The authors have agreed that the Library, Department of Electronics and Computer
Engineering, Pulchowk Campus, Institute of Engineering may make this report freely
available for inspection. Moreover, the author has agreed that permission for extensive
copying of this project report for scholarly purpose may be granted by the supervisors who
supervised the project work recorded herein or, in their absence, by the Head of the
Department wherein the project report was done. It is understood that the recognition will be
given to the author of this report and to the Department of Electronics and Computer
Engineering, Pulchowk Campus, Institute of Engineering in any use of the material of this
project report. Copying or publication or the other use of this report for financial gain without
approval of to the Department of Electronics and Computer Engineering, Pulchowk Campus,
Institute of Engineering and author’s written permission is prohibited. Request for permission
to copy or to make any other use of the material in this report in whole or in part should be
addressed to:
Head of Department
Lalitpur, Nepal
iii
ACKNOWLEDGEMENT
We are highly indebted to the Department of Electronics and Computer Engineering for
providing us an opportunity to employ our theoretical knowledge into practice in the form of
our final year project. This project has been a matter of great enthusiasm for us students
because we learned to use the various knowledge that we have learnt past few years at
Pulchowk Campus.
We are highly thankful to our project supervisor, Mr. Jitendra Kumar Manandhar for his
constant encouragement. We are equally indebted to our seniors Mr. Bibek Joshi, Mr.
Sandeep Manandhar and Mr. Vishal Gewali for clearing our doubts in various stages during
projects and providing the technical assistance. We would also like to thank our class mates
for supporting us. Similarly, we are equally thankful to Robotics Club and our juniors for
providing the various machineries and tools and sound working atmosphere.
Last but not the least we would like to thank all those who are involved in guiding us through
this project.
iv
ABSTRACT
The objective of this project was to design and build an embedded HTTP server using an AVR
microcontroller chip. The web server required the implementation of the interface with
Ethernet as well the internet like TCP/IP. This embedded web server is able to serve small,
static web page. The HTML code for the web page is kept in the program for the AVR
microcontroller. So, implementing the web server we were able to control the appliance
connected to the web server remotely via internet and check the status of the controlled
appliance.
The task of the monitoring and controlling the home appliances was obtained by writing the
TCP/IP stack for the web server. The ENC28J60 module provided the Ethernet interface
between the web server and the internet. The control information from the user via a web page
was passed up to the appliances/devices through the RF communication between the master
and slave controllers. The overall hardware design was made modular making the interface for
the web server, RF modules and the relay interfacing for the devices.
Since the capabilities of the embedded web server are nowhere near that of a regular server
computer, its small size and relatively low cost makes it more practical for some applications.
The web server was built, tested to work, and the web servers were successful in receiving
control information from the user and in turn control the desired devices. The status of the
controlled devices can be seen via the web page as well.
v
MOTIVATION
The term “Internet of Things” (hereafter referred as IoT) is the real motivation for us in
carrying out this project. The term IoT was first proposed by British technical pioneer at MIT.
IoT refers to the uniquely identifiable objects and their virtual representation in the internet
like structure.
So, we were keen in developing something as our major project that could represent or address
the discrete components in our day to day life by connecting them with the internet. The
concept of IoT has become so broad that it has been implemented in various ways.
Preliminarily, this concept was just limited in using the RFID tags for facilitating routing,
inventorying, and loss prevention. Along time, IoT has been used more extensively for
surveillance, security, healthcare, transport, food safety, document management etc. In present
day, IoT has been implemented in many applications like locating people and everyday
objects, tele-operation and tele-presence (ability to monitor and control the distant objects).
After going through these varied implementations of IoT, we were really clicked in doing
something that implements the IoT. But we were still confused till then how to implement the
IoT. While going through the various sites during our research phase, we came across a
hardware implementation known as the Embedded Web Server. This hardware used the
internet protocols like TCP/IP or UDP or ARP and can communicate with the real world
applications through the internet via a static (simple) web page. After learning about the IoT
and Embedded Web Server, we were really motivated in carrying out project implementing
the IoT and the web server. So, we decided that we will control various home appliances using
our web server. Further, we also made the provision of monitoring the status of the controlled
home appliances.
Besides, there is another large community funded professional project in USA carried out by
Physical Graph Corporation known as “Smart Things” that motivated us as well. In Smart
Things, the devices to be controlled are made smart by making the provision of internet
connectivity and other relevant necessities. So, the day to day objects like power sockets,
vi
doors, etc turned smart and they can be directly controlled via internet remotely through web
page or android or iOS application. The Smart Things project has been praised by many
corporate houses like CNN, Forbes, Readers’ Digest, Discovery Channel, Engadget, etc.
So, we learned a lot about the Internet of Things, Smart Things and Embedded Web Server
during the initial research phase. Therefore, while selecting the project, we were really
fascinated in carrying out controlling something remotely via the internet. We were really
excited by the Internet of Things, the professional project Smart Things, and the hardware
implementation Embedded Web Server. So these really motivated us in carrying out this
project. And also this kind of project has never been done previously in Nepal, and this
additionally motivated us in carrying out this project at any cost.
vii
Table of Contents
DEPARTMENT ACCEPTANCE ............................................................................................... i
PAGE OF APPROVAL.............................................................................................................. ii
COPYRIGHT............................................................................................................................. iii
ACKNOWLEDGEMENT ......................................................................................................... iv
ABSTRACT................................................................................................................................ v
MOTIVATION.......................................................................................................................... vi
LIST OF ABBREVIATIONS................................................................................................... xv
1. INTRODUCTION .................................................................................................................. 1
2. OBJECTIVES......................................................................................................................... 2
viii
4.4.1 Need for wireless communication ............................................................................ 17
5.2.3 USB-ASP.................................................................................................................. 23
5.4.5 KiCAD...................................................................................................................... 23
ix
6.2 AVR Atmega328 microcontroller................................................................................... 26
6.4 Router.............................................................................................................................. 28
6.5 SD Card........................................................................................................................... 28
6.7 Relays.............................................................................................................................. 30
7. METHODOLOGY ............................................................................................................... 31
8. TESTING.............................................................................................................................. 42
x
11. PROBLEMS FACED AND SOLUTIONS USED............................................................. 47
xi
LIST OF TABLES
Table 4. 1: OSI Reference Model ............................................................................................... 8
LIST OF FIGURES
Figure 4. 1: LAN Structure ......................................................................................................... 5
Figure 4. 3: IP Header............................................................................................................... 11
xii
Figure 6. 8: 5 pin SPDT relay ................................................................................................... 30
xiii
Figure C. 1: PCB layout of RFM12 module with Atmega8 controller..................................... 63
Figure C. 3: PCB layout of Atmega644 interface for embedded web server ........................... 64
Figure D. 3: Relay Interface Module with RFM12 (slave) and Atmega8 (slave) .................... 66
xiv
LIST OF ABBREVIATIONS
ARP Address Resolution Protocol
xv
GHz Giga Hertz
I/O Input/output
IP Internet Protocol
xvi
LAN Local Area Network
MSTR Master
RF Radio Frequency
RF Radio Frequency
RFM RF Module
SD Secure Digital
xvii
SPI Serial Peripheral Interface
xviii
1. INTRODUCTION
In today’s world, everyone is busy and every second counts. Therefore, it is hard for
people to manage time for their every works. Technology has made a huge leap over years
and people are always keen to complete their works by the use of minimum amount of time
and money that is practicable. People have been more bounded to their works thereby
resulting a scarcity of time for household and other domestic works. A system that could
assist individual in controlling and monitoring household and other relevant activities at
their convenience would contribute in better utilization of their valuable time and
resources.
We are going to control household devices like lights, ON/OFF control of simple
appliances like water pump, microwave oven, etc. Beside we can use our approach for
monitoring purposes like state of the controlled devices, temperature monitoring, and
status of doors/windows and so on.
1
2. OBJECTIVES
1. To design and implement remote home control and monitoring system.
2. To implement communication and control through internet using embedded web
server.
3. To design the communication system to be widely and easily accessible.
4. To design a low power and low cost system.
5. To build the proposed system within the predetermined time frame using minimum
possible cost.
2
3. LITERATURE REVIEW
While going through the relevant literatures, we got the information and knowledge on the
working of the embedded web server. Though there are computer based web server
prevalent, but due to the robustness and the many advantages in contrast to the computer
based web server many projects and research were carried out focusing the embedded web
server technology. Most of the researchers and project doers have used the ATMEL
microcontroller for their embedded web server projects. Talking about the projects and
research carried out implementing the embedded web server technology in other countries,
there are few to mention like Embedded Web Server (Bachelor level thesis) by Arturus
Lukosius at Vilnius Gediminas Technical University; Lithuania [2] , Embedded Web
Server based Remote Monitoring System by Tan Jing Hong at Universiti Teknikal
Malaysia [3], Embedded ATMEL HTTP Server by Jeremy Tzeming Tam at Cornell
University USA [4], AVR Microcontroller based Web Server by Vishram Mishra at Cochin
University of Science and Technology, India. [5]
Embedded Web Server was chiefly concerned with the creation of the embedded web
server. This bachelor level thesis had the details for the creating the embedded web server
by writing the TCP/IP HTTP protocol for the AVR microcontroller by using the Ethernet
interface.
Embedded Web Server based Remote Monitoring System, design and development of an
embedded web server using 8-bit microprocessor and TCP/IP Ethernet connection to be
used for office/home automation applications has been carried out. In this project, the
controller developed is based on Rabbit microprocessor and its core module model RCM
3700. Controlling the motor and others I/O like sensor and also alarms through a website
base controller is the primary task. Showing the I/O data through RCM 3700 with the
TCP/IP Ethernet connection to personal computer in webpage is another feature of this
project. The webpage and firmware has been done in Dynamic C programming language.
Embedded ATMEL HTTP Server is also focused in designing and building an embedded
HTTP server using a microcontroller chip. The web server in this project required the
3
implementation of the interface with Ethernet as well as several internet protocols such as
TCP/IP and ARP. This embedded web server is able to serve small, static web pages as
well as perform certain useful laboratory lab functions such as displaying the current
temperature read by the microcontroller from a thermometer, on the webpage. The web
server was built in this project has been successfully tested and a temperature reporting
feature has been added to it.
In AVR Microcontroller based Web Server, implementation of a web server over an AVR
microcontroller has been done. The web server can host a small web page that will be
stored in the microcontroller’s Flash memory. Through the interface of the web page, a
user can control the devices attached to the microcontroller.
After going through the several above literature in the web server, we got more
information in implementing the web server. We got the knowledge about the internet
protocol like TCP/IP or ARP that are needed to construct the web server. We also got to
know about the Ethernet interface that acts as the bridge between the web server and the
internet. The simple interfacing and other tasks can be done via the web server and the
overview can be viewed from the static web page hosted in the program memory of the
microcontroller itself.
4
4. BACKGROUND THEORY
A local area network (LAN) is a computer network covering a small geographic area, like
a home, office, or group of buildings. The defining characteristics of LANs, in contrast to
Wide Area Networks (WANs), include their much higher data transfer rates, smaller
geographic range, and lack of a need forleased telecommunication lines. Ethernet over
unshielded twisted pair cabling, and Wi-Fi are the two most common technologies
5
currently, but ARCNET, Token Ring and many others have been used in the past.
Although switched Ethernet is now the most common data link layer protocol and IP as a
network layer protocol, many different options have been used, and some continue to be
popular in niche areas. Smaller LANs generally consist of a one or more switches linked to
each other - often with one connected to a router, cable modem, or DSL modem for
Internet access. Larger LANs are characterized by their use of redundant links with
switches using the spanning tree protocol to prevent loops, their ability to manage differing
traffic types via quality of service, and to segregate traffic via VLANing. LANs may have
connections with other LANs via leased lines, leased services, or by 'tunneling' across the
Internet using VPN technologies.
6
4.1.3 TCP/IP protocol (TCP/IP Stack)
The Internet protocol suite is the set of communications protocols that implement the
protocol stack on which the Internet and most commercial networks run. It has also been
referred to as the TCP/IP protocol suite, which is named after two of the most important
protocols in it: the Transmission Control Protocol (TCP) and the Internet Protocol (IP),
which were also the first two networking protocols defined. The Internet Protocol suite—
like many protocol suites—can be viewed as a set of layers. Each layer solves a set of
problems involving the transmission of data, and provides a well-defined service to the
upper layer protocols based on using services from some lower layers. Upper layers are
logically closer to the user and deal with more abstract data, relying on lower layer
protocols to translate data into forms that can eventually be physically transmitted. The
TCP/IP reference model consists of four layers. The TCP/IP flow that I use for my PSM is
from the application layer (HTTP) then the data will send to the transport layer (TCP) and
go to the network (IP) and lastly go to the data link (the Ethernet).
7
4.1.3.1 Network Protocol Layers
Computers on a network communicate in agreed upon ways called protocols. The
complexity of networking protocol software calls for the problem to be divided into
smaller pieces. A layering model aids this division and provides the conceptual basis for
understanding how software protocols together with hardware devices provide a powerful
communication system.
8
The 7-layer model has been revised to the 5-layer TCP/IP reference model to meet the
current needs of protocols.
IP Header Figure shows the format of an IP datagram. The normal size of the IP header is
20 bytes, unless options are present. The most significant bit is numbered 0 at the left, and
the least significant bit of a 32-bit value is numbered 31 on the right. The 4 bytes in the 32-
bit value are transmitted in the order: bits 0 - 7, then bits 8 – 15 and so on. This is called
Big-Endian byte ordering, which is the byte ordering required for all binary integers in the
TCP/IP headers as they traverse a network. This is called the network byte order.
Figure 4. 3: IP Header
11
Header length The header length is the number of 32-bit words (4 bytes per word) in the
header, including any options. This limits the header length to 60 bytes.
Type of Service (TOS) The field, (TOS) is composed of a 32-bit precedence field (which
is currently ignored), 4 TOS bits, and an unused bit that must be 0. The 4 TOS bits are:
minimize delay, maximize throughput, maximize reliability and minimize monetary cost.
Only 1 of these bits can be turned on. If all 4 bits are 0, it implies normal service
Total Length This is the total length of the IP datagram in bytes. Using this field and the
header length field, we know where the data portion of the IP datagram starts and its
length. Since this is a 16-bit field, the maximum size of an IP datagram is 65535 bytes.
Identification This field uniquely identifies each datagram sent by a host. It normally
increments by one each time a datagram is sent.
Time to Live sets an upper limit on the number of routers through which datagram can
pass. It limits the lifetime of the datagram. It is initialized by the sender to some value
(Often 32 or 64) and decrements by one in every router that handles the datagram. Then
this field reaches 0, the datagram is discarded, and the sender is notified with an ICMP
message. This prevents the packet from getting caught in eternal routing loops.
Header Checksum is calculated over the IP header only. It does not cover any data that
follows the header. ICMP, UDP and TCP all have a checksum in their own headers to
cover their own header and data. Every IP datagram contains the source IP address and the
destination IP address. These are 32-bit values.
The Option Field This is a variable-length list of optional information for the datagrams.
The options are rarely used and not all hosts and routers support the option.
12
4.2 Embedded Web Server
Small systems to large systems may provide an interface and control via the onboard
switches or via IR or RF based remote control. But what if the User who wants to control a
device, is out of reach of the device or is at another part of world. There are other methods
developed to control the devices remotely, but each technique requires some new
implementations to be done. Here we use the existing technique of Internet Web based
HTTP protocol with TCP/IP protocol suite to control the devices. Embedding a web
application in a system is termed as embedded web server. Suppose an Embedded Web
Server is embedded in several units in a house as shown in figure 1.1. Every server is
connected to the network. A computer located a home as on figure controls all devices and
can receive requests from other computers on the Internet. The web server is identified by
its unique IP address and can be controlled remotely from anywhere in the world. A
computer located in an office may send a request to turn off the Refrigerator located at
home via Internet. The web server will be running an HTTP application through the
interface of which the user can control and monitor the devices.
14
Figure 4. 5: Interaction between single slave and single master
An ATmega 32 Microcontroller uses SPI (Serial Peripheral Interface) to effectively
communicate with the Ethernet controller ENC28J60. The usage of SPI provides serial
communication thus eliminating large number of lines used for data and addressing
purpose. The SPI allows high-speed synchronous data transfer between the AVR and
peripheral devices or between several AVR devices. On most parts the SPI has a second
purpose where it is used for In System Programming (ISP). The interconnection between
two SPI devices always happens between a master device and a slave device. Compared to
some peripheral devices like sensors which can only run in slave mode, the SPI of the
AVR can be configured for both master and slave mode. The mode the AVR is running in
is specified by the settings of the master bit (MSTR) in the SPI control register (SPCR).
Special considerations about the SS pin have to be taken into account.
The master is the active part in this system and has to provide the clock signal a serial data
transmission is based on. The slave is not capable of generating the clock signal and thus
cannot get active on its own. The slave just sends and receives data if the master generates
the necessary clock signal. The master however generates the clock signal only while
sending data. That means that the master has to send data to the slave to read data from the
slave. The interaction between a master and a slave AVR is shown in the figure
16
RF current can easily ionize air, creating a conductive path through it. This
property is exploited by "high frequency" units used in electric arc welding, which
use currents at higher frequencies than power distribution uses.
Another property is the ability to appear to flow through paths that contain
insulating material, like the dielectric insulator of a capacitor.
When conducted by an ordinary electric cable, RF current has a tendency to reflect
from discontinuities in the cable such as connectors and travel back down the cable
toward the source, causing a condition called standing waves, so RF current must
be carried by specialized types of cable called transmission line.
Wireless networks are wire free, relying on radio waves to transmit data instead of
cables. Wires have a tendency to get tangled, lost or damaged over time. Wireless
devices eliminate this concern.
Efficiency - improved communications leads to faster transfer of information
within businesses and between partners/customers.
You are rarely out of touch - you don't need to carry cables or adaptors in order to
access office networks.
Reduced costs - relative to 'wired', wireless networks are, in most cases, cheaper to
install and maintain.
17
equipment operating in these bands must tolerate any interference generated by ISM
equipment, and users have no regulatory protection from ISM device operation.
Despite the intent of the original allocations, and because there are multiple allocations, in
recent years the fastest-growing uses of these bands have been for short-range, low power
communications systems. Cordless phones, Bluetooth devices, near field communication
devices, and wireless computer networks all use frequencies allocated to low power
communications as well as ISM.
4.5 RF Communications
In our daily life, a communication link between two devices becomes essential. This
communication may be wired or wireless. If two devices we are dealing with are close to
each other (like a MCU and a Memory) then a wired link is preferred. However in many
situations two devices we are dealing with are reasonably far apart. In such a case a
wireless link is preferred.
18
Wide range, from few meters to millions of kilometers (Can be Used to control
Robots in Mars)
Does not require two devices to be in line of sight.
Can cross many obstacles
Circuits can be complicated and costly.
The RF communication is carried out via RF module. The module consists of the
transmitter and the receiver circuitry. The transmitter is fed with the data from one
controller and the receiver receives the data from the transmitter. The general transmission
of the data between two controllers using RF communication can be depicted from the
following figure.
20
A low START bit that indicates beginning of the data to be transferred.
8 data bits, denoting the actual data being transferred.
An optional parity bit for either odd or even parity.
4.7 I2C
I2C is the interface type. This one originated with Philips/Signetics, whose 8XC528 (8051
family) is an example of a microcontroller with an I2C interface built-in. The I2C interface
requires just two signal lines, plus a common ground. Serial Data/Address (SDA) is a
bidirectional line that requires open-collector or open-drain outputs. Serial Clock (SCL) is
the clock. Instead of a chip-select line, the master sends a slave address on SDA.
21
5. TOOLS AND IDE USED
5.2.1 WinAVRTM
5.2.3 USB-ASP
USB-ASP is an open source AVR ISP programmer. It is supported by AVR-DUDE AVR
programmer and can program all AVR devices supporting SPI ISP programming mode.
5.4.5 KiCAD
KiCAD is an open source software suite for electronic design automation. It facilitates the
design of schematics for electronic circuits and their conversion to PCBs (printed circuit
board) design. KiCAD uses an integrated environment for all of the stages of the design
process schematic Capture, PCB layout, Gerber file generation/visualization and library
editing. KiCAD has a built-in basic auto router. Tools exist within the package to create
artwork and 3D view of the PCB. KiCAD is also a cross platform.
23
5.3 Libraries Used
24
6. MAJOR COMPONENTS USED
6.1 AVR Atmega644 microcontroller
The high-performance, low-power Atmel 8-bit AVR RISC-based microcontroller
combines 64KB ISP flash memory with read-while-write capabilities, 2KB EEPROM,
4KB SRAM, 32 general purpose I/O lines, 32 general purpose working registers, real time
counter, three flexible timer/counters with compare modes and PWM, 2 USARTs, byte
oriented 2-wire serial interface, 8-channel/10-bit A/D converter with optional differential
input stage with programmable gain, programmable watchdog timer with internal
oscillator, SPI serial port, JTAG (IEEE 1149.1 compliant) test interface for on-chip
debugging, and six software selectable power saving modes. The device operates between
2.7-5.5 volts. By executing powerful instructions in a single clock-cycle, the device
achieves throughputs approaching 1 MIPS per MHz, balancing power consumption and
processing speed.
25
6.2 AVR Atmega328 microcontroller
The high-performance Atmel picoPower 8-bit AVR RISC-based microcontroller combines
32KB ISP flash memory with read-while-write capabilities, 1024B EEPROM, 2KB
SRAM, 23 general purpose I/O lines, 32 general purpose working registers, three flexible
timer/counters with compare modes, internal and external interrupts, serial programmable
USART, a byte-oriented 2-wire serial interface, SPI serial port, a 6-channel 10-bit A/D
converter (8-channels in TQFP and QFN/MLF packages), programmable watchdog timer
with internal oscillator, and five software selectable power saving modes. The device
operates between 1.8-5.5 volts. By executing powerful instructions in a single clock cycle,
the device achieves throughputs approaching 1 MIPS per MHz, balancing power
consumption and processing speed.
26
6.3 ENC28J60 Ethernet Controller
Microchip's ENC28J60 is a 28-pin, 10BASE-T stand alone Ethernet Controller with on
board MAC & PHY, 8 Kbytes of Buffer RAM and an SPI serial interface. With a small
foot print package size the ENC28J60 minimizes complexity, board space and cost. Target
applications include VoIP, Industrial Automation, Building Automation, Home Control,
Security and Instrumentation. The ENC28J60 is a stand-alone Ethernet controller with an
industry standard Serial Peripheral Interface (SPI™). It is designed to serve as an Ethernet
network interface for any controller equipped with SPI. The ENC28J60 meets all of the
IEEE 802.3 specifications. It incorporates a number of packet filtering schemes to limit
incoming packets. It also provides an internal DMA module for fast data throughput and
hardware assisted IP checksum calculations. Communication with the host controller is
implemented via two interrupt pins and the SPI, with data rates of up to 10 Mb/s. Two
dedicated pins are used for LED link and network activity indication.
27
6.4 Router
A router is a device that forwards data packets between computer networks, creating an
overlay internetwork. A router is connected to two or more data lines from different
networks. When a data packet comes in one of the lines, the router reads the address
information in the packet to determine its ultimate destination. Then, using information in
Figure 6. 5: Router
its routing table or routing policy, it directs the packet to the next network on its journey.
Routers perform the "traffic directing" functions on the Internet. In our project we have
used the local network of the router in order to send the command to the controlled
devices. The network of the router is also fed to the ENC28J60 module.
6.5 SD Card
Secure Digital or (SD) is a non-volatile memory card format for use in portable devices,
such as mobile phones, digital cameras, GPS navigation devices, and tablet computers. The
Secure Digital standard is maintained by the SD Card Association (SDA). SD technologies
have been implemented in more than 400 brands across dozens of product categories and
more than 8,000 models. The Secure Digital format includes four card families available in
three different form factors. The four families are the original Standard-Capacity (SDSC),
the High-Capacity (SDHC), the extended-Capacity (SDXC), and the SDIO, which
combines input/output functions with data storage. The three form factors are the original
size, the "mini" size, and the "micro" size. There are many combinations of form factors
and device families. Electrically passive adapters allow the use of a smaller card in a host
28
Figure 6. 6: SD Card
device built to hold a larger card. SD card is used in our project in order to store the
database of all the monitoring and controlling actions
29
6.7 Relays
A relay is an electrically operated switch. Many relays use an electromagnet to operate a
switching mechanism mechanically, but other operating principles are also used. Relays
are used where it is necessary to control a circuit by a low-power signal (with complete
electrical isolation between control and controlled circuits), or where several circuits must
be controlled by one signal. We have used relay as a switch to control the states (ON/OFF)
of the devices.
30
7. METHODOLOGY
Master Unit
SD Card
Embedded
Web Server
RF Module RF Module
Secondary Secondary
Controller Controller
31
7.3 Hardware Implementation
Hardware-wise, the main components of the system can be divided into following:
32
7.3.2 RF Interfacing Modules
The RF interfacing modules are small modules interfacing one ATMEGA8 microcontroller
and one RFM12/B module. The Module contains Socket for attaching RFM12/B module.
The module also has fixed i/o pins of the ATMEGA8 microcontroller available to be
interfaced outside to act as a fully functional slave unit in the system, as well as UART
pins for interfacing with another master controller to act as a wireless link. The RFM12B
modules, requiring <3.6V Vcc, the wireless modules are run at 3.3V, with ATMEGA8
running at 8 MHz to keep within recommended specifications.
33
7.3.3 Switching modules
The Switching modules are relay control modules that switch on and off to control the
attached devices. Each SPDT relay controls a single device to be attached to the system.
The relays are driven by ULN2003 Darlington array.
34
i. TCP/IP Stack
ii. SD Card + FAT
iii. UART
iii. Main Operating Code
The TCP/IP stack contains all required functions and modules for the web server, including
low level drivers for ENC28J60 Ethernet Controller (enc28j60.h, enc28j60.c), TCP/IP
stack implementation (ip_arp_udp_tcp.h, ip_arp_udp_tcp.c, net.h), and helper functions for
http server (websrv_help_functions.h, websrv_help_functions.c) such as url
encoding/decoding and string searching. The web server is implemented as HTTP/1.0
server (without keep alive connections), making the implementation simpler in terms of
memory requirement for use in low memory embedded systems.
SD card is interfaced through its available SPI mode for sake of simplicity in embedded
design. The card is accessed through FAT16/32 filesystem through the ‘fatfs’ embedded
file system library. This section contains all necessary code for FAT32 filesystem access
on SD card including low level SD/SPI access functions(mmc.c) and FAT filesystem
access functions(ff.h, ff.c, diskio.h).
Due to requiring 3.3V signal levels (while ENC28J60 tolerated 5V signals), rather than
sharing SPI bus, SD interface was placed on GPIO pins using software SPI (part of low
level driver in mmc.c).
The UART section comprises of code for handling UART (Serial Communcation)
functions. It includes uart.h and uart.c. It is an interrupt based UART implementation with
circular buffers for both RX and TX. This implementation allows efficient and error free
usage of hardware UART with minimal delay and impact on the other code sections. The
UART is used for communication with the RF interface module, serving as communication
link between the web-server controller (master) and the slave controllers operating the
remotely controlled devices.
35
The main operation code comprises all the other code sections not included in the above
sections. Chiefly, the code in main.c, which comprises the initialization codes as well as
the infinite loop for the system. It also forms the request-response handling part of the http
server and utilizes modules from the TCP/IP stack section. The basic code flow of this
section (ie. main code) is illustrated in the flowchart below.
Initialization
HTTP No
request
received?
Yes
HTTP No
request Display Error Page
valid?
Yes
Is action No
requested? Send UART
message to RFM
module
Yes
Display Page
Is Yes
message Update local Status
received? Database
from RF?
36
No
Here, the RF interface connected through UART link acts as a bridge between the web-
server and the local RF network, relaying messages passed from UART to RF and vice
versa.
The slave devices periodically broadcast their status (including status of connected inputs
and outputs). The web-server controller listens to these messages and stores the latest
status information in its memory. When displaying the status page, the received status from
this memory is displayed.
The periodic status messages also inform the sever of the unavailability of any slave device
if message from the device is not received in a given time frame. The web-server then
displays the status accordingly when it serves the status page.
The received Status messages are also logged in the SD card, along with timestamp, to
serve as device log and usage history.
37
7.4.2 RF master on ATMEGA8
The code for the RF master lies in the ATMEGA8 controller on the RF interface module
connected to the web-server controller through UART. The main purpose of this module is
to act as link between the web-server controller (through UART) and the local RF network
(through RFM12/B modules). Appropriately, it consists of the following sections.
i. RFM 12/B driver
ii. UART
iii. Main control loop
The RFM12/B module is connected to the controller through SPI. The low-level driver
comprises of the SPI link and hardware register access (rfm12_spi.c, frm12_hw.h,
rfm12_core.h). The high level interface consists of packet generation, transmission and
reception. For the sake of reliable data transmission and reception, data is sent in packets
of fixed structure composed of
i. Prologue (0xAAAA)
ii. Sync Pattern (0x2DD4)
iii. Header (type, length, header checksum)
iv. ‘length’ bytes of data
Prologue and Sync Pattern are RFM12/B specific portions, necessary for synchronization
of internal clocks on the modules as well as confirmation of valid data reception. The
message header provides length for accurate reception and checksum for error detection.
Messages with checksum failure are ignored by the system.
The UART section comprises of code for handling UART (Serial Communication)
functions. It includes uart.h and uart.c. It is an interrupt based UART implementation with
circular buffers for both RX and TX. This implementation allows efficient and error free
usage of hardware UART with minimal delay and impact on the other code sections. The
UART is used for communication with the web-server controller.
38
The main section (main.c) of the code contains the initialization section and infinite loop
section as shown in the flowchart below.
The initialization section comprises of initialization codes for the i/o ports, UART and
RFM module.
The main loop cycles between 3 tasks as shown below.
As this module acts as message relay between the RF and UART, it listens for received
UART messages, and transmits them through RF.
It checks for received RF messages and transmits them through UART to the web-server
controller.
Finally, it calls the RFM service routines that handle the actual low-level transmission and
reception of queued RF data.
Initialization
Message No
received Send RFM message
from
UART?
Yes
Message No
received Send UART message
from RF?
Yes
Complete Queued
RF tasks
Prologue and Sync Pattern are RFM12/B specific portions, necessary for synchronization
of internal clocks on the modules as well as confirmation of valid data reception. The
message header provides length for accurate reception and checksum for error detection.
Messages with checksum failure are ignored by the system. The main control loop consists
of an initialization section and an infinite loop as shown below.
The initialization section comprises initialization routines for I/O ports, timers and
RFM12/B module and driver.
40
In each pass of the infinite loop, the following tasks are performed.
Initialization
1 Second No
Timer Send Status message
Overflow?
Yes
Yes
Complete Queued
RF tasks
41
8. TESTING
During the hardware and software implementation, various kinds of testing were carried
out. The testing of the prototype module and the RF interface module were carried out
during this phase.
42
8.2 Testing of RFM12 Module
We have used the RFM12 module in order to transmit the control signals between the
master and the slave controller units. The RFM working of the RFM12 module was tested
using the breadboard circuitry and later with Atmega328 interface.
43
9. PROJECT APPLICATION
Previously, it has been mentioned that this project is the outcome of the motivation in
implementing the Internet of Things (referred IoT hereafter). So, instead of just completion
of the Embedded Web Server, our project is more concerned about the implementing the
term IoT. In fact this project is implementation of the IoT. Building the embedded web
server is a part in achieving the implementation for IoT.
a) Controlling the normal device by interfacing it with the embedded web server unit
b) Controlling the normal device after making it smart i.e. upgrading the normal
device with control ports and necessary parameters.
In our project, we have implemented the first ways more efficiently and also made a
provision for the second way. Thus, this project more applies in controlling the general
devices by interfacing it with the relay driver unit and ultimately to the embedded web
server unit.
This project successfully implements the IoT concept and is able to control the different
devices and appliances remotely via the internet. The devices to be controlled are linked
with the relay driver unit. The relay driver unit is further linked with the “slave controller
unit”. The slave controller unit consists of the RF module and the slave controller unit. The
slave controller unit communicates with the “master controller unit”. The master controller
unit consists of the embedded web server and the RF module. The control signal for
controlling the devices obtained through the internet is exchanged between the master and
slave controller units via RF communication. Thus the device is finally controlled via the
command from the slave controller that finally drives the relay connected to that device
and ultimately the device is controlled. Here control refers to the ON/OFF control of the
corresponding devices.
So, this project has vast applications according to the scenario to be used. The project finds
its application in controlling the things that utilizes the concept of IoT. We have restricted
44
our project just in home monitoring and control. But this project can be extensively used in
other areas as well. All other areas that require the internet based control come under the
application of this project.
This project solely finds its application any areas that implement the IoT. Naming few, the
applications of this project are listed below:
Domestic and Home Automation: controlling of the home appliances and devices
(Smart Home)
Industrial control: controlling the machineries in the industries
Monitoring: checking the status of the controlled devices
Smart lightning system in streets and public places
Monitoring and optimization of performance in the solar plants
Perimeter Access Control: Access control to restricted areas and detection of
people in non-authorized areas.
Smart Agriculture, etc.
45
10. PROJECT ADVANTAGES
Home monitoring and control has been carried out and implemented in various ways over
past few years. Being the project relating to home monitoring and control, this project has
the following advantages:
Low Cost: The project implements the low cost AVR HTTP web server for home
monitoring and control purposes. The use of embedded server makes it cheaper in contrast
to other computer based monitoring and control systems.
Low Power: This is one of the power friendly projects. The total power consumption of the
system is less than 5 watts. The system can be run 24/7 with the help of inexpensive
battery backup system.
Platform Independent: The monitoring and control of the appliance can be controlled via
any internet enabled devices (regardless the platform, operating system they use) and
through any desktop or mobile internet browsers.
Suitable for varied locations: There is sound internet connectivity available in various part
of the Nepal, and since our web page is simple static one, the control and monitoring action
can be carried out through the GPRS/EDGE networks as well. So our project seems fit for
the varied locations throughout the country.
Time Saving: People nowadays are always in rush. So, with this project in hand people
now can monitor and control their home appliances at their convenient time when they are
at work, in vehicles, etc.
46
11. PROBLEMS FACED AND SOLUTIONS USED
Memory: Previously we have used Atmega328 microcontroller for our project.
This controller has 32KB ROM and 2KB RAM. This proved insufficient for us in
storing the code for the embedded web server and the FAT system code. So, this
problem was solved using the bigger Atmega644 microcontroller. This controller
has double ROM and RAM specifications compared to the Atmega328.
Router: To test the working of our embedded web server, we used the local
network of the Router at the Robotics Club. There was problem with router and we
could not identify it. So, we used the router at our home to test the embedded web
server.
RFM12 Communication Error: There was an issue with the reliability of the data
received from the RF module. The data received was found to be erroneous and
was a big problem to us. This problem was minimized implementing the checksum
and carrier sense methods.
47
11. RESULT
After implementing the above hardware the embedded web server worked fine. The
control information can be given via the static web page. The control information passed to
the slave controller unit via the master controller unit. The RF communication worked
satisfactorily. The device to be controlled was interfaced with the relay interfacing board.
The ON/OFF control of the device from the web page and its status monitoring from the
web page was successfully accomplished.
48
13. BIBLOGRAPHY
1) “Computer Networks” ; Tanenbaum, Andrew S.; 4th edition; Pearson Inc ; 2007
[book]
2) “Embedded Web Server” ; Lukosius, Arturas ; Vilnius Gediminas Technical
University; [bachelor level thesis]
3) “An Embedded Web Server-Based Remote Monitoring System” ; Hong, Tan Jin ;
Universiti Teknikal Malaysia Melaka [final year project report]
4) “Emebdded ATMEL HTTP Server” ; Tzeming Tan, Jeremy ; Cornell University ;
[final year project report]
5) “AVR microcontroller based embedded web server”; Mishra, Vishram ; Cochin
University of Science and Technology (School of Engineering) ; [final year project
report]
6) “Learning AVR” ; http://www.embedded-creations.com/projects/uipAVR.html ;
[online]
7) “An AVR microcontroller based Ethernet device” ;
http://tuxgraphics.org/electronics/200606/article06061.shtml ; [online]
8) “HTTP/TCP with an atmega88 microcontroller (AVR Web Server)” ;
http://tuxgraphics.org/electronics/200611/embedded-webserver.shtml ; [online]
9) “The Internet Protocol Suite” ;
http://www.starlancs.com/EducateMe/educate_IP_stack.html ; [online]
10) “Internet of Things”; http://en.wikipedia.org/wiki/Internet_of_Things [online article]
11) “RFM12 Library”; http://das-labor.org/wiki/RFM12_library/en [online]
12) “ATmega32 AVR based Web server using ENC28J60 Ethernet interface” ;
http://www.embeddedmarket.com/products/AVR-Embedded-Web-server/ [online]
13) “Embedded Atmel HTTP Web Server” ; Tzeming Tam, Jeremy ; Cornell University
http://people.ece.cornell.edu/land/courses/eceprojectsland/STUDENTPROJ/2003to2
004/tt82/ATMELwebserver.pdf [online (project report)]
14) “Interfacing RFM12 Transceiver Module” ; Peter Gracias; Texas A&M University ;
http://www.embedds.com/interfacing-rfm12-transceiver-module/ [online]
49
15) “Web Server In a Box” ; Grassi, Mauro ; Silicon Chip Magazine ; November 2009
[magazine]
16) “ENC28J60 Stand-alone Ethernet Controller With SPI ” ; Microchip Technology
Inc. ; 2004 [pdf (datasheet)]
17) “RFM12 Datasheet” ; Harris Semiconductor ; [pdf(datasheet)]
18) “AVR Atmega8 microcontroller Datasheet” ; Atmel Corporation ; [pdf(datasheet)]
19) “AVR Atmega328 microcontroller Datasheet” ; Atmel Corporation ;
[pdf(datasheet)]
20) “AVR Atmega644 microcontroller Datasheet” ; Atmel Corporation ;
[pdf(datasheet)]
50
APPENDIX A : Data Sheet Snaps
A.1 AVR Atmega8 Features
• High-performance, Low-power Atmel AVR 8-bit Microcontroller
• Advanced RISC Architecture
– 130 Powerful Instructions – Most Single-clock Cycle Execution
– 32 × 8 General Purpose Working Registers
– Fully Static Operation
– Up to 16MIPS Throughput at 16MHz
– On-chip 2-cycle Multiplier
• High Endurance Non-volatile Memory segments
– 8Kbytes of In-System Self-programmable Flash program memory
– 512Bytes EEPROM
– 1Kbyte Internal SRAM
– Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
– Data retention: 20 years at 85°C/100 years at 25°C
– Optional Boot Code Section with Independent Lock Bits In-System Programming by On-chip
Boot Program
True Read-While-Write Operation
– Programming Lock for Software Security
• Peripheral Features
– Two 8-bit Timer/Counters with Separate Prescaler, one Compare Mode
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode
– Real Time Counter with Separate Oscillator
– Three PWM Channels
– 8-channel ADC in TQFP and QFN/MLF package Eight Channels 10-bit Accuracy
– 6-channel ADC in PDIP package Six Channels 10-bit Accuracy
– Byte-oriented Two-wire Serial Interface
– Programmable Serial USART
– Master/Slave SPI Serial Interface
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
• Special Microcontroller Features
51
– Power-on Reset and Programmable Brown-out Detection
– Internal Calibrated RC Oscillator
– External and Internal Interrupt Sources
– Five Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, and Standby
• I/O and Packages
– 23 Programmable I/O Lines
– 28-lead PDIP, 32-lead TQFP, and 32-pad QFN/MLF
• Operating Voltages
– 2.7V - 5.5V (ATmega8L)
– 4.5V - 5.5V (ATmega8)
• Speed Grades
– 0 - 8MHz (ATmega8L)
– 0 - 16MHz (ATmega8)
• Power Consumption at 4 MHz, 3V, 25°C
– Active: 3.6mA
– Idle Mode: 1.0mA
–Power-down Mode: 0.5µA
52
A.2 AVR Atmega328 features
• High Performance, Low Power Atmel AVR 8-Bit Microcontroller
• Advanced RISC Architecture
– 131 Powerful Instructions – Most Single Clock Cycle Execution
– 32 x 8 General Purpose Working Registers
– Fully Static Operation
– Up to 20 MIPS Throughput at 20MHz
– On-chip 2-cycle Multiplier
• High Endurance Non-volatile Memory Segments
– 4/8/16/32KBytes of In-System Self-Programmable Flash program memory
– 256/512/512/1KBytes EEPROM
– 512/1K/1K/2KBytes Internal SRAM
– Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
– Data retention: 20 years at 85°C/100 years at 25°C
– Optional Boot Code Section with Independent Lock Bits In-System Programming by On-chip
Boot Program True Read-While-Write Operation
– Programming Lock for Software Security
• Atmel QTouch library support
– Capacitive touch buttons, sliders and wheels
– QTouch and QMatrix acquisition
– Up to 64 sense channels
• Peripheral Features
– Two 8-bit Timer/Counters with Separate Prescaler and Compare Mode
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode
– Real Time Counter with Separate Oscillator
– Six PWM Channels
– 8-channel 10-bit ADC in TQFP and QFN/MLF package Temperature Measurement
– 6-channel 10-bit ADC in PDIP Package Temperature Measurement
– Programmable Serial USART
– Master/Slave SPI Serial Interface
– Byte-oriented 2-wire Serial Interface (Philips I 2 C compatible)
– Programmable Watchdog Timer with Separate On-chip Oscillator
53
– On-chip Analog Comparator
– Interrupt and Wake-up on Pin Change
• Special Microcontroller Features
– Power-on Reset and Programmable Brown-out Detection
– Internal Calibrated Oscillator
– External and Internal Interrupt Sources
– Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby,and Extended
Standby
• I/O and Packages
– 23 Programmable I/O Lines
– 28-pin PDIP, 32-lead TQFP, 28-pad QFN/MLF and 32-pad QFN/MLF
• Operating Voltage:
– 1.8 - 5.5V
• Temperature Range:
–-40
°C to 85°C
• Speed Grade:
– 0 - [email protected] - 5.5V, 0 - [email protected] - 5.5.V, 0 - 20MHz @ 4.5 - 5.5V
• Power Consumption at 1MHz, 1.8V, 25°C
– Active Mode: 0.2mA
– Power-down Mode: 0.1µA
– Power-save Mode: 0.75µA (Including 32 KHz RTC)
55
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator
– Interrupt and Wake-up on Pin Change
• Special Microcontroller Features
– Power-on Reset and Programmable Brown-out Detection
– Internal Calibrated RC Oscillator
– External and Internal Interrupt Sources
– Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby and
Extended Standby
• I/O and Packages
– 32 Programmable I/O Lines
– 40-pin PDIP, 44-lead TQFP, and 44-pad QFN/MLF
• Speed Grades
– ATmega644V: 0 - 4MHz @ 1.8V - 5.5V, 0 - 10MHz @ 2.7V - 5.5V
– ATmega644: 0 - 10MHz @ 2.7V - 5.5V, 0 - 20MHz @ 4.5V - 5.5V
• Power Consumption at 1MHz, 3V, 25·C
– Active: 240µA @ 1.8V, 1MHz
– Power-down Mode: 0.1µA @ 1.8V
56
Buffer
• 8-Kbyte transmit/receive packet dual port SRAM
• Configurable transmit/receive buffer size
• Hardware-managed circular receive FIFO
• Byte-wide random and sequential access with auto-increment
• Internal DMA for fast data movement
• Hardware assisted IP checksum calculation
57
64-bit hash table
- Programmable pattern matching of up to
64 bytes at user-defined offset
• Loopback mode
58
A.5 RFM12 Module Features
• Fully integrated (low BOM, easy design-in)
• No alignment required in production
• Fast-settling, programmable, high-resolution PLL synthesizer
• Fast frequency-hopping capability
• High bit rate (up to 115.2 kbps in digital mode and 256 kbps in analog mode)
• Direct differential antenna input/output
• Integrated power amplifier
• Programmable TX frequency deviation (15 to 240 KHz)
• Programmable RX baseband bandwidth (67 to 400 kHz)
• Analog and digital RSSI outputs
• Automatic frequency control (AFC)
• Data quality detection (DQD)
• Internal data filtering and clock recovery
• RX synchron pattern recognition
• SPI compatible serial control interface
• Clock and reset signals for microcontroller
• 16 bit RX Data FIFO
• Two 8 bit TX data registers
• Low power duty cycle mode
• Standard 10 MHz crystal reference
• Wake-up timer
• 2.2 to 5.4 V supply voltage
• Low power consumption
• Low standby current (0.3 µA)
• Compact 16 pin TSSOP package
59
APPENDIX B : SCHEMATICS
60
Figure B. 1: AVR Atmega328 interface schematics
Figure B. 2: AVR Atmega8 interface schematics
61
Figure B.3: AVR Atmega644 interface schematics
62
APPENDIX C : PCB LAYOUTS
63
Figure C. 3: PCB layout of Atmega644 interface for embedded web server
64
APPENDIX D : PROJECT SNAPSHOTS
65
Figure D. 3: Relay Interface Module with RFM12 (slave) and Atmega8 (slave)
66
APPENDIX E : PROJECT COST
SN Details Price
1 Relays 250
2 Atmega328 550
3 Miscellaneous 1000
5 Fabrication 1500
6 ENC28J60 1800
9 Router 2500
67