A Web-Server Data Acquisition Electronic Prototype Manuel Soares, Elisabete Santos, Rui Antunes
Departamento de Eng. Electrotécnica, Escola Superior de Tecnologia de Setúbal - Instituto Politécnico de Setúbal Rua Vale de Chaves, Estefanilha, 2910-761 Setúbal, PORTUGAL Phone: +351 265 790 000, Fax: +351 265 721 869, e-mail:
[email protected] [email protected] [email protected]
Abstract1— This paper presents the project and development of several electronic printed circuit boards, used for controlling systems and measuring devices over the Internet by a user accessing a web site. These prototypes integrate a micro-webserver, and allow reading and/or writing up to 64 digital inputs/outputs, and also up to 16 analog inputs/outputs. It owns an internal USB interface used for the boards configuration, directly with a Personal Computer, or remotely over the World Wide Web, using a simple dedicated web page previously loaded into this hardware prototype.
It can be divided into three main blocks (shown below in Figure 2): The Main Controller, the Web-server Controller and the I/O Controller. The Main Controller is responsible for the communication between the Web-server Controller and the eight (maximum) I/O Controller boards. The Main Controller also allows USB communication with a Personal Computer or Laptop, for the whole system user configuration.
I. INTRODUCTION Many control and measuring/instrumentation systems are now using the Internet resources, making measurements and control with the use of a simple web page, loaded from any web-server in the World Wide Web. This makes possible to read data and activate outputs far away from the process source to be controlled. To make web-remote-control a reality we first need to build an acquisition board compatible with a web-server, and also compatible with the TCP/IP protocol [1]. The motivation for this project is to allow an alternative way to remote-control or measure any system over the planet, showing the advantages and the huge number of applications that can use of this kind of hardware. II. IMPLEMENTATION A. The Hardware The developed electronic prototype is shown if Figure 1:
Fig. 2. Main block diagram.
Fig. 1. Electronic prototype (with a single I/O board). The authors wish to acknowledge the Department of Electrical Engineering at Escola Superior de Tecnologia de Setúbal – Setúbal Polytechnic Institute for the Lab resources and conditions provided for this project.
The I/O Controller block module is responsible for the digital and analog input/outputs control. Once connected to the Main Controller, it will allow a user to read and write on the 8 digital input/outputs (I/Os), plus 2 more analog input/outputs available, that each I/O board (in maximum of eight) contains, being able to read/write and enable or disable up to 64 digital input/outputs, and also up to 16 analog input/outputs.
The electronic I/O boards that make part the I/O Controller block have several led indicators on each one, showing the state of each I/O (if it is configured as an input or an output, and in case of an output if it is “ON” or “OFF”). The interface between the eight I/O boards and the Main Controller is done using tree different signals: ENABLE, CLK and DATA, for each I/O board. The ENABLE line defines if the I/O Controller is ready (or not) for the data. The CLK line indicates when the next bit is ready for data processing by the I/O Controller. Finally the DATA line will carry out the data bits that will be transmitted and received, and so it will be a bidirectional line. The communication between the Main and the I/O Controller is quite similar to the I2C protocol, once the DATA line is bidirectional.
For receiving the value, it is given a clock pulse in the CLK line. Then, the I/O Controller puts in the DATA line the first bit value, and the Main Controller will immediately read it. If this is the only bit present, the communication will end. Otherwise, the process is repeated until the reception of the last bit. For the test command shown below in Table II, in order to verify if an I/O board is connected (present), the Main Controller will transmit the first bit, and it should receive in return a sequence of three bits in the DATA line. If the sequence obtained is “0-1-0” it means that the I/O board is present. Table II Test commands for an I/O board
The Main Controller always acts as the Master for the I/O Controller (I/O boards), being responsible for first initiate the communication, and also for giving the control for the ENABLE and CLK signals. The protocol used allows the Main Controller to read the state and the inputs/outputs values of the I/O controller, and also to verify if any I/O board is present.
For implementing the Web-server Controller, the Modtronix SBC45EC board [2] was used, as shown below in Figure 3:
The communication starts, setting the ENABLE line to high state. Next, is set in the DATA line the first command bit, and then a clock pulse is given to the CLK line. This pulse is received by the I/O Controller as an interrupt, to start the communication routine. Then, it verifies if the ENABLE line is active. If not, it will reset the receive information register. Otherwise it will process the DATA line bit value, and the next command bits are received the same way. After the command is sent, it is now time to transmit or receive the current value (eight bits for an analog I/O, or one bit for a digital I/O), as shown in Table I: Table I Commands between the Main and the I/O Controller
Fig. 3. The Modtronix SBC45EC board. This board has incorporated a PIC18F452 Microcontroller [3] used to implement the micro-web-server, a 24LC512 nonvolatile EEPROM to store all the necessary data for the system (net configurations, I/O values, usernames and passwords for login, and also the web pages that will be loaded and presented by the micro-web-server). It has also an Ethernet 10BaseT interface and includes the RJ45 connector, allowing the connection to an Ethernet line. The source code for programming the Modtronix board is now available at http://www.modtronix.com/products/sbc45ec/ . The data transmission between the Modtronix board and the Main Controller is done by the internal USART of the Microcontrollers used in those two modules. B. Implemented Software Interface The Web-server Controller allows the interaction with the web pages that have .CGI extension (Common Gateway
Interface), thus being the user able to call pre-defined functions within the web-server, from any Internet Browser. This makes possible to use predefined commands (when added in the source code of the web pages), html commands [4] [5], and commands to be replaced by variable values. And that is how the interaction is made (using World Wide Web) to the digital and analog inputs/outputs. For our project were made two sets of web pages. The first one used for a generic case, and the other as an example for home automation (via Internet), using a PC/Laptop or a small Personal Digital Assistant (PDA), shown in Figures 4 and 6:
Fig. 6. Home Automation control from a web site. Table III Button and Checkbox names (html code)
Fig. 4. Main web page “Casa”. The configuration of the whole system is done using the main web page. And we can: - Select the I/O board to be controlled (in total of eight); - Protect the system (I/Os always set as inputs), in order to be able to change the I/Os configuration without direct interference on the previous connections (note that an I/O reconfiguration enable has always to be done on-board); - Change the username and password for login access (administrator or user mode); - Set, reset, enable or disable the digital and analog outputs for each (eight) I/O boards; - Read digital and analog input values from each I/O board; - Change net settings (IP, Sub-Mask, Gateway and MAC address) and finally load a specific web page into the electronic web-server board, as shown in Figure 5:
The sample html code that allows changing the value of the digital I/O_1 (for I/O board 1) is shown below in Figure 7. The name “VP1D1” will be used, according to Table III (above):
%121 0 %131 %141 1 %151 %161 %171 %181 %191 |
Fig. 7. Html code to change the I/O values of board 1.
Fig. 5. Loading a web page and changing TCP/IP settings.
The Main Controller software includes also USB communication with a Personal Computer. To program USB communications, it was used a special library provided by Microchip (PIC microcontroller’s company [6] [7]), named CDC (Communication Device Class), that has built-in functions for the data transmission and reception from/to the PIC microcontroller’s USB [8]
port. It was developed a special software security application interface between the user and the board controllers, directly via USB port. This application, programmed in Visual C# language allows directly setting/configuring the Main Controller, the IO Controller, and also the Server Controller, without the need of any TCP/IP access port. Figure 8 shows the main form window of this software application:
Table VI Commands from the PC to the Main Controller
For a correct message, the “Start Byte” and the “Stop Byte” will be respectively, ‘16’ and 35’. If the five byte frame message contains an error, the program will automatically jump to a signal synchronization routine. This routine will test each byte, until it founds the value ‘35’, which corresponds to a “Stop Byte”. Then, it will consider the next sequence of bytes as the correct frame. III. CONCLUSIONS
Fig. 8. Setting up the system from an USB port. It was created a special communication protocol, with a five byte frame message, between the Personal Computer (PC) used and the Main Controller, as described bellow in Tables IV, V and VI. The frame messages exchanged between these two devices are five byte length. The first “Start Byte” and the last “Stop Byte” are used to detect any USB communication error that eventually might occur. Table IV Frame type between the PC and the Main Controller
One of the main advantages of the developed prototype is the low cost and huge versatility, and also because it can be in fact applied and adapted to web-control and to web-measure a large number of systems, like for example industrial factories, for home-automation, security systems, schools and services. The internal structure was resumed to three main blocks. It was built a demo web site to read and write from/to the digital and analog input/output boards, using a PC/Laptop and also a small PDA. Both the switching “ON/OFF” input/output performance time, and the input/output analog reading/setting time relies naturally on the speed of the Internet connection used (generally were obtained between one and two seconds). For future development for this project, we purpose to use Wireless Internet technology specially provided for our micro-web-server controller, turning wireless the measuring and web control of any particular system that incorporates these small and low-cost electronic devices. REFERENCES
Table V Actions from the Main Controller to the PC
[1] “An Introduction to TCP/IP for Embedded System Designers”, Z-World Inc, 2001. [2] “Modtronix SBC45EC”, www.Modtronix.com . [3] “PIC18F452 Datasheet”, www.microchip.com . [4] “HTML 4.0 Reference”, www.clicknow.net/ebooks02.htm . [5] Bill Kennedy, Html and Xhtml: The Definitive Guide, UK: O’reilly, 2002. [6] “PIC18F4550 Datasheet”, www.microchip.com . [7] “AN833- Microchip TCP/IP Stack Application Note”, www.microchip.com . [8] “AN956- Migrating Applications to USB from RS-232 UART with Minimal impact on PC Software”, www.microchip.com .