Sie sind auf Seite 1von 8

Implementation of a Embedded Web Controller based on TCP/IP Protocol for Home Automation System

Chao-Huang Wei1 Bui Quang Hoa2 Yu-Ning Wang3 Department of Electrical Engineering, Southern Taiwan University No. 1, Nan-Tai St., Yung-Kang/Tainan, Taiwan 710, R.O.C. drwei@mail.stut.edu.tw 1 hoakynghe@gmail.com 2 ijustrunaway@gmail.com 3 Abstract
As the applications for remote control or remote monitoring grow, demands for adding Ethernet connectivity to home appliances have also been increased. The challenge for many embedded system designers today is to integrate more functionality to their products economically and without increasing the overall size of the device. This paper presents an approach to building a TCP/IP based embedded web controller with a SoC platform to remote control and monitoring home devices via LAN/Internet network. The main benefits of this approach include its lightweight design, automatic online configuration and userfriendly interface. The web controller was designed using a powerful 8-bit microprocessor with embedded 10/100Mbps fast Ethernet MAC/PHY on a single chip, which provides a very small form-factor solution to enable embedded system very compact, low power, high performance yet low cost. Existing software modules provided by this microprocessor enables easy and quickly implementation of the TCP/IP and HTTP network protocols. The validity of the approach has been verified on a network working with real appliances. Keywords: Web Controller, Embedded System, SOC, TCP/IP Stack A user friendly interface to easy access the remote network device is an important issue for the embedded systems. Webpages can be used as a rich but inexpensive user interface and can simplify connections to remote device. The embedded system need supply only Web-compatible http-server software and html (hypertext-markup-language) page information. All the hard work is done by an off-theshelf Web browser running on the user terminal, all devices requiring user interaction can be controlled and managed from one device which includes a web browser, such as a personal digital assistant, cell phone, PC, etc. Also, use of webpage based button and display designs reduce the cost of production while making the systems more user-friendly [6]. The Internet's data-transport protocols allow various computer systems to exchange information using a client/server model. In the case of http (hypertext-transport protocol) on the Web, this exchange allows the client to create a rich visual experience for the user with minimal information from the server. Users can browse the webpage of this system in different regions through internet explorer. Control the household appliances (e.g. airconditioner, refrigerator, water heater, etc.) Monitoring about the operational status of household appliances or measuring data of sensors. Figure 1 shows a proposed home automation system for this work using an embedded Ethernet web controller, which can provide webpage through HTTP protocol for remote control and monitoring of home appliances.
IR Window Reed Switch Humidity / Temperature Sensor IR Door Reed Switch DVD Player

1. INTRODUCTION
Nowadays, remote control applications via the Internet are going to be used more and more widely with the development of powerful processors and network technology. Based on reports by Forrester Research, by the year 2010, up to 95% of the devices used to access the Internet will be non-PC devices, i.e. the embedded networking system will be the primary solution. To achieve this goal economically a standalone hardware platform and its dedicated software should be employed [1 ~ 4]. Amount all network technologies Ethernet's ease of use, cost effectiveness, high bandwidth, stability, security, and a high degree of compatibility makes it a natural solution for accessing the Internet. The Ethernet based embedded system satisfies both the stability and reliability demanded by household devices and the bandwidth demanded by home multimedia players. [5].

IR Signals
Web Controller

Internet

Air Conditioner

Web Controller

PC
Modem Router

Fig.1 Embedded web control and monitoring system for home automation network.

The web controller is based on an AX11005 development kit by ASIX Electronics [7], which contains a high performance microcontroller with TCP/IP and embedded Ethernet MAC/PHY. This web controller services as a web server also to interprets the received TCP packet and provides a webpage to remote PC through internet connection. The rest of this paper is organized as follows. Section II describes the hardware platform, IR controller and sensors to be used for examine the system functionalities. In section III, the design software modules will be described briefly. The implementation and experiment results are presented in section IV. Section V presents some conclusion and discussion for the future work.

Fig. 3 Examples of AX110xx application [7] The AX110xx family is software compatible with legend 8051 microcontroller has integrate 32KB SRAM for data memory, expandable up to 2MB via external SRAM without bank select, 128 to 512KB Flash for program memory. That is enough for porting a small RTOS (e.g. FreeRTOS or uC/OS-II) into the embedded system. Using a RTOS enables the development of application softwares easier and quickly [8]. Flash memory is used for storage of Boot Loader, system core program, application codes, constants, static variables, and etc., and the SRAM is used to store variables and stack information which is used in the running program.

2. HARDWARE SYSTEMS
In this section the hardware platform and several peripherals devices for this work will be described. The IR remote control, humidity/temperature sensor, and reed switches were used for functionality test of this web controller.

2.1 Hardware Platform


The hardware platform of the embedded web controller is constructed on a 100MIPS single-cycle pipelined 8 bit AX11005 microcontroller with TCP/IP and embedded 10/100M Fast Ethernet MAC/PHY, this provides a very low cost yet very high performance solution for wide varieties of application, which need access to the LAN or Internet. Figure 2 shows the internal hardware structure of this chip [7].

2.2 IR Remote Control


IR remote controllers are very common in every family to control electrical appliances, yet theirs natural characteristics and too many diverse standard and non-standard designs leads them difficult to unify. In this work the NEC remote controller similarly protocol will be used (fig. 4a).

Fig. 4a IR signal output waveform. The data frame is configured with a preamble lead code and 4 bytes control codes (fig. 4b).

Fig. 2 Functional Block Diagram of Embedded Ethernet Microcontroller [7] With rich communication interfaces such as UART, I2C, SPI, 1-Wire, CAN, PCA, and Local Bus the AX110xx is suitable for home appliances, factory/building automation, security systems, remote control/monitoring/management, and streaming media applications such as network camera/remote surveillance, VoIP, automatic meter reading, environment monitoring or network sensor, etc. Figure 3 shows some application examples using AX110xx microcontroller.

Fig. 4b IR bit pattern codes

2.3 Humidity/Temperature Sensor


Humidity is undoubted difficult to measure electrically. Some considerations to measuring humidity include: analog to digital conversing and external circuitry which might require op-amps or oscillator circuitry; temperature compensation adjustments to calculate dew point; calibration against a known humidity source; and response time in the real-world.

The Sensirion SHT11 Sensor Module from Parallax Inc. (fig. 5) [9, 10] is a smart sensor for both humidity and temperature, and it comes with digital interface, thus the microcontroller can read out these values easily. The only math required is a simple scale and offset. The SHT11 is factory calibrated so that it returns temperature with a resolution of 0.01 degrees Celsius and relative humidity with a resolution of 0.03 percent. This is quite excellent for commercial or home-based projects that require such readings.

Reed switches are widely used for electrical circuit control in mechanical systems as proximity switches as well as in door and window sensors in burglar alarm systems. 3. SOFTWARE SYSTEMS

3.1 Software Modules


Several software modules for developing with AX110xx hardware platform was provided by ASIX corp. As shown in figure 8, the AX110xx software modules include CPU, Ethernet, S/W DMA, MS Timer, Local Bus, I2C, SPI, 1-Wire, CAN, UART2, PCA and two TCP/IP stacks (i.e. uIP and Lightweight IP). All these modules are developed on Keil C development environment. Most modules are optional and configurable depending on users application needs. Some small RTOS modules like uC/OS-II, Keil RTX51, FreeRTOS, etc. can be implemented on the AX110xx hardware platform (fig. 8) [12].

Fig. 5 Sensirion Temperature/Humidity Sensor [9] The sensor can be connected to the microcontroller with two-wire serial interface (fig. 6). The SCK is used to synchronize the communication between the microcontroller and the sensor. The bidirectional DATA is used to transfer data in and out of the sensor. DATA changes after the falling edge and is valid on the rising edge of the serial clock SCK. During communication the DATA line must remain stable while SCK is high. To avoid signal conflict the microcontroller should only drive DATA low with tri-state output, therefore an external pull-up resistor is required to pull the signal high.

Fig. 8. AX11005 Development Board [12] Fig. 6 Interface to Microcontroller [10] Several software modules used for building the web controller will be described below (fig.9):

2.4 Reed Switch Sensors


The reed switch is an electrical switch operated by an applied magnetic field. The reed switch contains a pair (or more) of magnetizable, flexible, metal reeds whose end portions are separated by a small gap when the switch is open. The reeds are hermetically sealed in opposite ends of a tubular glass envelope. A magnetic field will cause the reeds to come together, thus completing an electrical circuit (Fig. 7) [11].

Fig. 9 Block Diagram of AX110xx Software Modules [8] CPU module is the core module that handles the common functions for other modules and should be loaded before loading any other modules. CPU module includes two sub-modules, the CPU ISR module and the CPU API module. The CPU ISR module handles the interrupt service routines for external peripherals/Wakeup/Watchdog interrupt events. The CPU API module provides several API functions for Application Upper Layer module to

Fig.7 Reed Switch and its component makeup [11]

reset system, get/set some system information. The run-time firmware or driver can be updated through Ethernet or UART, the so-called In Application Programming (IAP). Ethernet module is implemented to support 10/100M Ethernet MAC/PHY interfaces and TCP/IP Offload Engine. This module includes three submodules, TOE (TCP/IP Offload Engine), MAC and PHY sub-modules. The Ethernet module supports some API functions for Application Upper Layer module, which is dependent on different applications like IP Camera or RS232-to-Ethernet, and should be implemented by user. MS Timer module is a milli-second timer supported by the AX110xx hardware from 1 ms up to 1023 ms. This module includes two sub-modules, one is MS Timer sub-module, and the other one is Delay sub-module. The timing functions can be achieved through a watchdog timer, three generalpurpose 16-bit timers, and a 5-channel program-able counter array (PCA). Because the AX110xx hardware runs up to 100MHz system clock, to avoid too frequently timer interrupt events occurs, the upper layer module can uses this MS Timer instead of the standard 8051 timers to handle the timer routine. I2C module is implemented to support external I2C peripherals. I2C module includes two submodules, the I2C Driver module and the I2C API module. The I2C Driver module will initialize the I2C interface and handle the data transfer on the I2C bus. The I2C interface is a 2-wire serial bus, which consists of the serial clock (SCLK) line and the serial data (SDA) line. The I2C API module provides Master mode API functions for CPU to read/write one-byte or onepage data from/to I2C bus. In Slave mode, no API functions are necessary; all slave functions are implemented into the I2C driver. Local Bus module is implemented to access external devices through Local Bus Interface (LBI), which is high-speed parallel interface used to communicate with external devices or CPU. Local Bus module includes two sub-modules, the Local Bus Driver module and the Local Bus API module. It supports three modes of operation, namely, master mode, slave mode, and Digiport mode, but only one mode can be activated at a time. Fig. 11 Relationship between Adapter Module and TCPIP Modules [13] TCPIP module provides the interface functions for upper layer application modules to implement network functions. Application modules such as DNS module can use those TCP/IP interface functions to make or accept TCP connections, send and receive data by TCP packets, and close connections. In the TCPIP module a uIP (micro IP) sub-module is included, which implements the TCP/IP protocol stack. The open source software is originally developed by Adam Dunkels and is ported for Keil C51 by Murray R. Van Luyn. There are three different types of interface function provided in TCPIP module. Figure 12 shows the interface functions provided in each type.

Fig. 10 Architecture of Protocol Modules [13] Adapter module is mainly provided as the interface module between TCP/IP module and Ethernet driver module. This module has a direct relationship with software DMA driver module, Ethernet driver module, TCP/IP module, and PPPoE module (fig. 11). In transmitting direction, the Adapter module receives the outgoing packet from TCPIP module and then transmits it to Ethernet through Ethernet driver module. In receiving direction, when Adapter module receives an incoming packet from Ethernet module, it will call the callback function of TCP/IP module to handle the received packet. The callback function is registered in Adapter module during initialization.

3.2 Protocols for Serving WebPages


The AX110xx protocol modules consist of eight application protocol modules and three network protocol modules. All modules are developed based on the AX110xx software driver modules. Below diagram shows the architecture of AX110xx software protocol modules (fig. 10).

is called to send out the packets that may have been produced [14].

Check for packet

Process packet

Application events

Output packets

Fig. 12 Overview of TCP/IP Interface Functions [13] General Interface Function is to get and set parameters: local host IP address, local host subnet mask, default gateway IP address, local machine MAC address, and some others. TCP interface function is to create a new TCP socket from TCP/IP module, establish a connection to a specified socket, enable/disable the TCP Keep Alive timer, get the local port number of a TCP connection, send a TCP packet, close a TCP connection, and some others. uIP interface function sends an ARP response packet to Ethernet, if the received packet is an ARP request packet; or updates the ARP table, if the received packet is an ARP response packet. Besides, the uIP function creates an Ethernet header to be added before the IP header, set the memory starting address for storing received incoming packets, and the starting address of the buffer allocated in TCP/IP module for storing the data of packet need to be sent out, and some others. The uIP stacks can be run either as a task in a multitasking system, or as part of the main program in a single tasking system. The main control loop does two things repeatedly (fig. 13): 1. Check if a packet has arrived from the network. 2. Check if a periodic timeout has occurred. If a packet has arrived, the input handler of the TCP/IP stack is invoked. This function will never block, but will return at once, when it returns, the stack or the application for which the incoming packet was intended may have produced one or more reply packets which should be sent out. If so, the network device driver is called to send out these packets. Periodic timeouts are used to drive TCP mechanisms that depend on timers, such as delayed acknowledgments, retransmissions and round-trip time estimations. When the main control loop infers that the periodic timer should fire, it invokes the timer handler of the TCP/IP stack. Because the TCP/IP stack may perform retransmissions when dealing with a timer event, the network device driver

Check for timeout

Process timeout

Application events

Output packets

Fig. 13 Main Control Loop HTTP server module is provided for applications needing the HTTP server function. This module implements a simple web server, which enables the remote configuration of system settings via a web browser. This module mainly consists of HTTP protocol sub-module and webpage sub-module, the former implements HTTP protocol functions mainly, and the latter implements element handling functions and data structures for webpage. Figure 14 shows an overview of the HTTP server functions.

Fig. 14 Overview of HTTP Server Functions HTTP protocol sub-module implements notifying the HTTP server module to accept a connection, handles the connection events, and receive data from a socket, handles post information received from the HTTP client, divides the HTML file into several blocks based on the amount of POST_Record structure, and updates those configuration data with new settings. Webpage sub-module implements initialization of the FSYS_Manage structure, and the POST_Record structure, retrieve the identification of

a webpage file, and stores the pointers of those functions for handling POST_Record elements. The webpages are files or blocks of text that use a form of encoding called hypertext markup language (HTML). The HTML encoding specifies the formatting of text and images on the page, including text size and fonts and the positioning of text and other elements on the page. The HTML code may include links to images that appear on the page, as well as links to other pages or resources. In serving a webpage with dynamic content, the software must have a way of inserting the dynamic content as the page is being served. ASIX Electronics offers a software tool (mfilesys.exe) for easy webpage conversion into appropriate data structures and element handling functions in the format of C language. This software generates three C files, including filesys.c, filesys.h and web_fun.c. Below is an example describing the detailed procedure for using the conversion tool under command window (fig. 15).

Hyper terminal is used for communication with PC, TFTP server is used for program the application runtime code to Flash, Device Finder utility is for searching and setting of the AX1110xx board on the net [8].
RJ-45 Cable Monitoring User Interface (WinXP) RS-232 Null Modem

KeilC IDE

Windows ISP

Hyper Terminal

TFTP Server

Device Finder

Fig. 16 Tools for Development of Web Controller The process to generate the binary code is as following steps: 1. Develop application firmware source codes in C language under Keil IDE development environment. 2. Compile the source code to ax110xx.hex. 3. Convert ax110xx.hex to ax110xx.bin, and then convert ax110xx.bin to 80-pin.bin runtime code for the microcontroller on the development board (fig. 17).

Fig. 15 Webpage Conversion to C Language Fig.15 C Source Files Generation Now, other function code can be added into the web_fun.c source file to handle HTTP post information. In the web_fun.c source file, each element has a separate POST_Record structure and handling function. 4. IMPLEMENTATION AND EXPERIMENT RESULTS This section describes the information about how to implementing the web controller using AX110xx development board and some experiment results using this controller for control and monitoring home appliances. Figure 16 is the block diagram shows all necessary tools for building this web controller, Keil C IDE is for source code compiling, Windows ISP is for program boot loader to the development board,

Fig 17 Firmware Source Code Compiling Procedure There are two methods to program the firmware code to AX110xx Flash, via UART interface or via Ethernet Boot Loader interface; the latter one is more quickly and supports firmware update online. To use this method the Ethernet Boot Loader code should be first programmed into the Flash memory via UART interface by Windows ISP. The memory allocation is listed in table 1. Table 1 Memory Map of the Web Controller 24KB ~ 2MB AX110xx application runtime code 16KB ~ 24KB Space for saving SW variables 0 ~ 16KB Bootloader

The process to programming the Flash is as following steps: 1. Run Hyper Terminal application to create a connection between AX110xx board and the PC. 2. Run WinISP to program AX110xx boot loader via the UART. 3. Startup the TFTPD32 DHCP/TFTP Server utility (tftpd32.exe, a free TFTP Server application) on the PC. 4. Configure the TFTPD32 DHCP Server, set the IP pool starting address field (e.g. 192.168.0.3) to the same subnet mask with the Server interfaces IP address (e.g. 192.168.0.55) (fig. 18). 5. Save the settings in the registry and the DHCP server starts affecting address on the LAN. 6. Configure Boot File download path on TFTP Server, and select the boot file ax110xx.bin. 7. AX110xx Ethernet Boot Loader will send out a BOOTP packet to request an IP address from the DHCP server. 8. After getting an IP address from DHCP server, the Ethernet Boot Loader will start to download the firmware code from the TFTP server and will auto-restart AX110xx to load the new firmware code. Figure 18 shows the process to program the boot file consists of 352114 bytes in 10s from PC to ax110xx board.

web server IP address on the web browser (e.g. http://192.168.0.3). The program code, webpage and collected data will be stored in the on board flash memory. There are two methods to build-up the webpage, the first one uses a home page editor tool such as Microsoft FrontPage in advance, then saves the completed webpage in the flash memory of web server, the another one puts the HTML code into the control program of the web server directly. The former one is for display a static webpage, the later one is for dynamic display of the control data or monitoring results [9]. The main page of this controller provides several functions for control and monitoring home appliances (fig. 19, 20): (1) Device control: The user can use the selection menu on these webpages and turn coressponded appliances ON or OFF by sending IR pulses using the IR remote controller. (2) Sensor data monitoring: The user can monitor the temperature/ humidity values reported from the Sensirions SHT11 Sensor on this webpage.

Fig. 19 Webpage of Web Controller


IR Receiver 2 (for Lamp) IR Receiver 1 (for DVD)

Fig 18 Procedure of DHCP server setting and Boot File Programming via TFTP To access the embedded web controller user can use the Device Finder utility and pressing the Web Browser button on the main window or open the AX11005 web controller main page by entering the

IR Web Controller

Fig. 20 Turn DVD Player and Lamps ON by IR

5. CONCLUSIONS AND FUTURE WORKS


This paper presents how to building an economical web controller to meet the networking and application needs in spite of their hardware and software limitations of small devices. This paper proposed an economical Ethernetbased web controller for home automation system which enables the user to control legacy home appliances and to receive sensor data to monitoring home status through a home network. The webpage provided by the web controller offers the user with an enhanced interactivity. In addition, this web controller can generate IR signals to control conventional home appliances, which are originally controlled by IR remote control. The feasibility of the proposed web controller was demonstrated by an experiment in which lamps and sensors (e.g. humidity/temperature sensor and reed switches) were controlled or monitored via the Ethernet network or via the IR transceiver and the results were fed back to the users monitor. For the future work, a RF interface (e.g. ZigBee, WiFi, and Wireless USB) can be adopted to the web controller, therefore this home network system can be operated also by mobile device.

[3] C. Suh and Y.-B. Ko, Design and Implementation of Intelligent Home Control Systems based on Active Sensor Networks, IEEE Transactions on Consumer Electronics, Vol. 54, No. 3, pp. 1177-1183, Aug. 2008. [4] H.B. Lee, L.J. Park, S.W. Park, T.Y. Chung, and J.H. Moon, Interactive Remote Control of Legacy Home Appliances through a Virtually Wired Sensor Network, IEEE Transactions on Consumer Electronics, Vol. 56, No. 4, pp. 22142248, Nov. 2010. [5] J. Axelson, Embedded Ethernet and Internet complete, Lakeview Research LLC Madison, WI 53704. [6] M.C. Filibeli, O. Ozkasap, and M.R. Civanlar, Embedded web server-based home appliance networks, Journal of Network and Computer Applications 30 (2007) 499514, 2007. [7] AX110xx Product Introduction, Revision 1.7, ASIX Electronics Corp., Dec. 2009. [8] AX110xx Software User Guide, Revision 1.5, ASIX Electronics Corp., Nov. 2009. [9] Sensirion SHT11 Sensor Module Precision Temperature and Humidity Measurement, Parallax, Inc. Jul. 2003. [10] SHT1x / SHT7x Relative Humidity & Temperature Sensor System, SENSIRION AG, Mar. 2003. www.sensirion.com [11] Reed switch, Wikipedia, http://en.wikipedia.org/wiki/Reed_switch [12] AX110xx Development Kit User Guide, Revision 1.5, ASIX Electronics Corp., Dec. 2009. [13] AX110xx Upper Protocol Developers Guide, Revision 1.4, Nov. 2009. [14] A. Dunkels, Programming MemoryConstrained Networked Embedded Systems, Swedish Institute of Computer Science Doctoral Thesis SICS Dissertation Series 47, Feb. 2007.

ACKNOWLEDGEMENT
This work was supported in part by the National Science Council (NSC) Taiwan under Grant NSC 992221-E-218-033.

REFERENCES
[1] G.J. Pottie and W.J. Kaiser, Principles of Embedded Networked Systems Design, Cambridge University Press, Aug. 2005. [2] S.Y. Zhang, D. Xu, Y.P. Jiang, and R.M. Wang, Realization of Home Remote Control Network Based on ZigBee, The Eighth International Conference on Electronic Measurement and Instruments, pp. 4-344 4-348, Oct. 2007.

Das könnte Ihnen auch gefallen