Method for reducing communication delay between Internet of Things equipment and database
By presetting configuration files and database registration listening condition statements in the server background program, only sending notifications and updating data when data changes, the problem of communication delays and resource waste between IoT devices and databases is solved, and low latency and low resources are achieved Consumed communication efficiency.
Patent Information
- Application Number
- CN202411393136.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-08
- Publication Date
- 2025-01-07
AI Technical Summary
The communication delay between IoT devices and databases is high. The existing polling and query mechanism causes data modification to be unable to be promptly feedback. Increasing the polling frequency will waste server resources, making it difficult to take into account both communication rate and resource utilization.
The server background program presets configuration files, registers the database to listen to conditional statements, and only sends change notifications and corresponding data when the data changes. The data update is sent to the IoT device through the preset topic to reduce unnecessary queries and resource consumption.
It reduces the communication delay between IoT devices and databases, effectively reduces the consumption of server resources, and improves the timeliness of data updates and communication efficiency.
Smart Images

Figure CN119276757A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a method for reducing communication delay and belongs to the field of communications. Background Art
[0002] Usually, IoT devices cannot directly connect to the database. They generally use external APIs to query the database, such as using HTTP, TCP or MQTT protocols to send query commands. The server uses SQL statements to periodically poll the data in the database and returns it to the IoT device based on the data results. Because SQL statements are response mechanisms, the database will only return results when it is queried, and no results will be returned if the database is not queried. Therefore, if the data in the database changes when the server does not query the database, the database can only return results when the server queries the next time. Therefore, this type of polling query has a high latency, which makes it easy for the data modifications in the two queries to not be fed back to the IoT device in time; if the problem of communication delay is solved by increasing the polling frequency, server resources will be wasted; therefore, if the query frequency is reduced, the communication delay will be high, and if the query frequency is increased, server resources will be wasted, resulting in the inability to have both communication rate and server resources. Therefore, it is necessary to solve the problem of reducing the communication delay between IoT devices and databases without wasting server resources. Summary of the invention
[0003] The purpose of the present invention is to solve the problem of reducing the communication delay between an Internet of Things device and a database without wasting server resources, and proposes a method for reducing the communication delay between an Internet of Things device and a database.
[0004] A method for reducing communication delay between an IoT device and a database, the method comprising the following contents:
[0005] Step 1: A configuration file is preset in the server background program. The server background program is used to read the internal preset configuration file after power-on. The configuration file includes the IDs of multiple IoT devices, the topic corresponding to each ID, and the conditional statement corresponding to each ID. After reading, the conditional statement is sent to the database, and a registration message is sent to the database. After receiving the conditional statement and the registration message, the database sends a registration success message to the server background program.
[0006] Step 2: When the data in the database is modified, determine whether the modified data meets the conditions in the conditional statement. If yes, send a data change notification to the server background program that registers the statement. If not, prohibit sending data change notifications to the server background program. After receiving the change notification, the server background program sends a request to query the modified data to the database. After receiving the request, the database sends the modified data to the server background program. The server background program finds the topic and ID corresponding to the modified data from the preset configuration file, and sends the modified data to the IoT device with the corresponding ID through the corresponding topic.
[0007] Preferably, the types of IoT devices include: track indicator lights, laser fences and 4G speakers in the warehouse.
[0008] Preferably, the conditional statement is: the state is not 0 or the time is within 1 hour.
[0009] Preferably, the database is a sql database.
[0010] The beneficial effects of the present invention are:
[0011] The server backend sends a registration message to the database. Once the data in the database changes, a notification message will be sent to the server backend. The server backend sends the change message to the IoT device with the corresponding ID through the corresponding topic according to the configuration file. Therefore, this application can reduce resource usage and communication delay.
[0012] When the corresponding changed rows or data are queried, the changed data will be published to the corresponding topic according to the rules preset in the configuration file, which helps to reduce server resource consumption and communication delays. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 A flowchart of a method for reducing communication delay between an IoT device and a database. DETAILED DESCRIPTION
[0014] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0015] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.
[0016] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments, but they are not intended to limit the present invention.
[0017] Specific implementation method 1: Combination Figure 1 This embodiment describes a method for reducing communication delay between an IoT device and a database, and the method includes the following contents:
[0018] Step 1: A configuration file is preset in the server background program. The server background program is used to read the internal preset configuration file after power-on. The configuration file includes the IDs of multiple IoT devices, the topic corresponding to each ID, and the conditional statement corresponding to each ID. After reading, the conditional statement is sent to the database, and a registration message is sent to the database. After receiving the conditional statement and the registration message, the database sends a registration success message to the server background program.
[0019] Step 2: When the data in the database is modified, determine whether the modified data meets the conditions in the conditional statement. If yes, send a data change notification to the server background program that registers the statement. If not, prohibit sending data change notifications to the server background program. After receiving the change notification, the server background program sends a request to query the modified data to the database. After receiving the request, the database sends the modified data to the server background program. The server background program finds the topic and ID corresponding to the modified data from the preset configuration file, and sends the modified data to the IoT device with the corresponding ID through the corresponding topic.
[0020] In this implementation, the information included in the configuration file is as follows:
[0021] IoT Device ID topic Conditional Statements 1001 001 Status is not 0 1002 002 The time is within 1 hour
[0022] When the data in the database changes, that is, when an update statement or an insert statement is entered, the database will be queried, and the database will send the field change data and the location information of the field change data in the database to the server.
[0023] This implementation utilizes the database change notification function to enable an external IoT device to perform low-overhead monitoring of a certain field in the database and automatically notify the IoT device through the MQTT protocol when the field changes.
[0024] The role of this implementation is as follows:
[0025] 1) Registration: Specify the queries that the database should monitor. The database can monitor DML (Data Manipulation Language) events, DDL (Data Definition Language) events, and global events (such as closing the database).
[0026] 2) Notification: Once the data in the database changes, the database will automatically send out a notification, and we need to define event handling operations in our program.
[0027] 3) Response: In our program, once we receive a notification, we generally automatically update the datacache. Of course, we can notify the user that the data has changed and let him decide whether to update it.
[0028] Specific implementation method 2: This implementation method further limits the method of reducing the communication delay between the Internet of Things device and the database described in specific implementation method 1. In this implementation method, the types of Internet of Things devices include: track indicator lights, laser fences and 4G speakers in the warehouse.
[0029] In this embodiment, for example, when the data in the database changes, it is sent to the track indicator light through the corresponding topic and ID, and the track indicator light changes from red to green, thereby changing the state to indicate the vehicle status.
[0030] Specific implementation method three: This implementation method further limits the method for reducing the communication delay between the Internet of Things device and the database described in specific implementation method one. In this implementation method, the conditional statement is: the state is not 0 or the time is within 1 hour.
[0031] Specific implementation method 4: This implementation method further limits the method for reducing the communication delay between the Internet of Things device and the database described in specific implementation method 1. In this implementation method, the database is a SQL database.
[0032] Working principle:
[0033] When a new IoT device wants to associate a field in the database, the IoT device needs to first send the device ID, the topic it subscribes to, and the device request data field name to the server background program through the MQTT broker. The server background program registers according to the conditional statement in the preset configuration file.
[0034] After the device is successfully registered with the database, if the field is modified by other programs, the database will actively push field change notifications to the server background program. By using the binding relationship between the configuration file and the device, the topic subscribed by the IoT device on the MQTT platform can be known, and the message can be assembled according to the predetermined protocol and sent to the topic. At this time, the IoT device can immediately obtain the relevant data and process it.
[0035] In this method, the server backend program and the database are required to be in the same LAN or the same server, because when the database pushes data, the target IP address needs to be accessible.
[0036] Although the present invention is described herein with reference to specific embodiments, it should be understood that these embodiments are merely examples of the principles and applications of the present invention. It should therefore be understood that many modifications may be made to the exemplary embodiments and that other arrangements may be devised without departing from the spirit and scope of the present invention as defined by the appended claims. It should be understood that the various dependent claims and features described herein may be combined in a manner different from that described in the original claims. It should also be understood that features described in conjunction with individual embodiments may be used in other described embodiments.
Claims
1. A method for reducing communication delay between an Internet of Things device and a database, characterized in that: The method includes the following: Step 1: A configuration file is preset in the server background program. The server background program is used to read the internal preset configuration file after power-on. The configuration file includes the IDs of multiple IoT devices, the topic corresponding to each ID, and the conditional statement corresponding to each ID. After reading, the conditional statement is sent to the database, and a registration message is sent to the database. After receiving the conditional statement and the registration message, the database sends a registration success message to the server background program. Step 2: When the data in the database is modified, determine whether the modified data meets the conditions in the conditional statement. If yes, send a data change notification to the server background program that registers the statement. If not, prohibit sending data change notifications to the server background program. After receiving the change notification, the server background program sends a request to query the modified data to the database. After receiving the request, the database sends the modified data to the server background program. The server background program finds the topic and ID corresponding to the modified data from the preset configuration file, and sends the modified data to the IoT device with the corresponding ID through the corresponding topic.
2. A method for reducing communication delay between an IoT device and a database according to claim 1, characterized in that: Types of IoT devices include: track indicator lights, laser fences and 4G speakers in the warehouse.
3. A method for reducing communication delay between an IoT device and a database according to claim 1, characterized in that: The conditional statement is: the status is not 0 or the time is within 1 hour.
4. A method for reducing communication delay between an IoT device and a database according to claim 1, characterized in that: The database is a sql database.