Good article reposted -- Research and Implementation of coap protocol in wireless Iot

Source: Internet
Author: User
Tags representational state transfer response code

Research and Implementation of coap protocol in wireless Iot

Time: 2013-04-09? Source: Electronic Technology Tang Chunming, Zhang Ying, Wu yuping

Keyword: coap ??? Wireless ??? Iot ??? Protocol ??????

Abstract:Many devices in IOT are resource-limited, that is, they only have a small amount of memory space and limited computing power. Therefore, traditional HTTP protocol applications are too large for Iot. The IETF Core Working Group proposes a rest-based coap protocol. Coap is the application layer protocol in the 6lowpan protocol stack. After introducing the content, features, and interaction model of the coap protocol in detail, the contiki embedded operating system is used in the uipv6 start kit wireless network development kit, not only has the coap Protocol been implemented on the browser side, but also the coap protocol has been implemented using a self-compiled client program, and the interaction function with the database has been added, this allows you to view not only real-time data, but also historical data on the Web interface.
Keywords:Iot; 6 lowpan; coap; contiki

0 Introduction
????
The Internet of Things (IOT) is a network that is extended and extended on the basis of the Internet. Its user end is extended and extended to any item for information exchange and communication, the purpose is to connect all items to the network for easy identification, management and control.
??? The features of wireless Iot include comprehensive perception, real-time and accurate delivery of item information, and intelligent computing technology to analyze and process massive data for intelligent control.
??? Many devices in the wireless IOT are resource-limited. These devices only have a small amount of memory space and limited computing power. To this end, the IETF (Internet Engineering Task Force) core (constrained restful environment) Working Group has developed an application layer protocol in the form of rest (representational state transfer) for restricted nodes. This is the coap (constrained application protocol) protocol being developed by the core working group.

1 6lowpan protocol stack
????
Because the TCP/IP protocol stack is not applicable to devices with limited resources, a 6 lowpan (IPv6 over low power Wireless Personal Area Networks) protocol stack is proposed. Coap is the application layer protocol in the 6lowpan protocol stack. 6lowpan enables IPv6 to be used for Low-Power lossy networks. It is based on the IEEE 802.15.4 standard. 6 lowpan protocol stack 1.


??? The lower two layers of the protocol stack use 802.15.4 PHY/Mac, and a IPv6-6LoWPAN adapter layer is added in the middle. The transport layer uses UDP protocol and the application layer uses coap protocol. It includes the minimum subset of rest and stateless HTTP ing to HTTP. The communication host uses the coap protocol to support a stable communication architecture for wireless connection between sensor nodes and the Internet.

2 coap Protocol
????
In October March 2010, the core working group began to develop the coap protocol, which has not yet been finalized. Coap is an application layer protocol for Iot devices with limited resources. It is a network-oriented protocol that uses features similar to HTTP. Its core content is resource abstraction, restful interaction, and extensible Header Options. The application uses the URI identifier to obtain resources on the server. That is, the application can perform get, put, post, and delete operations on resources like HTTP. Coap Protocol has the following features:
??? (1) Header Compression: coap contains a compact binary header and an extended header. It only has a short 4 B basic header, followed by an extension option. A typical request header is 10 ~ 20 B. Figure 2 shows the Information Format of the coap protocol.


??? The meaning of each field in the header is as follows: V (Version) indicates the version number of the coap protocol; t (type) indicates the information type of the message; oC (option count) indicates the number of Optional options after the header; Code indicates the Message Type: Request Message, response message, or empty message; Message ID indicates the message number, it is used to detect duplicate messages and match message types.
??? (2) method and Uris: To enable the client to access resources on the server, coap supports methods such as get, put, post, and delete. Coap also supports Uris, which is the main feature of the Web architecture.
??? (3) the transport layer uses UDP protocol: coap is built on UDP to reduce overhead and support the multicast function. It also supports a simple stop and wait reliability transmission mechanism.
??? (4) Support for asynchronous communication: HTTP does not apply to M2M (machine-to-machine) communication because transactions are always initiated by the client. Coap supports asynchronous communication, which is a common sleep/Wakeup mechanism for M2M communication applications.
??? (5) support resource discovery: to discover and use resources independently, it supports the built-in resource discovery format for discovering the resource list on the device, or, the device publishes its own resources to the Service Catalog. It supports the format in rf120085 and uses the path/. Well-known/core in the core to indicate the resource description.
??? (6) Support for caching: coap supports cache of resource descriptions to optimize its performance.
??? (7) Subscription mechanism: coap uses asynchronous communication and subscription mechanism to push messages from the server to the client. Implement coap publishing and subscription. It is a kind of resource post-processing program automatically registered after successful requests. It is configured by the default Event _ and periodic_resources. Their events and polling handlers are released using the est. policy_subscri bers () function.
2.1 coap protocol stack
????
Figure 3 shows the coap protocol stack. The transport layer of coap uses UDP. Due to the reliability of UDP transmission, the coap protocol adopts a dual-layer structure, defines a transaction processing mechanism with retransmission, and provides features such as resource discovery and Resource description. Coap uses the smallest possible load, thus limiting the fragmentation.


??? The transaction layer is used to exchange information between nodes. It also provides functions such as multicast and congestion control. The request/response layer (Request/responselayer) is used to transmit the request and response information for resource operations. The rest architecture of coap protocol is based on the communication at this layer. Coap's double-layer processing method prevents coap from using the TCP protocol and provides a reliable transmission mechanism. The default timer and exponential retransmission interval are used to re-transmit con (confirmable) messages until the receiver sends a confirmation message. In addition, coap's double-layer processing method supports asynchronous communication, which is one of the key requirements for IOT and M2M applications.
2.2 coap subscription Mechanism
????
The HTTP Request/Response Mechanism assumes that the transaction is initiated by the client, which is usually called the PULL model. As a result, the client cannot efficiently understand that devices are wireless and low-power-consuming. These devices are sleep most of the time and therefore cannot respond to polling requests. Core considers it an important requirement to support the local PUSH model, that is, the server initializes the transaction to the client. The push model requires a subscription interface to request responses to changes to specific resources. Because UDP transmission is asynchronous, special notification messages are not required. Subscription mechanism 4.

?

2.3 coap Interaction Model
??? Coap uses a request/response model similar to http: The coap terminal node sends one or more requests to the server as a client, and the server replies to the client's coap requests. Unlike HTTP, coap requests and responses do not need to establish a connection before sending, but use coap information for asynchronous information exchange. Coap uses UDP for transmission. This is achieved through the reliability of the information layer options. Coap defines four types of information: verifiable con (confirmable) information, unverifiable non (non-confirmable) information, and verifiable ack (acknowledgement) information and reset information RST (reset ). The method code and response code are included in the information to implement the request and response functions. These four types of information are transparent for Request/response interaction.
??? Coap request/response semantics are included in coap information, including method code and response code. The coap option contains optional (or default) request and response information, such as Uri and load content types. The token option is used to independently match the underlying request to response information.
??? Request/Response Model: The request is contained in verifiable or unverifiable information. If the server is immediately available, the response to the request is included in the verifiable confirmation information. Figure 5 shows the basic GET request and response modes. Figure 5 (a) indicates that the request is successfully sent and ACK confirmation information is received. Figure 5 (B) indicates that the request information is re-transmitted, then you will receive the ACK confirmation message.


??? Although the coap Protocol is still being developed, the contiki and tinyos embedded operating systems have supported the coap protocol. Contiki is a multitasking operating system with a uipv6 protocol stack. It is suitable for embedded systems and wireless sensor networks. It occupies a small amount of system resources and is suitable for networks and devices with limited resources. Currently, Firefox has integrated the copper plug-in to implement the coap protocol. However, this method can only read real-time data on sensor nodes, rather than view historical data. To this end, based on the contiki system and the uipv6start kit Wireless Network Development Kit, the client program compiled by myself enables interaction with the database and stores historical data into the database, in this way, the Web browser can not only access real-time data on the sensor node, but also view historical data to facilitate problem analysis.

3. Implementation of the experimental platform and coap Protocol
3.1 Experiment Platform
????
The hardware platform is an IPv6 smart Gateway (mxg300), mx231cc node, USB wireless network adapter (stick), and JTAG download device of the United States. Configure the hardware platform and platform 6 of the experiment, as shown in figure 7. The software platform is winavr and AVR studio, which is used to download programs from nodes and USB NICs.


??? Among them, the main chips of IPv6 Intelligent Network Shutdown are BCM 6358ukfbg, which supports multi-user Ethernet, with a highly optimized 32 mips cpu and a standard ejtag debugger; bcm53 25ekqmg integrates five transceiver, it has a 128 KB data packet buffer, supports up to 2 k MAC addresses, supports Address Auto-learning, provides real plug-and-play connections, and is low-power; sige2521a60 provides 2.4 ~ 2.5 GHz wireless working frequency range, used in the wireless solution of ISM 2.4.ghz.

? Figure 8 shows the interface layout of IPv6 smart wireless gateway, which is customized based on the openwrt system. It has three LAN ports, one wide area network port, one 802.11a/B/g Wi-Fi wireless network interface, one standard USB port, and one optional serial port debugging port. In addition to the function of a universal wireless router, the smart wireless gateway can also implement IPv6 interconnection between a usb uip network based on the contiki operating system and a common IP network, it also supports the ability of systems to develop their own application software packages based on openwrt to implement more complex applications.


??? Openwrt is an open-source Linux version. It is mainly used in embedded systems. The gateway and node are equipped with a contiki system, which provides macro-defined and restful network service instances.
??? The main chip on mx231cc node is atmega1284p. It has 128 kb programmable flash memory, 4 kb E2PROM, 16 kb in-chip SRAM, JTAG interface, optimized power consumption and processing speed. Run the contiki system on the node. The nodes also contain photosensitive sensors, indoor temperature sensors, and three-color LED indicators.
3.2 implement the Firefox browser of coap protocol (B/S architecture)
????
The system structure of the B/S architecture is shown in Figure 9.


??? The system consists of user browsers, Web servers, IPv6 smart gateways, and mx231cc nodes. The user's browser accesses the Web server through the HTTP protocol. The mx231cc node communicates with the IPv6 smart gateway through the coap Protocol, so that the user's browser can access resources on the node. Figure 9. A line indicates a wired connection, and a dotted line indicates a wireless connection.
??? In the current contiki 2.5, coap 03 and coap06 are integrated. These two files are in the apps directory of contiki 2.5, and the core content about coap is in these two files. The main part of the program is:

??? Autostart_processes (& coap_sample) the process needs to be started by itself, that is, when the node starts the program;
??? Periodic_resource () is the main part of the process.
??? Then compile and compile the file into the. ELF file, and download it to the node using the JTAG download tool. The Node Address is set to 2001: 2: 11: 22ff: fe33: 4499. In this case, you can use Firefox to access the node. Because Firefox comes with the coap plug-in, if you use other browsers, You need to configure the coap proxy. The following request format is used to reverse the three-color LED light on the control node:
??? Getcoap: // [<mote_ip_address>]: <poa_number>/readings
??? Here, mote_ip_address is the IPv6 address of the node, port_number is the port number of the node, and readings is the resource requested by the client (temperature ).
??? Therefore, enter coap: // [2001: 2: 11: 22ff: fe33: 4499]: 61616/toggle in the address bar of the browser to reverse the three-color LED lights on the node. The response information of the server is 10.


??? From the browser, we can see that the coap protocol supports the Discover and observe functions, and has methods such as get, post, put, and delete. Type indicates that the information type is ack, and the code is 200, indicating that the client request is successfully completed. The transaction ID is 38 264, which is used for duplicate information detection. If options is 1, there is an option, and the content type is text.
??? From this we can see that through the coap protocol of Firefox browser, we can access the sensor resources on the node.
3.3 coap client implementation (C/S architecture)
????
In the previous section, you can use the Firefox browser to implement the coap protocol, but you can only view real-time data, not historical data. Therefore, a C/S architecture environment is set up here. 11.


??? Figure 11 client software is written in C # language based on the. NET architecture, and the database uses SQL Server 2008. This program can read data every 10 s and store it in the database. You can also view historical data, including temperature, humidity, and brightness, on the web interface of the foreground.
??? Insert the data in the database as shown in Figure 12. The figure shows the indoor brightness value.


??? You can view Real-Time and historical data on the web browser, as shown in Figure 13.


??? It can be seen that, based on the C/S architecture, not only real-time data can be displayed, but also historical data can be viewed, in order to detect problems in time, more practical.

4 Conclusion
????
This article describes the content, features, interaction model, and subscription mechanism of the coap protocol in detail, and provides the system configuration method based on the uipv6 start kit wireless network development kit, the network can implement coap protocol through Firefox and client software. Users can not only read real-time data on the sensor, but also view historical data.

Src = http://www.21ic.com/app/rf/201304/178560_3.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.