IoT Gateway Supporting Communication with Web Servers

Overview

With the development of the Internet of Things (IoT), more and more devices need to connect to the cloud. These devices include various instruments, industrial equipment, collection devices, and sensors, most of which use serial ports (RS232, RS485). Therefore, IoT gateways such as serial-to-TCP and serial-to-WiFi can be used to transmit data to the cloud. However, due to different protocols when communicating with cloud servers, developers need to create various backend programs to facilitate data conversion and storage.

The new “IoT Gateway Supporting Communication with Web Servers” can directly communicate with web servers using POST and GET commands. Users only need to write PHP code to achieve data conversion and storage, simplifying the development of the upper machine interface in IoT.

The biggest advantage of such IoT gateways is that they save development complexity, allowing the gateway to communicate directly with cloud servers using GET/POST commands.

Principle

Let’s discuss the usage and principle of such gateways. We know that when we enter the following link in the browser, it will submit data to the web server using a GET command.

Submitted Data Content:

This data content will be sent directly to the web server at IP address 192.168.1.180 on port 80. The PHP program running on the web server can correctly read data such as data=123456.

However, the issue with traditional transparent IoT gateways is:

The data sent from various instruments to the IoT gateway is not in standard GET command format. Therefore, the IoT gateway needs to perform data conversion, such as adding GET /1.php?data= before the data and appending HTTP/1.1 after it.

The data sent from various instruments is in hexadecimal format, but web servers easily handle string data. Therefore, it is necessary to convert hexadecimal to string.

Implementation Method

Products such as ZLAN5143 and ZLAN8343N can achieve the above functionality. The steps are as follows:

Write a configuration file on the computer with the following content and then download it to the IoT gateway.

Note that the $ symbol represents the data received by the serial port. The IoT gateway will replace $ with the data received by the serial port, and then upload the content of this configuration file to the web server. This way, the web server can receive serial data in the format of GET commands.

If you need to convert the data format from hexadecimal to string first, use the # symbol instead of the $ symbol in the configuration file.

From this, we see that such gateways not only support GET commands from web servers but also can be flexibly designed. It is a versatile method to add prefixes before and suffixes after serial data.

Web Server Downlink

The above method only implements the function of converting serial hex data to GET commands when transferring data from the serial port to the network. However, if the web service needs to send data according to GET commands, a portion of that data also needs to be forwarded to the serial port.

For example, when the web server sends a GET command to the IoT gateway (IP address 192.168.0.200) at port 8080, the effective data in the GET command (here it is 61626364656667) is converted into hexadecimal data (abcdefg) and output from the gateway’s serial port to the controller and actuator. As shown in the figure below:

The implementation method is to add the line: NFL: data=# HTTP/1.1 at the beginning of the original configuration file. The IoT gateway will search for the prefix data= and suffix HTTP/1.1 when it receives any network data, extract the middle part, and convert it to hexadecimal for output from the serial port.

The implementation of the web server downlink function is also aided by ZLAN IoT’s ability to act as a TCP client when uploading data while also being able to receive connections and data from the web server as a TCP server.

Conclusion

IoT gateways that can directly communicate with web servers via GET commands—both receiving and sending data—can greatly reduce the development workload of cloud programs. This type of IoT gateway facilitates the integration and access of IoT network devices.

IoT Gateway Supporting Communication with Web Servers

IoT Gateway Supporting Communication with Web Servers

Leave a Comment