Research on the Calling Method of Web Service in Single Chip Microcomputer System

Publisher:捡漏来了Latest update time:2011-12-22 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction

As a new technology with powerful interoperability and scalability, Web Service is increasingly used for the integration of heterogeneous data. It is natural to apply it to the integration of heterogeneous data in industrial data acquisition systems. This paper introduces a method of calling Web Service in a single-chip microcomputer system to realize active data submission, which facilitates the integration of data acquisition systems. In traditional data acquisition systems, single-chip microcomputer systems can be used to collect instrument data using serial ports, submit data to the host computer through serial buses, and communicate with the host acquisition server through pre-designed communication protocols to integrate the collected data. When it is necessary to add a lower-level acquisition module, the corresponding host acquisition port needs to be expanded, and the upgrade and maintenance of the acquisition system are very troublesome. In the single-chip microcomputer system, by calling the Web Service on the acquisition server side to interact with the host computer, the communication between the lower and upper computers can be simplified, and the main work can be focused on how the lower single-chip microcomputer system communicates with the instrument to collect data. Based on this method, a distributed data acquisition solution based on industrial Ethernet can be easily constructed. This solution can also easily integrate existing data acquisition systems and facilitate the upgrade of single-chip microcomputer systems. For example, the acquisition system implemented by single-chip microcomputer can be easily changed to PLC acquisition system or direct PC data acquisition mode, and the upgraded system only needs to call the same Web Service to interact with data. Since Web Service calls use HTTP protocol to interact with data, this solution can also be easily expanded to support remote data acquisition on the Internet.

2 Implementation of calling Web Service in MCU system

2.1 Web Service Technology[7,9,10]

Web Service is a programmable application component that can be accessed through the Web protocol, enabling information between previously isolated sites to communicate and share with each other. Web Service uses unified and open standards on the Internet, such as HTTP, XML, SOAP, WSDL, UDDI, etc., so Web Service can be used in any environment that supports these standards (Windows, Linux, etc.). Web Service is not actually a new technology. As mentioned earlier, it uses Internet standards, which are the core technologies of Web Service.

(1) HTTP is an application layer protocol based on TCP. It is an important basis for reliable data exchange on the Internet. HTTP provides a transport layer for Web Service requests and responses. HTTP enables any device and platform to access Web Services.

(2) XML (Extensible Markup Language) is a set of specifications that allows programmers to define HTML-like tags to facilitate data access, processing, exchange, conversion, etc. Its main feature is the use of meaningful tags, which enables computers to understand the meaning of data. XML can run on any system, application, and platform. Data transmission is based on the Internet, and the transmission cost is cheap.

(3) SOAP (Simple Object Access Protocol) is an XML-based communication protocol for network information exchange in a decentralized and distributed environment. Its design goals are simplicity and extensibility, which facilitates interoperability between a large number of heterogeneous programs and platforms, so that existing applications can be accessed by a wide range of users. Because the data is in text format, it is easy to debug and pass through firewalls.

(4) WSDL (Web Service Description Language) is an XML-based syntax used to describe Web service functions.

(5) UDDI (Universal Description, Discovery, and Integration) is a platform-independent, open framework based on XML that describes, discovers, and integrates services over the Internet.

2.2 The Essence of Web Service Calls

Now many language tools support Web service development, such as VS.Net, J2EE, JBuilder, etc., and many language tools are cross-platform (Windows, Linux, etc.). These development tools have special development kits or class libraries that can easily implement the definition and call of Web Service. This article mainly studies the call method of Web Service in the single-chip microcomputer system.

Calling a Web Service is essentially an information exchange between the program client and the Web Service server, and there is a special information format. ASP.net provides three interaction ports (protocols): SOAP, HTTP-GET, and HTTP-POST[7]. Among these three protocols, SOAP is the most commonly used XML Web Service. Compared with HTTP, SOAP is more complex, but has stronger acceptance capabilities. SOAP is an XML-based protocol that provides a method for packaging and encoding data for network data transmission. Any user can use the SOAP protocol to communicate with any Web Service. Even if the XML Web Service is not built on the ASP.NET platform, such as Java, it can use SOAP for data transmission. Therefore, SOAP is language independent. HTTP encapsulates SOAP messages and then transmits them over the network in its form. The HTTP-GET and HTTP-POST methods are relatively simple in their ability to transmit parameters and data, and are very suitable for situations where clients who cannot use SOAP want to call Web Services. Compared with SOAP, the HTTP-GET and HTTP-POST methods have the following characteristics:

Advantages: (1) The HTTP method does not require complex XML message processing and is suitable for platforms that do not support XML; (2) The HTTP method does not require the addition of additional tags during interaction, which reduces the amount of interactive data and overhead, and is conducive to improving overall performance.

Disadvantages: (1) Cannot call Web Services with complex data type parameters; (2) Inconvenient to process if the call returns a complex data type; (3) Cannot serialize classes and structures into XML messages; (4) Cannot pass parameters by reference.

Combined with the actual needs of the MCU system to call Web Service and considering the low processing power of the MCU, the lack of support for XML, the lack of suitability for complex data processing, and the low development efficiency, it is considered that the HTTP method is more appropriate. This article will take HTTP-POST as an example to introduce the implementation method of calling Web Service.

2.3 Core Technology for Implementing Web Service Calls in MCU Systems

(1) Implementing HTTP based on embedded network module

In embedded systems (WinCE, Linux, etc.), HTTP can be implemented based on its own TCP/IP protocol stack or directly use the embedded Web server [1-5] to use the HTTP protocol. In computer systems, the Web client can be directly called in a high-level language to use the HTTP protocol or the SOCKET network programming can be used to implement data interaction based on HTTP. The implementation is relatively simple, but in the single-chip microcomputer system, it does not have its own TCP/IP protocol stack, so HTTP is implemented in the single-chip microcomputer system based on the embedded network module.

To implement the HTTP protocol, the TCP/IP protocol stack must be used as the basis. The functions of the TCP/IP protocol stack can be easily implemented using the embedded network module. As shown in Figure 1, the lower computer and the instrument equipment are connected through the 485 bus. The lower computer is developed using a single-chip microcomputer and uses a master-slave mode to communicate with the equipment and instruments to collect data. The collected data is then sent to the embedded network module through the bus. The module receives the serial data and uses the embedded TCP/IP protocol stack to convert the serial data into Ethernet data. The embedded network module is connected to the industrial Ethernet through a network cable. In this method, the lower computer is the key to implementing the HTTP application layer protocol. As long as the data packet sent by the lower computer conforms to the HTTP protocol and is converted by the embedded network module into a legal HTTP-POST request packet that can be processed by the Web server, the Web Service can be used to process and save the data, thus realizing the single-chip microcomputer system calling the Web Service.[page]

Figure 1 MCU system structure

In the experiment, an embedded network module ZNE-100T developed by Guangzhou Zhou Ligong Microcomputer Development Co., Ltd. was selected. It has an internally integrated TCP/IP protocol stack, which can easily complete the network functions of embedded devices. In addition, the evaluation board of ZNE-100T was directly used for testing convenience. The configuration software provided by Zhou Ligong can set the parameters of the network module, including IP address, subnet mask, gateway, serial port baud rate, port working mode, target IP address and target port, etc. The port working mode is specially explained. Since the HTTP protocol is based on TCP, the mode in the experiment is set to TCP Client mode, and the target port is set to 80 by default.

(2) HTTP-POST message format

Internet standards define two HTTP protocol standard documents: RFC1945 and RFC2616[6]. These two documents describe the implementation standards of HTTP/1.0 and HTTP/1.1 respectively. The biggest difference between the two versions of the HTTP protocol is that the former does not support keep-alive and requires the TCP connection to be closed after each HTTP request and response, while the latter supports persistent connection, which means that a TCP connection can be opened for multiple requests/responses, greatly improving performance. Due to the low processing efficiency and limited resources of the microcontroller system, it is unrealistic to implement the complete HTTP protocol on it. In fact, it is not necessary to implement all of it in order to implement Web Service calls. It is only necessary to implement the basic HTTP1.1 protocol to complete the data communication between the microcontroller system and the Web server. After analysis and research, a relatively simple and effective HTTP-POST format was found. The following is a specific example to illustrate the implementation method.

Use C# to implement Web Service1 and define a method for processing analog data:

[WebMethod]

public string SimulateData(byte s,float[] a)

{

return "OK";

}

In the parameters of the SimulateData method, s is the lower computer station address, which can be used to distinguish which lower computer sends the data, and array a is the simulation data submitted by the lower computer. The number of data is determined according to the actual data transmitted.

The following is the HTTP-POST request packet data:

POST /WebService1/service1.asmx/SimulateData HTTP/1.1

Host: 127.0.0.1

Content-Type: application/x-www-form-urlencoded

Content-Length: 43

s=1&a=100.0&a=100.0&a=100.0&a=100.0&a=100.0

The above is a legitimate HTTP-POST protocol package example. "/WebService1/service1.asmx/SimulateData" is the method name of the Web Service to be called and its service address. The last line is the real valid data information. The data includes the acquisition station address, which is 1 in this example, and 5 simulated data, which is 5 100.0 in this example. In addition to the data field in the HTTP-POST packet, the 43 in "Content-Length: 43" will be set by the program in the lower computer according to the actual number of bytes in the data field, indicating the number of valid data bytes submitted. It can be seen that as long as the correct HTTP request header, the corresponding Web Service address, and the data field data are set according to the HTTP1.1 POST specification, a simple HTTP-POST protocol can be implemented. In the single-chip microcomputer system, only these data need to be sent through the serial port, and the rest of the work is implemented by the embedded network module, which is as simple as writing an ordinary serial port sending program. The HTTP-POST request converted by the meridian module finally reaches the Web server and is written into the real-time database according to the corresponding data. If the real-time requirement is not high and the data storage volume is not large, the ACCESS database can be used, otherwise a dedicated database server such as Oracle and SQL can be used. Server.

After calling the Web Service, data will also be returned to the lower computer to indicate the execution result. If the lower computer does not care about the execution result, the returned data can be ignored. Otherwise, it can be processed accordingly as needed. The following is the return data of the author's experiment:

HTTP/1.1 200 OK

Date: Thu, 08 Feb 2007 07:45:51 GMT

Server: Microsoft-IIS/6.0

MicrosoftOfficeWebServer: 5.0_Pub

X-Powered-By: ASP.NET

X-AspNet-Version: 1.1.4322

Cache-Control: private, max-age=0

Content-Type: text/xml; charset=utf-8

Content-Length: 101

ok >

The "ok" above is the data returned after the method SimulateData is executed correctly.

3 Advantages

Based on the method proposed in this paper, it is convenient to use the single chip microcomputer to build a data acquisition system based on industrial Ethernet, which has the following advantages:

(1) It is easy to integrate the data collection of existing equipment and instruments. As long as you know the communication protocol of the instrument equipment, realize data communication on the lower computer, and encapsulate the collected data into HTTP-POST request packets and send them through the serial port.

(2) It uses industrial switched Ethernet and HTTP protocol to meet the needs of local and remote data collection. The system can be connected to the Internet. The Web Service and the lower computer system can be located in different geographical locations. Moreover, the Web Service can process data submitted by multiple different geographical locations at the same time, which facilitates data concentration and better management and use of data.

(3) It is convenient for maintenance and upgrading, and it is convenient to add sampling points. You can add lower computers as needed, and add several modules as needed for debugging.

(4) Different from the traditional dedicated data collection server mode, the functions of the host server are provided by Web services. There is no need to write a dedicated data receiving program and host collection program. Only the Web Service interface code needs to be written. The actual communication with the instrument is completed by the lower computer, forming a distributed data collection. The Web service is a multi-threaded architecture that can concurrently process data sent by multiple lower computer modules, so that the entire system supports the collection of more data points and improves the collection efficiency of the entire system.

4 Conclusion

Experiments have shown that the data acquisition system can be deployed quickly and effectively based on the method in this paper, which has many advantages over the traditional serial port server data acquisition method. The communication between the upper computer and the lower computer is based on Web Service technology, so that the system development work is mainly focused on the communication between the lower computer and the instrument, which improves the system development efficiency. Due to the cross-platform and language-independent nature of Web Service, the system solution can be easily maintained and modified, greatly reducing the development cost.

Reference address:Research on the Calling Method of Web Service in Single Chip Microcomputer System

Previous article:EEPROM Virtual Technology Based on MC9S08QG8 Single Chip Microcomputer
Next article:Design of Embedded Internet Terminal Based on Single Chip Microcomputer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号