Multi-bus adaptive protocol intelligent Internet of Things gateway system

By designing a multi-bus adaptive protocol intelligent IoT gateway system, and adopting a domestic CPU and SM4 encryption algorithm, the system achieves automatic sensor address detection and data encryption, solves the problem of unknown sensor bus protocol addresses, and provides an independent IoT gateway system.

CN119030826APending Publication Date: 2024-11-26NANJING TECH UNIV
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410998160.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-24
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

In existing technologies, the unknown address of the sensor bus protocol makes it impossible to read data, and there is a lack of domestically developed IoT gateway systems, which makes it impossible to achieve independent data encryption and transmission.

Method used

A multi-bus adaptive protocol intelligent IoT gateway system was designed. It adopts a domestic CPU as the main controller and integrates multiple controllers and interfaces. It supports bus interfaces such as I2C, UART, and SPI. Through adaptive protocol detection and SM4 encryption algorithm, it realizes automatic detection of sensor addresses, data encryption and uploading.

Benefits of technology

It achieves automatic sensor address detection and data encryption, reduces dependence on foreign solutions, and provides an application development environment with strong autonomy, innovation and adaptability. It features multiple interface access, good performance, high stability and convenient operation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119030826A_ABST
    Figure CN119030826A_ABST
Patent Text Reader

Abstract

The invention, which relates to the technical field of the Internet of Things gateway, discloses a multi-bus adaptive protocol intelligent Internet of Things gateway system comprising a sensor equipment layer, a protocol conversion layer and a cloud server. Wherein the sensor equipment layer is used for collecting environment data and equipment state information as sensor data, and uploading the environment data and the equipment state information to the protocol conversion layer through a sensor bus; the protocol conversion layer is used for acquiring sensor data acquired by different sensors, and packaging and uploading the sensor data to a remote server through adaptive protocol detection and data encryption; and the cloud server is used for receiving, storing, analyzing and displaying the sensor data from the sensor, providing a user access interface, and accessing and managing Internet of Things equipment and data. According to the invention, the expandability of platform functions is improved through hierarchical and modular hardware design; and an autonomic, innovative and adaptive application development environment can be provided for various bus sensors.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of Internet of Things gateways, and in particular to a multi-bus adaptive protocol intelligent Internet of Things gateway system. Background Art

[0003] General-purpose processors are the basic components of the information industry and the core components of electronic devices. In recent years, chip manufacturers have developed domestically produced high-performance processors in the domestic market. Based on the domestically produced independent instruction set LoongArch, they have rich on-chip resources and a small area. They have the advantages of high performance, low power consumption, low price, and strong scalability, and are widely used in commercial and industrial control fields.

[0004] At present, the competition in the field of cybersecurity and informatization is severe. It is necessary to improve the competitiveness of domestic core technologies and adopt an "independent" development strategy of "independent design, independent research and development, and independent production". Using foreign instruction systems can develop and produce products, but it is impossible to form a domestic independent industrial ecology. Therefore, it is necessary to achieve independence from the root of the instruction system and establish a domestic independent information and innovation industry ecology. Summary of the invention

[0005] Based on this, it is necessary to provide a multi-bus adaptive protocol intelligent Internet of Things gateway system to address the above technical problems.

[0006] The present invention provides a multi-bus adaptive protocol intelligent Internet of Things gateway system, which includes: a sensor device layer, a protocol conversion layer and a cloud server;

[0007] Among them, the sensor device layer is used to collect environmental data and device status information as sensor data, and upload it to the protocol conversion layer through the sensor bus;

[0008] The protocol conversion layer is used to obtain sensor data collected by different sensors, and to package and upload the sensor data to the remote server through adaptive protocol detection and data encryption;

[0009] Cloud servers are used to receive, store, analyze and display sensor data from sensors, and provide user access interfaces to access and manage IoT devices and data.

[0010] Furthermore, the protocol conversion layer includes: a bus interface, a main control board and an expansion board;

[0011] Among them, the bus interface is used to access the sensor bus, obtain sensor data, realize data transmission, and support bus interfaces of multiple protocols;

[0012] The main control board is used to carry an embedded processor, provide computing power, support communication protocol conversion and data encryption packaging, and connect to the expansion board using a general input and output interface;

[0013] Expansion board, used for sensor buses based on different protocols, expanding multiple types of functional circuits, connecting and driving functional components and sensor devices.

[0014] Further, the expansion board includes: a power supply voltage conversion circuit, a temperature and humidity sensor circuit, a light intensity sensor circuit, an OLED display circuit, and a button and LED expansion circuit;

[0015] Among them, the power supply voltage conversion circuit is used to carry the switching power supply chip to convert the 12V DC power provided by the main control board into a 5V voltage output;

[0016] The temperature and humidity sensor circuit is used to expand the connection of temperature and humidity sensors based on the I2C0 bus to detect the current ambient temperature and humidity;

[0017] The light sensor circuit is used to expand the connection of the light sensor based on the I2C0 bus to detect the current ambient light intensity;

[0018] OLED display circuit, used to expand the connection of OLED display based on SPI bus, and provide visual display of current sensor number and environmental parameters;

[0019] The button and LED expansion circuit is used to expand the connection between buttons and LED light-emitting diodes based on the general input and output interface, and perform human-computer interaction through button touch;

[0020] Furthermore, the expansion board also includes: a serial port expansion circuit and a peripheral expansion circuit;

[0021] Among them, the serial port expansion circuit is used to carry the serial port conversion chip and the interface chip, transmit and receive serial port data based on the USB interface, and realize the conversion of level signals;

[0022] The peripheral expansion circuit is used to expand multiple industrial temperature sensors based on the UART3 bus and detect the temperature at multiple points in the industrial field.

[0023] Furthermore, the main control board includes: a protocol detection module, an encryption packaging module, an operation program module, a protocol setting module and a remote display module;

[0024] Among them, the protocol detection module is used to perform self-detection and adaptive protocol configuration of the bus protocol after the system is turned on, and automatically detect the communication protocol of the sensor bus;

[0025] The encryption and packaging module is used to encrypt the sensor data using a parallel encryption method, and after the encryption is completed, it is packaged into message queue telemetry transmission protocol data and sent to the cloud;

[0026] The operating program module is used to develop monitoring host computer software based on the application development framework, and read, configure and store sensor data collected in real time;

[0027] The protocol setting module is used to set the message queue telemetry transmission protocol to realize the transmission between sensor data and remote data;

[0028] The remote display module is used to establish a communication connection with the mobile program and display the sensor data collected by the sensor device in real time.

[0029] Further, the protocol detection module includes: an I2C bus protocol detection unit, an RS485 bus detection unit and a device button drive unit;

[0030] Among them, the I2C bus protocol detection unit is used to first perform I2C bus sensor detection after the system is turned on, automatically detect the address of the I2C bus protocol, and after the I2C bus detection is completed, prompt to enter the RS485 bus detection unit for detection;

[0031] The RS485 bus detection unit is used to connect the slave devices with device addresses of 1 to 255 by enumeration, and then store the device addresses of the successfully connected devices;

[0032] The device button driver unit is used to program LED drivers and button drivers, serving as function buttons and indicators for the adaptive protocol gateway.

[0033] Furthermore, the sensor detection of the I2C bus is first performed, and the address of the I2C bus protocol is automatically detected, including:

[0034] S11, search for I2C bus devices. If the search is successful, configure the I2C bus device to read mode and go to S12;

[0035] S12, configure the slave device address to be read to 1, and go to S13;

[0036] S13, if the device address is greater than 128, go to S16; otherwise, call the function to read the slave device and go to S14;

[0037] S14, if the data is read successfully, the device address is found successfully, the device address is stored, and the process goes to S15; if the data is not read successfully, the process goes to S15;

[0038] S15, configure the slave device address to be read plus 1, and go to S13;

[0039] S16. The program ends and all device addresses are stored.

[0040] Furthermore, the slave devices with device addresses of 1 to 255 are connected by enumeration, and the device addresses of the successfully connected devices are stored, including:

[0041] S21, search for RS485 bus device, if the search is successful, configure the RS485 bus device to read mode, and go to S22;

[0042] S22, configure the slave device address to be read to 1, and go to S23;

[0043] S23, if the device address is less than 250, go to S26; otherwise try to connect to the slave device and go to S24;

[0044] S24, if the device is successfully connected, disconnect the slave device, store the device address, and go to S25; if the data reading is unsuccessful, go to S25;

[0045] S25, configure the slave device address to be read plus 1, and go to S23;

[0046] S26. The program ends and all device addresses are stored.

[0047] Furthermore, the sensor data is encrypted using a parallel encryption method, and after encryption is completed, it is packaged into message queue telemetry transmission protocol data and sent to the cloud including:

[0048] S31, dividing the sensor data to be encrypted into blocks of 16 bytes;

[0049] S32, creating a process pool, and assigning the segmented data blocks to each process for processing, and each process in the process pool independently performs the encryption task;

[0050] S33, putting the segmented data blocks into the input queue one by one, each process selects a data block from the input queue, encrypts the data block using the SM4 algorithm, and puts the encrypted data block into the output queue;

[0051] S34, after all data blocks are encrypted, the encrypted data blocks are taken out from the output queue in order, and all data blocks are merged to obtain complete encrypted data;

[0052] S35. Pack the encrypted data into message queue telemetry transmission protocol data and send it to the cloud server.

[0053] Furthermore, the monitoring host computer software includes an automatic address detection function, a sensor data reading function, and a message queue telemetry transmission protocol data sending function.

[0054] The beneficial effects of the present invention are:

[0055] 1. By adopting domestic design solutions, the scalability of platform functions is improved with hierarchical and modular hardware design; first, an expansion board is designed based on the domestic CPU to realize multi-bus sensor data acquisition; secondly, an automatic address detection function is designed based on the multi-bus protocol, which can automatically detect the sensor address; the data is encrypted based on the domestic encryption algorithm SM4; finally, an adaptive protocol host computer software is designed based on the domestic CPU hardware, which can perform address management, automatic sensor addition, data storage and upload to the cloud.

[0056] 2. The present invention uses a signal processing board with a domestically produced CPU as the main control, integrates a variety of controllers and interfaces, and transplants the more adaptable LoongOS operating system management platform resources; configures an environment based on the QT interface, conducts multi-bus experiments and performance parameter tests, and verifies that the platform has the ability to complete the automatic adaptation protocol adaptation processing of multiple buses. Compared with traditional sensor gateways, the domestic design of the present invention can not only replace foreign solutions and effectively reduce dependence on imports, but also has the characteristics of multiple interface access, good performance, high stability, convenient operation, strong expansion capability, strong adaptability, etc., and can provide an autonomous, innovative, and adaptable application development environment for multiple bus sensors. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0058] Figure 1 is a system principle block diagram of a multi-bus adaptive protocol intelligent Internet of Things gateway system according to an embodiment of the present invention;

[0059] Figure 2 is a write format of an I2C bus protocol frame according to an embodiment of the present invention;

[0060] Figure 3 is a read format of an I2C bus protocol frame according to an embodiment of the present invention;

[0061] Figure 4 is a general Modbus data frame format according to an embodiment of the present invention;

[0062] Figure 5 is a functional block diagram of a multi-bus adaptive protocol gateway according to an embodiment of the present invention;

[0063] Figure 6 is a hardware structure diagram of an intelligent gateway system according to an embodiment of the present invention;

[0064] Figure 7 is a schematic diagram of a power supply voltage conversion circuit according to an embodiment of the present invention;

[0065] Figure 8 is a schematic diagram of a detection circuit of an AHT20 temperature and humidity sensor according to an embodiment of the present invention;

[0066] Fig. 9 is a schematic diagram of a BH1750 light intensity sensor circuit according to an embodiment of the present invention;

[0067] Fig.10 is a schematic diagram of an OLED display screen circuit according to an embodiment of the present invention;

[0068] Fig.11 is a schematic diagram of a button and LED expansion circuit according to an embodiment of the present invention;

[0069] Fig.12 is a schematic diagram of a serial port expansion circuit according to an embodiment of the present invention;

[0070] Fig.13 1 is a schematic diagram of an RS485 bus expansion circuit according to an embodiment of the present invention;

[0071] Fig.14 is a schematic diagram of a peripheral expansion circuit according to an embodiment of the present invention;

[0072] Fig.15 is a flow chart of data encryption processing according to an embodiment of the present invention;

[0073] Fig.16 is a parallel encryption flow chart according to an embodiment of the present invention;

[0074] Fig.17 is a flowchart of SM4 encryption according to an embodiment of the present invention;

[0075] Fig.18 is a flow chart of SM4 decryption according to an embodiment of the present invention;

[0076] Fig.19 is a flowchart of automatic detection of I2C bus protocol addresses according to an embodiment of the present invention;

[0077] Fig. 20 is a flow chart of automatic detection of MODBUS bus protocol address according to an embodiment of the present invention;

[0078] Fig.21 is a flow chart of GPIO driver code implementation according to an embodiment of the present invention;

[0079] Fig. 22 It is a hardware layer and application layer driver according to an embodiment of the present invention;

[0080] Fig.23 is an intelligent gateway address detection interface according to an embodiment of the present invention;

[0081] Fig.24 is a smart gateway sensor reading interface according to an embodiment of the present invention;

[0082] Fig.25 It is the intelligent gateway MQTT data transmission according to an embodiment of the present invention;

[0083] Fig.26 is a flowchart of a mobile phone applet according to an embodiment of the present invention;

[0084] Fig. 27 It is a mobile phone applet according to an embodiment of the present invention that displays current sensor data.

[0085] Figure numbers: 1. Sensor device layer; 2. Protocol conversion layer; 3. Cloud server. DETAILED DESCRIPTION

[0086] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0087] See also Figure 1 , provides a multi-bus adaptive protocol intelligent Internet of Things gateway system, the system includes: a sensor device layer 1, a protocol conversion layer 2 and a cloud server 3.

[0088] Specifically, the gateway can realize data collection and uploading from multiple sensors.

[0089] Among them, the I2C bus protocol and the MODBUS protocol based on the RS485 bus are the most commonly used sensor protocols.

[0090] 1) I2C bus

[0091] I2C (Inter-Integrated Circuit) is used to connect integrated circuit modules (IC) within a board. It uses a bidirectional 2-wire serial data. The I2C bus is a multi-master bus, and each node can be set with a unique address, so multiple sensors can be connected to the bus. The data operations of the I2C bus mainly include read operations and write operations.

[0092] A write operation is when the host sends data to the slave. Figure 2 As shown in the figure, the host will send a start signal to the bus, followed by the first byte of 8-bit data, 7-bit address and data direction bit, "0" for write. When the data is transmitted, the host will send a stop signal to stop the bus.

[0093] Read operation refers to the slave sending data to the master. The bus operation format is as follows: Figure 3 As shown in the figure. The host sends a start signal, and the first two bytes transmitted are the same as the write operation; but after the second byte, the bus must be restarted to change the direction of data transmission. The final stop signal is also sent by the host.

[0094] 2) RS485 bus and MODBUS protocol

[0095] The MODBUS bus protocol based on hardware RS485 defines a simple protocol data unit (PDU) that is independent of the underlying communication layer. The MODBUS protocol mapping on a specific bus or network can introduce some additional fields on the application data unit (ADU). The general MODBUS data frame format is as follows: Figure 4 As shown in the figure. The MODBUS protocol establishes a request format initiated by the client. The address field in the MODBUS data frame is encoded with one byte, so multiple sensors can be connected to the MODBUS bus; the function code field of the MODBUS data unit is encoded with one byte. The valid codeword range is decimal 1-255 (128-255 is reserved for abnormal responses). Sub-function codes are added to some function codes to define multiple operations.

[0096] In general, sensor buses often use the I2C bus protocol and the modbus protocol of the RS485 bus. Sensors are connected to the same bus and are distinguished by addresses. If the address and communication parameters are unknown, the sensor data cannot be read.

[0097] The invention designs an intelligent gateway of an adaptive protocol based on a domestically produced CPU and is connected to a sensor, and can perform automatic address detection, automatic data reading, automatic parameter storage and automatic parameter configuration.

[0098] The specific functional block diagram is as follows Figure 5 As shown in the figure, the smart gateway is divided into three layers. The sensor device layer is connected to the protocol conversion layer based on the I2C bus and RS485 bus. The cloud service receives and displays the sensor device layer data.

[0099] The system hardware structure is as follows Figure 6As shown in the figure, the 60-core extended GPIO (general input / output port) led out from the main control board based on the domestic CPU (such as the embedded processor 2K1000LA) includes common bus interfaces such as I2C, UART, SPI, and CAN. The system design expands the onboard BH1750 sensor and AHT20 sensor circuit based on the I2C0 bus to measure the current ambient temperature, humidity, and light intensity; expands 3 DS18B20 industrial temperature sensors based on the UART3 bus to test the multi-point temperature of the industrial site; expands the OLED display based on the SPI bus to display the current field sensor data and environmental parameters; expands the touch button and LED light-emitting diode based on the ordinary GPIO for human-computer interaction.

[0100] The present invention takes the embedded processor 2K1000LA as an example, which is carried by Loongson. On the basis of achieving pin and interface compatibility with the original version 2K1000, the processor is updated to the LA264 processor core based on LoongArch (abbreviated as Dragon Architecture). The hardware interface of the processor 2K1000LA is fully compatible with 2K1000, and the performance and power consumption are optimized by adjusting the design. Mainstream interfaces including USB, GMAC, SATA, and PCIE are provided, which can meet the product application of multiple scenarios, and is also the first choice for entry-level hardware for domestic development.

[0101] In one embodiment, the sensor device layer 1 is used to collect environmental data and device status information as sensor data, and upload them to the protocol conversion layer through the sensor bus.

[0102] In one embodiment, the protocol conversion layer 2 is used to obtain sensor data collected by different sensors, and to package the sensor data and upload it to a remote server through adaptive protocol detection and data encryption.

[0103] In the description of the present invention, the protocol conversion layer 2 includes: a bus interface, a main control board and an expansion board.

[0104] The bus interface is used to access the sensor bus, obtain sensor data, realize data transmission, and support bus interfaces of multiple protocols.

[0105] The main control board is used to carry an embedded processor, provide computing power, support communication protocol conversion and data encryption packaging, and connect to the expansion board using a general input and output interface.

[0106] In the description of the present invention, the main control board includes: a protocol detection module, an encryption packaging module, an operation program module, a protocol setting module and a remote display module.

[0107] The protocol detection module is used to perform self-detection and adaptive protocol configuration of the bus protocol after the system is turned on, and automatically detect the communication protocol of the sensor bus.

[0108] In the description of the present invention, the protocol detection module includes: an I2C bus protocol detection unit, an RS485 bus detection unit and a device key driving unit.

[0109] Among them, the I2C bus protocol detection unit is used to first perform I2C bus sensor detection after the system is turned on, automatically detect the address of the I2C bus protocol, and after the I2C bus detection is completed, prompt to enter the RS485 bus detection unit for detection.

[0110] In the description of the present invention, Fig.19 As shown, the sensor detection of the I2C bus is first performed, and the address of the I2C bus protocol is automatically detected, including:

[0111] Step S11, search for an I2C bus device. If the search is successful, configure the I2C bus device to read mode and go to step S12.

[0112] Step S12: configure the slave device address to be read to 1, and go to step S13.

[0113] Step S13: If the device address is greater than 128, go to step S16. Otherwise, call the slave device read function and go to step S14.

[0114] Step S14: If the data is read successfully, the device address is found successfully, the device address is stored, and the process goes to step S15. If the data is read unsuccessfully, the process goes to step S15.

[0115] Step S15, configure the slave device address to be read plus 1, and go to step S13.

[0116] Step S16: The program ends and all device addresses are stored.

[0117] The RS485 bus detection unit is used to connect slave devices with device addresses of 1 to 255 in an enumeration manner, and then store the device addresses of successfully tested connections.

[0118] In the description of the present invention, Fig. 20 As shown, the slave devices with device addresses of 1 to 255 are connected by enumeration, and the device addresses of the successfully connected devices are stored, including:

[0119] Step S21, search for RS485 bus device, if the search is successful, configure the RS485 bus device to read mode, and go to step S22.

[0120] Step S22, configure the slave device address to be read to 1, and go to step S23.

[0121] Step S23: If the device address is less than 250, go to step S26. Otherwise, try to connect to the slave device, go to step S24.

[0122] Step S24: If the device is successfully connected, disconnect the slave device, store the device address, and go to step S25. If the data reading is unsuccessful, go to step S25.

[0123] Step S25, configure the slave device address to be read plus 1, and go to step S23.

[0124] Step S26: The program ends and all device addresses are stored.

[0125] After the Modbus protocol sensor detection of the RS485 bus is completed, the system pops up a dialog box to prompt the user to confirm the sensor information and then enter the sensor data detection process.

[0126] In order to track the operation process of the system, LED display indicators are designed to dynamically and graphically indicate the status of the system operation process.

[0127] The device button driver unit is used to program LED drivers and button drivers, serving as function buttons and indicators for the adaptive protocol gateway.

[0128] LED drivers and button drivers are written based on GPIO devices as function buttons and indicators of the adaptive protocol gateway. GPIO drivers are designed and compiled into static library functions for the main program to call. The driver code implementation process is as follows: Fig.21 shown.

[0129] The key code is:

[0130] int gpio_init(int gpio_num,char*mode)

[0131] {

[0132] int fd,len;

[0133] char*file_export=" / sys / class / gpio / export";

[0134] char file_gpiox_direction

[64] ;

[0135] char file_gpiox_value

[64] ;

[0136] char file_gpioxout_direction

[64] ;

[0137] char file_gpioxout_value

[64] ;

[0138] char gpio_num_char

[64] ;

[0139] sprintf(gpio_num_char,"%d",gpio_num);

[0140] sprintf(file_gpiox_direction,"%s / gpio%d / direction"," / sys / class / gpio",gpio_num);

[0141] sprintf(file_gpiox_value,"%s / gpio%d / value"," / sys / class / gpio",gpio_num);

[0142] if(open_write(file_export,gpio_num_char)) / / Export GPIO

[0143] {

[0144] printf("open_write %s %s failed!\n",file_export,gpio_num_char);

[0145] }

[0146] if(open_write(file_gpiox_direction,mode)) / / Set mode

[0147] {

[0148] printf("open_write %s %s failed!\n",file_gpiox_direction,gpio_num_char);

[0149] }

[0150] }

[0151] int gpio_read(int gpio_num)

[0152] {

[0153] int fd,len;

[0154] char* file_export = " / sys / class / gpio / export";

[0155] char file_gpiox_direction

[64] ;

[0156] char file_gpiox_value

[64] ;

[0157] char file_gpioxout_direction

[64] ;

[0158] char file_gpioxout_value

[64] ;

[0159] char gpio_num_char

[64] ;

[0160] char gpio_value_char

[64] ;

[0161] sprintf(gpio_num_char, "%d", gpio_num);

[0162] sprintf(file_gpiox_direction, "%s / gpio%s / direction", " / sys / class / gpio", gpio_num_char);

[0163] sprintf(file_gpiox_value, "%s / gpio%s / value", " / sys / class / gpio", gpio_num_char);

[0164] if (access(file_gpiox_value, F_OK)) / / Check if the file exists

[0165] {

[0166] if (open_write(file_export, gpio_num_char)) / / Export GPIO

[0167] {

[0168] printf("open_write %s %s failed!\n", file_export, gpio_num_char);

[0169] }

[0170] }

[0171] if(open_write(file_gpiox_direction,"in")) / / Set to input mode

[0172] {

[0173] printf("open_write%s%s failed!\n",file_gpiox_direction,gpio_num_char);

[0174] }

[0175] char value[2]={0};

[0176] if(open_read(file_gpiox_value,value,1)) / / Read the port value

[0177] {

[0178] printf("open_read%s failed!\n",file_gpiox_value);

[0179] }

[0180] else

[0181] {

[0182] printf("open_read%s value is%s\n",file_gpiox_value,value);

[0183] }

[0184] return atoi(value);

[0185]

[0186] printf("write%s%sfailed!\n",file_gpiox_direction,gpio_num_char);

[0187] return -1;

[0188] }

[0189] if(open_write(file_gpioxout_value,gpio_value_char)) / / Set the output value

[0190] {

[0191] printf("open_write%s%s failed!\n",file_gpiox_value,gpio_value_char);

[0192] return -1;

[0193] }

[0194] return 0;

[0195] }

[0196] The code of the makefile file compiled into a static library is as follows:

[0197] static-lib = libls2kla.a

[0198] $(static-lib): gpio.o aht20.o i2c.o bh1750.o oled.o

[0199] ar - rc $@ $^

[0200] %.o: %.c

[0201] $(CC) - c $<

[0202] .PHONY: install

[0203] install:

[0204] mkdir - p install / lib

[0205] mkdir - p install / include

[0206] cp - rf *.h install / include

[0207] cp - rf *.a install / lib

[0208] mkdir - p.. / test_lib / install / lib

[0209] mkdir - p.. / test_lib / install / include

[0210] cp - rf *.h.. / test_lib / install / include

[0211] cp - rf *.a.. / test_lib / install / lib

[0212] clean:

[0213] rm -rf *.o *.a libls2kla

[0214] Similarly, write the I2C underlying driver and AHT20, BH1750, OLED driver, and export functions, such as Fig. 22 shown.

[0215] The encryption and packaging module is used to encrypt the sensor data using a parallel encryption method, and after the encryption is completed, it is packaged into message queue telemetry transmission protocol data and sent to the cloud.

[0216] Specifically, the multi-bus adaptive intelligent gateway based on the processor 2K1000LA is mainly used in application scenarios such as industrial control and the Internet of Things. Data transmission and storage in these scenarios require a high degree of security and reliability to prevent unauthorized access and tampering of data. The use of the SM4 encryption algorithm can significantly improve the security performance of the system, meet the relevant standards and requirements of the National Cryptography Administration, and ensure the confidentiality and integrity of data during transmission and storage.

[0217] The SM4 algorithm is compact in design and has moderate computational complexity. It is suitable for software and hardware implementation and can run efficiently on a variety of platforms. Its main features include symmetry, block encryption, and high security. Symmetry means that the same key is used for encryption and decryption, which simplifies the complexity of key management and distribution. Block encryption allows fixed-length data blocks (128 bits) to be processed each time, which improves processing efficiency. Through rigorous mathematical analysis and extensive practical application verification, the SM4 algorithm has demonstrated its strong ability in anti-attack and data protection.

[0218] The overall implementation steps are as follows Fig.15 As shown, including the following aspects:

[0219] 1. Data acquisition and processing: Collect sensor data through I2C and RS485 buses and pre-process the data.

[0220] 2. Data encryption: Use SM4 algorithm to encrypt and store the collected data;

[0221] 3. Data transmission: Pack the encrypted data into MQTT protocol (Message Queue Telemetry Transport Protocol) data and send it to the cloud.

[0222] 4. Data decryption: Use the inverse operation of the SM4 algorithm to decrypt the collected data

[0223] In the description of the present invention, a parallel encryption method is used to encrypt sensor data, and after encryption is completed, it is packaged into message queue telemetry transmission protocol data and sent to the cloud, including:

[0224] Step S31, the sensor data to be encrypted is divided into blocks of 16 bytes (assuming that there is a large section of data to be encrypted, this section of data will be divided into several small blocks of 16 bytes. Each small block will be encrypted independently).

[0225] Step S32: create a process pool (use Python's multiprocessing library to create a process pool), and distribute the segmented data blocks to each process for processing. Each process in the process pool independently performs the encryption task.

[0226] Step S33: put the segmented data blocks into the input queue one by one. Each process selects a data block from the input queue, encrypts the data block using the SM4 algorithm, and puts the encrypted data block into the output queue.

[0227] Step S34: After all data blocks are encrypted, the encrypted data blocks are taken out from the output queue in order, and all data blocks are merged to obtain complete encrypted data.

[0228] Step S35: Pack the encrypted data into Message Queue Telemetry Transport Protocol (MQTT protocol) data and send it to the cloud server.

[0229] The above parallel computing method can significantly improve the execution efficiency of the SM4 encryption algorithm, especially when processing large-scale data, and can fully utilize the computing power of multi-core processors to achieve faster encryption operations. Fig.16 shown.

[0230] In the encryption process of the SM4 algorithm, the overall design of the sender's information encryption system is as follows:

[0231] The SM4 encryption process is to divide the plaintext information into specified block sizes, then iteratively encrypt each small block, and then output the encrypted ciphertext block.

[0232] A software random number generator (SRNG) generates a 128-bit random master key. Ensure that the randomly generated key has sufficient entropy and unpredictability to prevent the key from being guessed or cracked.

[0233] The 128-bit master key is transformed linearly and nonlinearly into 32 round keys (RK). The 128-bit plaintext is divided into four 32-bit groups X0, X1, X2, and X3, and 32 rounds of iterations are performed, each round using a round key for encryption. Finally, 128-bit ciphertext data is output. The SM4 encryption algorithm is as follows: Fig.17 Shown

[0234] For the overall design of the recipient's decryption system:

[0235] Divide the received 128-bit ciphertext into four 32-bit groups: Y0, Y1, Y2, and Y3. Perform 32 rounds of iterations, using a round key for decryption in each round. Each round of operation is the same as the encryption process, except that the order of using the round keys is reversed. The output is: 128-bit plaintext data. The decryption process is as follows: Fig.18 shown.

[0236] The operating program module is used to develop monitoring host computer software based on the application development framework to read, configure and store sensor data collected in real time.

[0237] Specifically, 1) Interface design

[0238] In order to better monitor the system, this system has developed a monitoring host computer software based on Qt (application development framework), realizing functions such as data collection, monitoring and remote transmission. The host computer is developed using the cross-platform development environment Qt Creator, which supports multiple platforms such as Windows and Linux. It can roughly include event-driven, graphics engine and controls, and is the most commonly used host computer development technology in embedded development.

[0239] This paper designs the host computer interface of the adaptive protocol intelligent gateway of the processor 2K1000LA based on QT, which can automatically read the sensor data according to the configuration parameters when the system is turned on by accurately detecting the address of the sensor and automatically storing the configuration information.

[0240] 2) Functional design

[0241] The adaptive protocol intelligent gateway system is designed with three interfaces. Fig.23 As shown, the automatic address detection function is realized. When the address detection button is clicked, the address of the current sensor is searched according to the set detection method. After the address is found, it will be automatically displayed in the list, and the user can choose to save the current address. When the detection is completed, you can choose to save the current address and click Next to enter the sensor reading operation interface.

[0242] The second interface is as follows Fig.24 As shown in the figure, the intelligent gateway sensor reading function of the adaptive protocol is realized. When the reading button is clicked, the sensor data corresponding to the current address is read. When the reading is completed, you can choose to save the current data and click Next to enter the MQTT data sending operation interface.

[0243] The third interface is as follows Fig.25 As shown in the figure, the MQTT data sending function of the smart gateway sensor with adaptive protocol is realized. When the connect button is clicked, the current gateway is connected to the remote server based on the MQTT protocol. When the reading is completed, you can choose to save the current data and click Next to enter the MQTT data sending operation interface.

[0244] The protocol setting module is used to set the message queue telemetry transmission protocol to realize the transmission between sensor data and remote data.

[0245] Specifically, MQTT (Message Queue Telemetry Transport) is a message publish / subscribe transport protocol based on clients and servers. It is based on the TCP protocol, and the default port number is 1883. Here, the transmission of sensor data and cloud data is realized based on the MQTT protocol.

[0246] To use the MQTT protocol in Qt, compile the QMQTT source code provided by the open source MQTT messaging service EMQTT for Qt. Make corresponding modifications in the QT project:

[0247] (1) Modify the pro file and make relevant compilation settings. The qmake.pro file configures QT+=network.

[0248] (2) Initialization of code addition:

[0249] client=newQMQTT::Client(QHostAddress(Address),1883).

[0250] The key code for mqtt connection in the program is:

[0251] client->setClientId(ClientId);

[0252] client->setUsername(Username);

[0253] client->setPassword(Password.toLatin1());

[0254] client->setVersion(QMQTT::MQTTVersion::V3_1_1);

[0255] client->setKeepAlive(120);

[0256] client->setHostName(Address);

[0257] client->setPort(1883);

[0258] client->connectToHost();

[0259] connect(client,SIGNAL(received(QMQTT::Message)),this,SLOT(doproce ss_receivemessage(QMQTT::Message)));

[0260] The remote display module is used to establish a communication connection with the mobile program and display the sensor data collected by the sensor device in real time.

[0261] Specifically, the remote network platform is developed using WeChat developer tools. The communication between the collected data and the cloud is packaged into MQTT for transmission using the TCP / IP protocol. Its main functions include data collection, cloud platform connection and visualization. When the mini program is successfully connected to the cloud platform, the mini program can receive real-time collected data and visualize it through ECharts.

[0262] WeChat applet is designed based on json language and developed using page flow. Each page has buttons, actions, interfaces, etc. The WeChat applet of this smart gateway system has designed 4 pages. The initialization page is used to configure the network token cloud server. The background program obtains the cloud temperature, humidity, and light intensity and displays them on the other 3 pages. Fig. 27 shown.

[0263] Expansion board, used for sensor buses based on different protocols, expanding multiple types of functional circuits, connecting and driving functional components and sensor devices.

[0264] In the description of the present invention, the expansion board includes: a power supply voltage conversion circuit, a temperature and humidity sensor circuit, a light intensity sensor circuit, an OLED display screen circuit, and a button and LED expansion circuit.

[0265] The power supply voltage conversion circuit is used to carry the switching power supply chip to convert the 12V DC power provided by the main control board into a 5V voltage output.

[0266] Specifically, the power supply voltage conversion circuit is as follows Figure 7 As shown, the Loongson Pi motherboard provides 12V DC power, which is converted into 5V voltage output after being transformed by the TPS5430 switching power chip and the surrounding resistors and capacitors. The voltage conversion formula is shown below.

[0267]

[0268] The temperature and humidity sensor circuit is used to expand the connection of temperature and humidity sensors based on the I2C0 bus to detect the current ambient temperature and humidity.

[0269] Specifically, the AHT20 temperature and humidity sensor detection circuit schematic diagram is as follows Figure 8As shown, the AHT20 temperature and humidity sensor is a digital sensor based on the I2C bus. It is connected to the CPU through the SCL and SDA buses of the I2C bus. The address of its 7-bit chip is 0x38.

[0270] The AHT20 temperature and humidity sensor is a digital humidity and temperature sensor produced by Aosong (GuangzhouAoSong Electronics Co., Ltd.). It is an improved version of the AHT10, using more advanced technology to provide higher performance and more accurate measurement results.

[0271] The light sensor circuit is used to expand the connection of light sensors based on the I2C0 bus to detect the current ambient light intensity.

[0272] Specifically, the principle of the BH1750 light sensor detection circuit is as follows Fig. 9 As shown, the BH1750 light sensor is a digital sensor based on the I2C bus. It is connected to the CPU through the SCL and SDA buses of the I2C bus. The address of the 7-bit chip is 0x23.

[0273] BH1750 is a digital light intensity sensor that can digitally measure the light intensity of the surrounding environment. It is widely used in various light sensing control systems and automatic dimming systems. BH1750 communicates with the main controller through the I2C bus interface and outputs light intensity data in digital form. The main controller can obtain light intensity data by reading the digital signal output by BH1750.

[0274] The OLED display circuit is used to expand the connection to the OLED display based on the SPI bus to provide a visual display of the current number of sensors and environmental parameters.

[0275] Specifically, the schematic diagram of the OLED display circuit is as follows: Fig.10 As shown, the main control SSD1306 of the OLED display is a digital controller based on the I2C bus, which is connected to the CPU through the SCL and SDA buses of the I2C bus, and the address of its 7-bit chip is 0x3C.

[0276] SSD1306 is a popular OLED (Organic Light-Emitting Diode) display driver chip, which is widely used in various embedded systems and electronic devices to drive OLED displays.

[0277] The button and LED expansion circuit is used to expand the connection between buttons and LED light-emitting diodes based on the ordinary general input and output interface, and perform human-computer interaction through button touch.

[0278] Specifically, the button and LED display circuit schematic diagram is as follows Fig.11 As shown, the LED is driven by low level lighting. When lit, the current passing through is about 1mA, and the current calculation formula is shown below.

[0279]

[0280] The schematic diagram of the key circuit is as follows Fig.11 As shown in the figure, the GPIO in the key detection circuit uses an internal pull-up input. When the pin is floating, the input level is high; when the key is pressed, the pin level is low. When the key is pressed, the current passing through is about 7mA, and the current calculation formula is shown in the following formula.

[0281]

[0282] In the description of the present invention, the expansion board also includes: a serial port expansion circuit and a peripheral expansion circuit.

[0283] Among them, the serial port expansion circuit is used to carry the serial port conversion chip and the interface chip, and transmit and receive serial port data based on the USB interface to realize the conversion of level signals.

[0284] Specifically, the serial port signal conversion circuit schematic diagram is as follows Fig.12 As shown in the figure, CH340N is a serial port conversion chip that converts TTL level into USB bus level; the chip is powered by the 5V power supply of the USB interface. As long as the USB interface is connected to the PC, the chip will be powered on; after the chip is powered on, it will self-check on the PC side and mount the USB to serial port, so that serial port data can be sent and received based on the USB interface.

[0285] The circuit principle of RS485 bus and main control board expansion interface is as follows Fig.13 Adding the interface chip SP3485 realizes the conversion from TTL level to RS485 bus level; since RS-485 is differential level communication, when the distance is long or the rate is high, there is echo interference on the line. At this time, it is necessary to connect 120Ω matching resistors in parallel at both ends of the communication line.

[0286] In the software design, the libmodbus protocol was ported, and based on this protocol, a Modbus protocol driver based on RS485 bus was developed.

[0287] The peripheral expansion circuit is used to expand multiple industrial temperature sensors based on the UART3 bus and detect the temperature at multiple points in the industrial field.

[0288] Specifically, the schematic diagram of the peripheral expansion circuit is as follows: Fig.14As shown, SPI corresponds to the connection between the expansion board frame and the OLED display screen, three DS18B20 industrial temperature sensors are expanded based on the UART3 bus, and I2C corresponds to the connection between the expansion board frame and the AHT20 temperature and humidity sensor. This circuit brings out all the peripheral interfaces on the Loongson Pi through 3.54-pitch pin headers for related tests.

[0289] In addition, the overall structure of the printed circuit board PCB is compact, and a layer of copper is laid on the bottom plate as grounding and anti-interference. The vias are as small as possible, and the corners are rounded. Some capacitors are designed on the back, the connectors are close to the edge, and the high-frequency signal and clock signal lines are as short as possible. The four corners are equipped with screw holes with a diameter of 3mm to facilitate the fixing of the circuit board.

[0290] In one embodiment, the cloud server 3 is used to receive, store, analyze and display sensor data from sensors, and provide a user access interface to access and manage IoT devices and data.

[0291] The present invention designs a multi-bus adaptive protocol intelligent Internet of Things gateway system, which is based on the domestic LoongArch architecture CPU. First, a hardware expansion module is designed to collect data from multi-bus sensors; secondly, a hardware static library function is designed based on sensors and devices to facilitate the hierarchical and modular design of the system; finally, the resources of the LoongOS operating system management platform with higher adaptability are transplanted, and sensors of various buses are configured for automatic detection. The collected sensor data is packaged into MQTT protocol data and transmitted to the remote Internet of Things platform through the network. The test results show that the designed intelligent gateway can normally receive multi-bus data and upload data based on the MQTT protocol, thereby realizing the intelligent gateway communication function of multi-bus sensors.

[0292] In summary, with the help of the above technical scheme of the present invention, by adopting a domestic design scheme, the scalability of the platform function is improved with a hierarchical and modular hardware design; firstly, an expansion board is designed based on the embedded processor 2K1000LA to realize multi-bus sensor data acquisition; secondly, an automatic address detection function is designed based on the multi-bus protocol, which can automatically detect the sensor address; the data is encrypted based on the domestic encryption algorithm SM4; finally, an adaptive protocol host computer software is designed based on the domestic CPU hardware, which can perform address management, automatic sensor addition, data storage and upload to the cloud.

[0293] The present invention uses a signal processing board with a domestically produced CPU as the main control, integrates a variety of controllers and interfaces, and transplants the more adaptable LoongOS operating system management platform resources; configures an environment based on the QT interface, conducts multi-bus experiments and performance parameter tests, and verifies that the platform has the ability to complete the automatic adaptation protocol adaptation processing of multiple buses. Compared with traditional sensor gateways, the domestic design of the present invention can not only replace foreign solutions and effectively reduce dependence on imports, but also has the characteristics of multiple interface access, good performance, high stability, convenient operation, strong expansion capability, strong adaptability, etc., and can provide an autonomous, innovative, and adaptable application development environment for multiple bus sensors.

[0294] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

Claims

1. A multi-bus adaptive protocol intelligent Internet of Things gateway system, characterized in that: The system includes: a sensor device layer, a protocol conversion layer and a cloud server; The sensor device layer is used to collect environmental data and device status information as sensor data, and upload them to the protocol conversion layer through the sensor bus; The protocol conversion layer is used to obtain sensor data collected by different sensors, and to package and upload the sensor data to a remote server through adaptive protocol detection and data encryption; The cloud server is used to receive, store, analyze and display sensor data from sensors, and provide a user access interface to access and manage IoT devices and data.

2. A multi-bus adaptive protocol intelligent Internet of Things gateway system according to claim 1, characterized in that: The protocol conversion layer includes: a bus interface, a main control board and an expansion board; The bus interface is used to access the sensor bus, obtain sensor data, realize data transmission, and support bus interfaces of multiple protocols; The main control board is used to carry an embedded processor, provide computing power, support communication protocol conversion and data encryption packaging, and connect to the expansion board using a general input and output interface; The expansion board is used for sensor buses based on different protocols, expanding multiple types of functional circuits, and connecting and driving functional components and sensor devices.

3. A multi-bus adaptive protocol intelligent Internet of Things gateway system according to claim 2, characterized in that: The expansion board includes: a power supply voltage conversion circuit, a temperature and humidity sensor circuit, a light intensity sensor circuit, an OLED display screen circuit, and a button and LED expansion circuit; The power supply voltage conversion circuit is used to carry a switching power supply chip to convert the 12V DC power provided by the main control board into a 5V voltage output; The temperature and humidity sensor circuit is used to expand and connect the temperature and humidity sensor based on the I2C0 bus to detect the current ambient temperature and humidity; The light intensity sensor circuit is used to extend the connection of the light intensity sensor based on the I2C0 bus to detect the current ambient light intensity; The OLED display screen circuit is used to expand the connection to the OLED display screen based on the SPI bus to provide a visual display of the current number of sensors and environmental parameters; The button and LED expansion circuit is used to expand the connection between buttons and LED light emitting diodes based on a common universal input and output interface, and perform human-computer interaction through button touch.

4. A multi-bus adaptive protocol intelligent Internet of Things gateway system according to claim 3, characterized in that: The expansion board also includes: a serial port expansion circuit and a peripheral expansion circuit; The serial port expansion circuit is used to carry a serial port conversion chip and an interface chip, and transmit and receive serial port data based on a USB interface to achieve level signal conversion; The peripheral expansion circuit is used to expand multiple industrial temperature sensors based on the UART3 bus to detect multiple-point temperatures on industrial sites.

5. A multi-bus adaptive protocol intelligent Internet of Things gateway system according to claim 2, characterized in that: The main control board includes: a protocol detection module, an encryption packaging module, an operation program module, a protocol setting module and a remote display module; The protocol detection module is used to perform self-detection and adaptive protocol configuration of the bus protocol after the system is turned on, and automatically detect the communication protocol of the sensor bus; The encryption and packaging module is used to encrypt the sensor data using a parallel encryption method, and after the encryption is completed, package it into message queue telemetry transmission protocol data and send it to the cloud; The operating program module is used to develop monitoring host computer software based on the application development framework, and read, configure and store sensor data collected in real time; The protocol setting module is used to set the message queue telemetry transmission protocol to realize the transmission between sensor data and remote data; The remote display module is used to establish a communication connection with the mobile terminal program and display the sensor data collected by the sensor device in real time.

6. A multi-bus adaptive protocol intelligent Internet of Things gateway system according to claim 5, characterized in that: The protocol detection module includes: an I2C bus protocol detection unit, an RS485 bus detection unit and a device button drive unit; Wherein, the I2C bus protocol detection unit is used to first perform sensor detection of the I2C bus after the system is turned on, automatically detect the address of the I2C bus protocol, and after the I2C bus detection is completed, prompt to enter the RS485 bus detection unit for detection; The RS485 bus detection unit is used to connect slave devices with device addresses of 1 to 255 in an enumerated manner, and then store the device addresses of successfully tested connections; The device key driving unit is used to program LED driving and key driving, and serves as a function key and indication of the adaptive protocol gateway.

7. A multi-bus adaptive protocol intelligent Internet of Things gateway system according to claim 6, characterized in that: The sensor detection of the I2C bus is first performed, and the address of the I2C bus protocol is automatically detected, including: S11, search for I2C bus devices. If the search is successful, configure the I2C bus device to read mode and go to S12; S12, configure the slave device address to be read to 1, and go to S13; S13, if the device address is greater than 128, go to S16; otherwise, call the function to read the slave device and go to S14; S14, if the data is read successfully, the device address is found successfully, the device address is stored, and the process goes to S15; if the data is read unsuccessfully, the process goes to S15; S15, configure the slave device address to be read plus 1, and go to S13; S16. The program ends and all device addresses are stored.

8. A multi-bus adaptive protocol intelligent Internet of Things gateway system according to claim 6, characterized in that: The method of connecting the slave devices with device addresses of 1 to 255 by enumeration and then storing the device addresses of the successfully connected devices includes: S21, search for RS485 bus device, if the search is successful, configure the RS485 bus device to read mode, and go to S22; S22, configure the slave device address to be read to 1, and go to S23; S23, if the device address is less than 250, go to S26; otherwise try to connect to the slave device and go to S24; S24, if the device is successfully connected, disconnect the slave device, store the device address, and go to S25; if the data reading is unsuccessful, go to S25; S25, configure the slave device address to be read plus 1, and go to S23; S26. The program ends and all device addresses are stored.

9. A multi-bus adaptive protocol intelligent Internet of Things gateway system according to claim 6, characterized in that: The parallel encryption method is used to encrypt the sensor data, and after the encryption is completed, it is packaged into message queue telemetry transmission protocol data and sent to the cloud, including: S31, dividing the sensor data to be encrypted into blocks of 16 bytes; S32, creating a process pool, and assigning the segmented data blocks to various processes for processing, wherein each process in the process pool independently performs encryption tasks; S33, putting the segmented data blocks into the input queue one by one, each process selects a data block from the input queue, encrypts the data block using the SM4 algorithm, and puts the encrypted data block into the output queue; S34, after all data blocks are encrypted, the encrypted data blocks are taken out from the output queue in order, and all data blocks are merged to obtain complete encrypted data; S35. Pack the encrypted data into message queue telemetry transmission protocol data and send it to the cloud server.

10. A multi-bus adaptive protocol intelligent Internet of Things gateway system according to claim 6, characterized in that: The monitoring host computer software includes an automatic address detection function, a sensor data reading function, and a message queue telemetry transmission protocol data sending function.

Citation Information

Cited By

  • Communication system for artificial intelligence education

    CN120602510A

  • Industrial monitoring Qt development platform construction method for LoongArch platform

    CN121918800A

  • LoongArch platform-oriented industrial monitoring Qt development platform construction method

    CN121918800B