Internet of Things equipment access method based on cloud gateway
Through the cloud gateway-based Internet of Things device access method, the problems of data forwarding complexity, security risks and lack of customized functions are solved, cost reduction and diversity requirements are met, and system stability and processing efficiency are improved.
Patent Information
- Application Number
- CN202411308299.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-19
- Publication Date
- 2025-01-07
AI Technical Summary
During the access process of existing IoT devices, data needs to be forwarded through third-party platforms, which increases complexity and security risks. Gateways with JSON data analysis function are expensive and lack customized functions, which cannot meet diversified needs.
Using the cloud gateway-based Internet of Things device access method, configuring and binding device, point and communication protocol information, communicating with third-party cloud gateways through the server or client, converting data formats, and using hexadecimal data to JSON Data conversion and analysis reduces costs and realizes customized functions.
Eliminates the dependence on third-party gateways, reduces implementation costs, improves processing efficiency and system stability, and meets the diverse needs of access to multiple types of equipment.
Smart Images

Figure CN119276933A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Internet of Things device access, and in particular to an Internet of Things device access method based on a cloud gateway. Background Art
[0002] In the process of IoT device access in existing technologies, the platform generally adopts a common model: using the original data conversion JSON service provided by the gateway manufacturer, forwarding the data through a third-party platform, and finally transmitting the data to the IoT platform for storage and analysis. This model meets the basic needs of device access to a certain extent. However, with the rapid development of IoT technology and the diversification of application scenarios, this model has gradually exposed some problems.
[0003] First, data needs to be forwarded through a third-party platform, which not only increases the complexity of data transmission, but also may introduce additional security risks. As a transit station for data transmission, the stability and security of the third-party platform directly affect the normal operation of the entire IoT system. Once the third-party platform fails or is attacked, the entire IoT system may be seriously affected.
[0004] Secondly, the price of gateways with JSON data parsing function is generally high, which undoubtedly increases the cost of IoT devices. For some projects or enterprises with limited budgets, this is undoubtedly a heavy burden. At the same time, the high price also limits the popularity and application scope of such gateways.
[0005] Finally, the lack of customized functions is one of the most prominent problems in the current IoT device access. Different IoT platforms and application scenarios have different requirements for device access, but the gateway solutions of existing technologies can only provide limited functions and are difficult to meet diverse needs. This has led to many IoT projects encountering bottlenecks in the device access link and failing to give full play to the advantages of IoT technology.
[0006] Therefore, it is necessary to provide an IoT device access method based on a cloud gateway, which can solve the problems in the prior art that data needs to be forwarded through a third-party platform when IoT devices are accessed, the gateway with JSON data parsing function is expensive, and lacks customization. Summary of the invention
[0007] The purpose of the present invention is to provide an IoT device access method based on a cloud gateway, which can solve the problems in the prior art that when IoT devices are accessed, data needs to be forwarded through a third-party platform, and the gateway with JSON data parsing function is expensive and lacks customization.
[0008] The present invention is achieved in that:
[0009] A method for accessing an IoT device based on a cloud gateway comprises the following steps:
[0010] Step 1: When the IoT device is connected, configure and bind the IoT device, point and communication protocol information;
[0011] Step 2: Based on the configuration and binding information in step 1, start a server or client on the IoT platform for communicating with the third-party cloud gateway;
[0012] Step 3: The third-party cloud gateway responds to the server or client's data query on the device location, and the server or client converts the response data of the third-party cloud gateway into a format that the IoT platform can understand and use.
[0013] In the step 1, each IoT device corresponds to at least one point.
[0014] The step 1 comprises the following sub-steps:
[0015] Step 1.1: Configure the communication protocol type, IP address, port, and data forwarding URL when the IoT device is connected;
[0016] Step 1.2: Configure the device number and collection frequency of the IoT device, and bind the communication protocol type;
[0017] Step 1.3: Configure the point name, data type, register address, and slave ID of the IoT device.
[0018] Design and develop device management, point management, protocol management, and log viewing pages to meet the configuration, binding, and viewing requirements of IoT devices, points, and communication protocol information. The functional points of these pages include:
[0019] (1) Configure the communication protocol type and control protocol startup for IoT device access on the protocol management page;
[0020] (2) On the device management page, bind the IoT device to the corresponding communication protocol type, and set the CRC check method and collection frequency;
[0021] (3) Add point information to the IoT device on the point management page of the IoT device, including: point name, point type, measurement point type, slave ID, and register address;
[0022] (4) On the log viewing page, you can view all historical data of the corresponding IoT device or its corresponding point at any time.
[0023] In step 2, according to the bound communication protocol type and the configured IP address and port, the server or client receives data from the IoT device and transmits it to the third-party cloud gateway of the IoT platform. At the same time, it can send instructions to the IoT device.
[0024] In step 2, the server or client acts as a hub for data transmission to remotely control and manage the device; according to the configuration of the communication protocol type in step 1, a network component is created for starting, stopping and reloading the server or client;
[0025] When the server or client is a TCP server, create a TCP server network component to set the consumer, server host and port number, and start the TCP server; the functions of the TCP server network component include starting, stopping and reloading the TCP server, and receiving response data from the third-party cloud gateway.
[0026] In step 2, the server or client communicates with the third-party cloud gateway through data polling, and the data polling process is as follows:
[0027] Step 2.1: Create a new thread pool and obtain one or multiple threads at the same time through the thread pool;
[0028] Step 2.2: When starting the server or client service, traverse all points of the device and add a scheduled task for each point.
[0029] In the step 2.2, creating a scheduled task specifically includes: configuring the execution frequency of the scheduled task, regularly putting the device point information that needs to be polled into the message queue, and regularly sending query data messages to the third-party cloud gateway. The message queue is first-in-first-out, and data is sent and queried in order. When the message queue is empty, the thread waits. When a new element is added, the waiting thread is notified to process it.
[0030] The step 3 comprises the following sub-steps:
[0031] Step 3.1: At the device point that needs to be polled, get a new thread from the thread pool and execute the code logic in the new thread;
[0032] Step 3.2: The server or client sends hexadecimal query data to the third-party cloud gateway to query the latest data of the device points that need to be polled;
[0033] Step 3.3: The third-party cloud gateway returns the query result data in hexadecimal format to the server or client;
[0034] Step 3.4: The server or client parses the hexadecimal query result data, and saves the parsed query result data to the MySQL table of the JSON database, or forwards the parsed query result data to the data forwarding URL.
[0035] Compared with the prior art, the present invention has the following beneficial effects:
[0036] 1. The present invention can not only eliminate the dependence of the Internet of Things platform on the third-party gateway platform for device access, but also reduce the cost of implementing the Internet of Things project through the conversion and parsing of hexadecimal data and JSON data, and can also realize more customized functions to meet the diverse needs of multi-type device access.
[0037] 2. The present invention utilizes parallel processing technology and waiting / notification queues to execute multiple tasks simultaneously to improve overall processing efficiency and speed up data processing. When the queue is empty, the thread waits. When a new element is added, the waiting thread is notified to process it, thereby ensuring the robustness, efficiency and stability of the system operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 It is a flow chart of the method for accessing Internet of Things devices based on cloud gateway of the present invention. DETAILED DESCRIPTION
[0039] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments.
[0040] Please see attached Figure 1 , a method for accessing an IoT device based on a cloud gateway, comprising the following steps:
[0041] Step 1: When the IoT device is connected, configure and bind the device, point, and communication protocol information.
[0042] In the step 1, each IoT device corresponds to at least one point. For example, the IoT device thermometer and hygrometer includes two devices, a thermometer and a hygrometer. The two devices correspond to two points, namely, a temperature point and a humidity point.
[0043] The step 1 comprises the following sub-steps:
[0044] Step 1.1: Configure the communication protocol type, IP address, port, and data forwarding URL for IoT device access.
[0045] Step 1.2: Configure the device number, collection frequency, and binding communication protocol type of the IoT device.
[0046] Step 1.3: Configure the point name, data type, register address, slave ID, etc. of the IoT device.
[0047] By configuring and binding IoT devices, communication protocols and points, it is ensured that each point corresponding to each IoT device and the communication protocol it uses can correctly correspond to each other, thereby ensuring the accuracy and integrity of the data. By accurately configuring these key information, a solid communication foundation is established, providing strong guarantees for subsequent data transmission and processing.
[0048] Specifically, we can design and develop pages such as device management, point management, protocol management, and log viewing to meet the configuration, binding, and viewing requirements of IoT devices, points, and communication protocol information. The functional points of these pages can be adaptively developed according to actual application needs, for example:
[0049] (1) On the protocol management page, you can configure the communication protocol type for IoT device access, control protocol start and stop, etc.
[0050] (2) On the device management page, you can bind the corresponding communication protocol type to the IoT device, set the CRC check method and collection frequency, etc.
[0051] (3) On the point management page of the IoT device, you can add point information to the IoT device, including: point name, point type, measurement point type, slave ID, register address, etc.
[0052] (4) On the log viewing page, you can view all historical data of the corresponding IoT device or its corresponding point at any time.
[0053] Step 2: Based on the configuration and binding information in step 1, start a server or client on the IoT platform to communicate with the third-party cloud gateway.
[0054] In step 2, according to the bound communication protocol type and the configured IP address and port, the server or client receives data from the IoT device and transmits it to the third-party cloud gateway of the IoT platform. At the same time, it can send instructions to the IoT device.
[0055] The server or client acts as a hub for data transmission to achieve remote control and management of the device. Based on the configuration of the communication protocol type in step 1, a network component can be created to start, stop, and reload the server or client.
[0056] For example, when the server or client is a TCP server, create a TCP server network component to set the consumer, server host and port number, and start the TCP server. The functions of the TCP server network component include starting, stopping and reloading the TCP server, and receiving the response data from the third-party cloud gateway.
[0057] The creation code is as follows:
[0058]
[0059] In step 2, the server or client communicates with the third-party cloud gateway through data polling, and the data polling process is as follows:
[0060] Step 2.1: Create a new thread pool and obtain one or multiple threads at the same time through the thread pool.
[0061] Step 2.2: When starting the service (communication protocol) of the server or client, traverse all points of the device and add a scheduled task for each point.
[0062] In the step 2.2, creating a scheduled task specifically includes: configuring the execution frequency of the scheduled task, regularly putting the device point information that needs to be polled into the message queue, and regularly sending messages to query data to the third-party cloud gateway. The message queue has the characteristics of first-in-first-out, and can send and query data in an orderly manner, playing the role of a data buffer. When the message queue is empty, the thread waits. When a new element is added, the waiting thread is notified to process it, ensuring the robustness, efficiency and stability of the system operation. The execution code is as follows:
[0063] / / Start a new thread and put the information collected by the device into the message queue regularly
[0064] public void run(){
[0065] try{
[0066] messageQueue.add(deviceConfigEntity);
[0067] }catch(Exception e){
[0068] log.error("[Command sending failed]{}",e.getMessage());
[0069] }
[0070] }
[0071] / / Start scheduled tasks to execute regularly
[0072] DevicePointTask immediate=newDevicePointTask(deviceConfigEntity,sendCommander.getMessageQueue());
[0073] dynamicTask.startCron(taskId,immediate,deviceConfigEntity.getFrequency()*1000);
[0074] Preferably, in the development and design of consumer points, the message queue can use a blocking queue, which can be used to store device polling parameters and play the role of data buffering. The code is as follows:
[0075] LinkedBlockingQueue <devicepointconfigentity>messageQueue;.
[0076] Through multi-threading technology, multiple threads are obtained simultaneously using the thread pool, and multiple scheduled tasks can be executed at the same time to improve the overall processing efficiency and speed up data processing; and data from multiple devices can be processed at the same time to improve the concurrent performance of data transmission.
[0077] By adding scheduled tasks, we can ensure regular data collection and avoid data omissions or delays. By using message queue technology and its first-in-first-out characteristics, we can buffer and queue data and ensure orderly transmission and processing of data.
[0078] Step 3: The third-party cloud gateway responds to the server or client's data query on the device location, and the server or client converts the response data of the third-party cloud gateway into a format that the IoT platform can understand and use.
[0079] The step 3 comprises the following sub-steps:
[0080] Step 3.1: At the device point that needs to be polled, get a new thread from the thread pool and execute the code logic in the new thread.
[0081] Step 3.2: The server or client sends hexadecimal query data to the third-party cloud gateway to query the latest data of the device points that need to be polled.
[0082] Step 3.3: The third-party cloud gateway returns the query result data in hexadecimal format to the server or client.
[0083] Step 3.4: The server or client parses the hexadecimal query result data, and saves the parsed query result data to the MySQL table of the JSON database, or forwards the parsed query result data to the data forwarding URL.
[0084] By using hexadecimal data for communication, accurate data analysis can be achieved, thereby extracting useful information, namely query results, making it easier to store query results in the IoT platform, that is, save them in the MySQL table of the json database, and then realize real-time query and storage of data at device locations, providing strong support for subsequent data analysis and applications.
[0085] For example, in the development and design of consumer points, a new thread is started to obtain the measurement point information data of the corresponding point of the IoT device from the blocking queue in real time, and the hexadecimal request data is encapsulated and sent to the third-party cloud gateway. The code for the third-party cloud gateway's response and the IoT platform's parsing and forwarding to the data forwarding URL is as follows:
[0086]
[0087]
[0088] Among them, the configuration and code of data forwarding to the data forwarding URL are as follows:
[0089] After parsing the response data of the third-party cloud gateway into JSON data, send (post) an http request to the specified URL (configured in the communication protocol type), and the body content is the device JSON data.
[0090]
[0091] The process and code for parsing the response data of the third-party cloud gateway according to the data type in the point configuration and storing it in the MySQL library table when it is stored in the platform are as follows:
[0092] 1. Concatenate the IP address, function code, custom command, starting address, and number of registers of the IoT device to form hexadecimal query data and send it to the third-party cloud gateway.
[0093] 2. After the IoT platform receives the response data from the third-party cloud gateway, it converts it from hexadecimal to JSON format according to the data type in the measurement point configuration.
[0094] According to the different data types in the measurement point configuration, the IoT platform can perform different conversion operations on the response data.
[0095] 3. Store the converted query result data in the MySQL library table corresponding to the platform.
[0096] / / Encapsulate the request message
[0097] StringBuilder body=new StringBuilder();
[0098] / / From site ID: device address
[0099] body.append(DataUtil.decimalToHex(pointConfigEntity.getSlaveId(),1));
[0100] / / Function code
[0101] body.append(pointConfigEntity.getRegisterType());
[0102] / / Send the custom command
[0103] if(Func.isNotBlank(pointConfigEntity.getSelfCommand())){
[0104] body.append(pointConfigEntity.getSelfCommand());
[0105] }else{
[0106] / / The data start address is high first, low last, if not enough, fill with 0
[0107] body.append(String.format("%04x",
[0108] pointConfigEntity.getDataStartAddress()));
[0109] / / The number of data registers is high first, low last, if not enough, add 0
[0110] body.append(String.format("%04x",
[0111] pointConfigEntity.getDataAddressNums()));
[0112] }
[0113] / / Send a message to the gateway
[0114] result=networkManager.send(protocolConfigVO,DataUtil.hexStringToBytes(body.toString()));
[0115] / / Analyze the point data
[0116] int dataByteNums=Integer.parseInt(reultHex.substring(4,6),16);
[0117] / / Use the parseInt method to convert hexadecimal to decimal
[0118] String realHexData=reultHex.substring(6,6+dataByteNums*2).
[0119] The above are only preferred embodiments of the present invention and are not intended to limit the scope of protection of the invention. Therefore, any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.< / devicepointconfigentity>
Claims
1. A method for accessing an IoT device based on a cloud gateway, characterized in that: The following steps are involved: Step 1: When the IoT device is connected, configure and bind the IoT device, point and communication protocol information; Step 2: Based on the configuration and binding information in step 1, start a server or client on the IoT platform for communicating with the third-party cloud gateway; Step 3: The third-party cloud gateway responds to the server or client's data query on the device location, and the server or client converts the response data of the third-party cloud gateway into a format that the IoT platform can understand and use.
2. The method for accessing IoT devices based on a cloud gateway according to claim 1, characterized in that: In the step 1, each IoT device corresponds to at least one point.
3. The method for accessing IoT devices based on a cloud gateway according to claim 1, wherein: The step 1 comprises the following sub-steps: Step 1.1: Configure the communication protocol type, IP address, port, and data forwarding URL when the IoT device is connected; Step 1.2: Configure the device number and collection frequency of the IoT device, and bind the communication protocol type; Step 1.3: Configure the point name, data type, register address, and slave ID of the IoT device.
4. The method for accessing IoT devices based on a cloud gateway according to claim 1, wherein: Design and develop device management, point management, protocol management, and log viewing pages to meet the configuration, binding, and viewing requirements of IoT devices, points, and communication protocol information. The functional points of these pages include: (1) Configure the communication protocol type and control protocol startup for IoT device access on the protocol management page; (2) On the device management page, bind the IoT device to the corresponding communication protocol type, and set the CRC check method and collection frequency; (3) Add point information to the IoT device on the point management page of the IoT device, including: point name, point type, measurement point type, slave ID, and register address; (4) You can view all historical data of the corresponding IoT device or its corresponding point at any time on the log viewing page.
5. The method for accessing IoT devices based on a cloud gateway according to claim 1, characterized in that: In step 2, according to the bound communication protocol type and the configured IP address and port, the server or client receives data from the IoT device and transmits it to the third-party cloud gateway of the IoT platform. At the same time, it can send instructions to the IoT device.
6. The method for accessing IoT devices based on a cloud gateway according to claim 1, characterized in that: In step 2, the server or client acts as a hub for data transmission to remotely control and manage the device; according to the configuration of the communication protocol type in step 1, a network component is created for starting, stopping and reloading the server or client; When the server or client is a TCP server, create a TCP server network component to set the consumer, server host and port number, and start the TCP server; the functions of the TCP server network component include starting, stopping and reloading the TCP server, and receiving response data from the third-party cloud gateway.
7. The method for accessing IoT devices based on a cloud gateway according to claim 1, characterized in that: In step 2, the server or client communicates with the third-party cloud gateway through data polling, and the data polling process is as follows: Step 2.1: Create a new thread pool and obtain one or multiple threads at the same time through the thread pool; Step 2.2: When starting the server or client service, traverse all points of the device and add a scheduled task for each point.
8. The method for accessing IoT devices based on a cloud gateway according to claim 7, wherein: In the step 2.2, creating a scheduled task specifically includes: configuring the execution frequency of the scheduled task, regularly putting the device point information that needs to be polled into the message queue, and regularly sending query data messages to the third-party cloud gateway. The message queue is first-in-first-out, and data is sent and queried in order. When the message queue is empty, the thread waits. When a new element is added, the waiting thread is notified to process it.
9. The method for accessing IoT devices based on a cloud gateway according to claim 1, characterized in that: The step 3 comprises the following sub-steps: Step 3.1: At the device point that needs to be polled, get a new thread from the thread pool and execute the code logic in the new thread; Step 3.2: The server or client sends hexadecimal query data to the third-party cloud gateway to query the latest data of the device points that need to be polled; Step 3.3: The third-party cloud gateway returns the query result data in hexadecimal format to the server or client; Step 3.4: The server or client parses the hexadecimal query result data, and saves the parsed query result data to the MySQL table of the JSON database, or forwards the parsed query result data to the data forwarding URL.