Internet of Things remote control data transmission method and system and storage medium
By synchronously transmitting IoT remote control commands and data files in the MQTT communication environment, the network security and efficiency issues of IoT devices in complex scenarios are solved, and autonomous management and efficient data transmission of edge gateways are realized.
Patent Information
- Application Number
- CN202411009346.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2024-11-12
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing IoT remote control technologies suffer from several problems in scenarios with a large number of nodes, including high network security risks, high communication traffic costs, cumbersome cluster data synchronization, significant delays in device status feedback, and low performance in remote command execution. In particular, complex command strategies and associated data file transfers lead to overall system inefficiency.
In an MQTT communication environment, the client generates a command set and broadcasts JSON data packets. The server parses and stores the commands and data files, enabling synchronous transmission of commands and data files. A timed execution mechanism and a result feedback mechanism are designed to ensure that the edge gateway can manage itself autonomously in the network environment.
It improves the security and reliability of IoT devices, reduces network dependence, enhances system operating efficiency, and ensures the complete transmission and autonomous execution of complex command strategies and data files.
Smart Images

Figure CN118945203A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of road pole combination, and in particular relates to an Internet of Things remote control data transmission method, system and storage medium. Background Art
[0002] With the continuous improvement of the communication infrastructure system, intelligent terminal devices are increasingly used in various intelligent control scenarios, such as smart homes, unmanned factories, smart street lights and other scenarios. At the same time, in order to ensure sufficient Internet security and equipment asset security, smart IoT devices should not be deployed in the Internet environment. Otherwise, it is easy to cause huge losses and public safety hazards due to frequent network attacks and data intrusions in the Internet environment. At the same time, remote control requires the execution of a large number of data synchronization and remote control instructions. In scenarios with a large number of nodes, such as city-level street lights or natural resource monitoring gateways, it is necessary to implement information handshakes and data synchronization verification and sending back and forth between the server and the client multiple times. Specifically, the instructions and the operating parameters corresponding to the instructions are defined and sent separately. Although there is sufficient instruction flexibility, the synchronization of parameters with the corresponding configuration parameter files and code source data will result in the following costs: First, the overall network security risk is high. In order to synchronize data multiple times, the time and risk of service and node devices being exposed to the network environment are significantly increased.
[0003] Second, the node communication traffic overhead is large. The mode in which instructions, parameters and code data source files are listed separately will cause partial transmission omissions and data mismatches during multiple synchronizations, resulting in the need for repeated transmission and multiple handshake confirmations, resulting in significant additional communication overhead.
[0004] Third, cluster data synchronization is cumbersome. New configuration parameters and corresponding operating data are broadcast from the server to each node. Affected by the uncertainty of the transmission network, it requires complex leak detection, proofreading, and re-issuance to accurately configure the source data and parameters to each node gateway command after it runs.
[0005] Fourth, the delay in device status feedback is significant. Node devices scattered in different networks and operating environments have significant and random differences in the delay required to report their own status.
[0006] Fifth, the remote command execution performance is low. Commands and data are separated and transmitted separately, which leads to high requirements for the transmission integrity of command-data versions and sequences. Once a mismatch occurs between different parameter versions, it will lead to unpredictable losses and risks.
[0007] In the current IoT data transmission, the IoT instructions focus on remote control, with the aim of ensuring that the device control instructions are accurately and securely sent to the corresponding IoT device nodes, and there is no need to additionally configure the configuration file related to the instruction. This situation is suitable for a single remote device control and status feedback. For example, patent CN202110735785.7 mainly serves the stable transmission of video files, and does not consider further strategic functions such as how the video stream performs playback. Solutions CN201810173421.2 and CN202110036372.X mainly realize the transmission and execution of a single instruction, focusing on how to reduce latency and improve response to facilitate remote meter reading and street light control.
[0008] When the IoT terminal device needs to implement a relatively complex command strategy and supporting data files, it is necessary to further form a dedicated remote command control strategy solution, which will lead to the many costs mentioned above. This is why the present invention comes about. Summary of the invention
[0009] In view of the above-mentioned technical problems, the purpose of the present invention is to provide an Internet of Things remote control data transmission method, system and storage medium, which can synchronously transmit instructions and supporting strategies and data files, and realize the association between different instruction texts, supporting strategies, data files, and execution result feedback through the unique random sequence number in the instruction table. This solution can realize a more complex instruction execution mechanism for autonomous local preset strategies. After a set of remote control instructions and preset strategies are fully transmitted, the edge gateway can be separated from the cloud platform to realize self-operation management of autonomous preset strategies, which can significantly improve the security and reliability of edge smart gateway devices.
[0010] The technical solution of the present invention is: A method for remotely controlling data transmission of the Internet of Things comprises the following steps: S01: In the MQTT communication environment, the client forms an instruction set according to a preset instruction table, generates a JSON data packet from the instruction set, and broadcasts it in the form of MQTT broadcast; S02: After the server monitors the MQTT broadcast, it decomposes the JSON data packet in real time. If it is a command sent to the local gateway device, it parses the command parameter table and stores it in the local device command database; if it is a data file, it parses the data variable table and stores the file data in the local device database; S03: Query the unexecuted instructions in the local device instruction database, call the corresponding instructions to complete the remote control of the corresponding device; if it is a data file, obtain the file matching usage policy and store it in the instruction data table, and store the file stream according to the policy information.
[0011] In the preferred technical solution, the MQTT communication environment includes at least one MQTT communication server and an edge gateway, the edge gateway is connected to at least one functional terminal, and the MQTT communication server, edge gateway and functional terminal all establish server and client data transmission methods.
[0012] In the preferred technical solution, the instruction table preset in step S01 is: Fields type meaning id int Record number SN varchar Instruction 22-bit random sequence number Topic varchar Project Name client_name varchar The name of the client issuing the command client_id varchar The ID of the client issuing the command DevID varchar Local device ID DevName varchar Local device name QoS int Command message level InstructContent varchar Instruction text SourceInstructorID varchar The device ID that issues the command InstructorID varchar The name of the device issuing the command InstructorName varchar Command name HardWareName varchar To control the hardware device Value varchar Hardware Execution Value Enable int Has it been executed? datatime timestamp Timestamp of issuing command SendOrNot int Is this information sent? message varchar Instruction Attachment Information
[0013] In the preferred technical solution, the method in step S01 in which the client forms an instruction set according to a preset instruction table includes: S11: correspond to the elements defined in the instruction table one by one; S12: When it is necessary to send a command to the remote device, construct the command according to the command parameter table: command name, client, target device sequence, target device parameters; S13: If there is file data that needs to be sent, generate a data variable table: fixed-length file, target client, file attached parameter sequence; fill in the data body: data file full name, project subject, client ID, key, device ID, device name, data file sending timestamp, file attached message, file sending source ID, receiving device ID, and complete the assembly of the file data stream.
[0014] In the preferred technical solution, after the server monitors the MQTT broadcast in step S02, the following steps are further included: The received topic is judged. If it matches the preset broadcast topic, the parsed JSON data stream is segmented and assigned fields according to the element definition in the instruction table. Read the value of the InstructorName field. If it is equal to 0, it means that this MQTT message is a transmission data file; otherwise, it is a remote control instruction. Read the target device ID of the message to see if it is equal to the local gateway device ID. If the values are the same, it is information that should be checked. Otherwise, it is not data sent to the local gateway device, and the message is discarded and returns to the listening link again, waiting to receive the next MQTT message for the next round of processing.
[0015] In the preferred technical solution, step S02 further includes: If the type of information received is a command, parse the command text: serial number, project subject, client ID, key, device ID, device name, command issuance timestamp, command attached message, command source ID, target device ID, target device command parameter value, and store it in the local device command database; If it is a data file, the data body is parsed: the full name of the data file, project subject, client ID, key, device ID, device name, data file issuance timestamp, file attachment message, file issuance source ID, receiving device ID, and the file data information is stored in the local device database.
[0016] In the preferred technical solution, step S03 further includes: A timing loop mechanism for executing instructions is formed on the server side, and unexecuted records in the local device instruction database are regularly queried at preset intervals. For unexecuted records, if the preset execution time has expired, the corresponding instruction type name in the InstructorName field is called according to the preset parameters to complete the remote control of the corresponding device; If the execution of the instruction requires supporting files and strategies, the message value is parsed to read the corresponding file and executed according to the strategy. After the execution is completed, the execution result is associated with the 22-bit random serial number, and the new device parameters after the execution of the instruction are queried and the results are stored in the instruction execution result table, and marked as not yet released. The execution result information is sent to the instruction source device to complete the feedback notification of the remote control result.
[0017] In the preferred technical solution, step S03 further includes: A polling mechanism is formed on the target terminal to regularly query the instruction execution result table. When an execution result that has not been sent back is found, the execution result is sent back to the source terminal in the form of MQTT broadcast, the field information is queried and assembled into a JSON format data packet, which is serialized and converted into a string message stream and sent in the form of MQTT broadcast; After the source terminal receives the broadcast, it completes data parsing in an asynchronous manner. The instruction table sent by the source terminal and the instruction execution result table received are associated with the data table foreign key using the SN field. When the source terminal generates a new instruction record, a unique SN number is generated synchronously. After sending it to the remote target terminal, the SN number remains unchanged and is written into the instruction execution result table, which is then sent back to the source terminal by the remote target terminal. This realizes the closed loop of sending and receiving instruction records and instruction execution result records.
[0018] The present invention also discloses an Internet of Things remote control data transmission system, comprising: Client instruction generation and broadcast module. In the MQTT communication environment, the client forms an instruction set according to the preset instruction table, packages the instruction set into a JSON data packet, and broadcasts it in the form of MQTT broadcast; The server-side parsing and receiving module, after listening to the MQTT broadcast, decomposes the JSON data packet in real time. If it is a command sent to the local gateway device, the command parameter table is parsed and stored in the local device command database; if it is a data file, the data variable table is parsed and the file data is stored in the local device database; The instruction execution module queries the unexecuted instructions in the local device instruction database and calls the corresponding instructions to complete the remote control of the corresponding device; if it is a data file, the file matching usage policy is obtained and stored in the instruction data table, and the file stream is stored according to the policy information.
[0019] The present invention further discloses a computer storage medium on which a computer program is stored. When the computer program is executed, the above-mentioned Internet of Things remote control data transmission method is implemented.
[0020] Compared with the prior art, the present invention has the following beneficial effects: 1. Constructed a set of instruction and file data mechanism: constructed the instruction and file data content consisting of two sets of data tables, and realized the judgment mechanism of transmitting instructions, files and instruction results between IoT devices with Topic as the keyword. At the same time, in the two sets of data tables, the attribute registration and mutual verification mechanism between the instruction and file information source devices and the target devices are defined respectively.
[0021] 2. Designed a set of command sending methods: On the source terminal and the target terminal, run the client and server logic at the same time to realize the device command sending and receiving mechanism in the MQTT IoT environment. The server listens to the messages of the specified topic in the MQTT network, and the client sends the messages of the predetermined topic in the MQTT network at the same time, realizing the timely communication mechanism between different device points.
[0022] 3. Implemented a set of policy files and supporting data transmission methods: The source terminal packages the files and supporting data (such as preset policies) that need to be transmitted to the smart terminal into a serialized string information stream. Specifically, the full name of the file, file ownership, file policy and file body are first packaged into a JSON data packet according to the preset splicing rules, and finally accompanied by additional information such as the receiving terminal and supporting instruction name, and then serialized into a string sequence, which is sent in the client logic in the form of MQTT broadcast. The server logic is used at the target terminal to listen and check the information, and the reverse process is used to parse and restore it to the original file and policy data.
[0023] 4. A method for checking and storing instructions is designed: the source terminal first edits the instructions for remotely controlling the target terminal into a database record. Then the source terminal client queries the instruction record that has not been sent to the target terminal, and assembles the fields into a JSON data packet. It is then converted into a serialized string stream and broadcast in the MQTT network environment in the form of an MQTT message. After the server logic of the target terminal listens to the message, it first determines whether it is information that should be checked by this terminal. If so, the server method of the target terminal will reverse parse the information, first convert the message body into a string sequence, and then convert the sequence into a JSON data packet, and then restore the instruction record to an instruction record of the source terminal.
[0024] 5. A mechanism for scheduled execution based on instruction table query and predetermined strategy is designed; the server logic of the remote terminal has a built-in loop method for regularly polling instruction records, which regularly queries the unexecuted instruction records in the instruction table at preset intervals (the Enable field value is 0). When one or more unexecuted instruction records are found, the instruction name and instruction scheduled strategy information in the instruction record are read to complete the execution of the scheduled instruction. At the same time, the remote terminal writes the result (return value) of the instruction execution into the local instruction execution result data table, and marks the instruction execution result as unpublished (SendOrNot field, write 0 for not sent, 1 for sent).
[0025] 6. A feedback mechanism that can regularly feedback remote execution results is designed; the internal client algorithm of the remote terminal has a built-in polling mechanism for regularly querying the instruction execution result table. When it is found that there is an execution result that has not been sent back, the execution result is sent back to the source client in the form of MQTT broadcast. Specifically, the information of each field is queried first, and assembled into a JSON format data packet, and then serialized and converted into a string message stream, and finally submitted to the MQTT broadcast module of the client algorithm in an asynchronous manner. After hearing the broadcast information, the server algorithm of the source terminal completes the data parsing in the reverse order of the above process in an asynchronous manner. At the source terminal, the sent instruction record table and the received instruction execution result record are associated with the data table foreign key by the SN field. That is, when the source terminal generates a new instruction record, a system-unique SN serial number is generated synchronously. After sending to the remote target terminal, the SN number remains unchanged and is written into the instruction execution result table. Then it is sent back to the source terminal by the remote target terminal. In this way, the closed loop of sending and receiving instruction records and instruction execution result records is realized.
[0026] 7. Implemented an edge gateway autonomous management mechanism that can independently execute preset strategies without network communication for a short period of time. Since the main elements (instructions, thresholds, strategies and supporting data files) for smart terminals to implement specific functions can be sent to accurate terminals in a timely manner during periods when the network environment is unobstructed in the form of MQTT broadcasts. This enables the client algorithms and server algorithms in each terminal to form a relatively complete set of internal mechanisms for self-sustaining operation. When the network environment is interrupted, it can operate stably and self-stable according to the preset operating logic and data mechanism without interference. This mechanism has significant practical significance in the city-level IoT environment scenario. It can effectively prevent node function abnormalities caused by unstable network communications, and at the same time effectively improve the operating efficiency of the overall system. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The present invention will be further described below in conjunction with the accompanying drawings and embodiments: Figure 1 This is a flow chart of the Internet of Things remote control data transmission method of the present invention; Figure 2 The service end of the present invention specifically performs a flow chart; Figure 3 The client of the present invention specifically executes the flow chart; Figure 4 This is a flow chart of instruction execution of terminals A and B of the present invention. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention is further described in detail below in conjunction with specific embodiments and with reference to the accompanying drawings. It should be understood that these descriptions are only exemplary and are not intended to limit the scope of the present invention. In addition, in the following description, the description of well-known structures and technologies is omitted to avoid unnecessary confusion of the concept of the present invention.
[0029] Principle description: This solution can synchronously transmit instructions, supporting strategies and data files, and realize the association between different instruction texts, supporting strategies, data files, and execution result feedback through each 22-bit unique random serial number in the instruction record table. Compared with the existing solutions, this solution design can realize a more complex instruction execution mechanism for autonomous local preset strategies. After a complete transmission of a set of remote control instructions and preset strategies, the edge gateway can be separated from the cloud platform to realize self-operation management of autonomous preset strategies. In contrast, the existing solutions mainly focus on the single function of the device and fail to realize the application of instructions for complex preset strategies and supporting data files. Once the timely intervention of the network cloud platform is separated, the function of the remote device will fail and the business operation data will be lost. In addition, this solution forms a more secure private data format based on the MQTT network environment, which can significantly improve the security and reliability of edge intelligent gateway devices. This solution divides the remote control mechanism into two sets of mechanisms, the client and the server, so as to realize the complete closed loop of sending remote instructions-remote device reception-remote device autonomous execution-result feedback.
[0030] Terminology explanation: MQTT: Message Queuing Telemetry Transport (MQTT) is a message protocol based on the publish / subscribe paradigm under the ISO standard (ISO / IEC PRF 20922). It works on the TCP / IP protocol family and is a publish / subscribe message protocol designed for remote devices with low hardware performance and poor network conditions. For this purpose, it requires a message middleware. MQTT is a client-server based message publish / subscribe transmission protocol that is lightweight, simple, open and easy to implement.
[0031] IoT devices or functional terminals: Physical devices connected through the Internet that can collect, exchange and process data to achieve intelligent management and control. They are widely used in smart homes, industrial automation, smart cities and other fields. For example, smart door locks, LED electronic billboards, sensors in industrial automation, and smart street lights in smart cities.
[0032] Remote control category: Remote control of intelligent IoT devices is the process of remotely managing and operating devices through network technology and communication protocols. It includes: remote monitoring and diagnosis, real-time monitoring of device status through sensor data, such as remote inspection of the operating status of factory equipment; remote setting and adjustment, remote configuration and adjustment of device parameters, such as adjusting process parameters between different production batches; remote maintenance and update, remote execution of equipment maintenance operations and software updates to ensure continuous and efficient operation of equipment.
[0033] like Figure 1 As shown, a method for remote control data transmission of the Internet of Things includes the following steps: S01: In the MQTT communication environment, the client forms an instruction set according to the preset instruction table, packages the instruction set into a JSON data packet, and broadcasts it in the form of MQTT broadcast; S02: After the server monitors the MQTT broadcast, it decomposes the JSON data packet in real time. If it is a command sent to the local gateway device, it parses the command parameter table and stores it in the local device command database; if it is a data file, it parses the data variable table and stores the file data in the local device database; S03: Query the unexecuted instructions in the local device instruction database, call the corresponding instructions to complete the remote control of the corresponding device; if it is a data file, obtain the file matching usage policy and store it in the instruction data table, and store the file stream according to the policy information.
[0034] This solution will realize a command data method that integrates remote online control commands, preset strategies, and application data files in the IoT environment. At the same time, it can also allow the edge gateway to self-sustain according to the preset strategy in the case of occasional network disconnection, until the network environment is restored and the latest status of the device can be uploaded to the cloud platform in time. Specifically, a set of command data composite data organization mechanisms that can be applied in the three-level control environment of "cloud platform-edge gateway-functional terminal" are designed: 1. The network environment between the cloud platform and the edge gateway is an IoT link, such as using the MQTT protocol to increase the network's dedicated properties and data security.
[0035] 2. Set up instructions, policies and data receiving mechanisms in the edge gateway, and establish corresponding storage data tables.
[0036] 3. The edge gateway is designed with a self-inspection mechanism. After receiving and storing the command, it can parse and execute the command according to the preset strategy. After execution, the result is transmitted back to the cloud platform in the form of MQTT broadcast.
[0037] 4. The cloud platform transmits application data, and can synchronously transmit file names and file-attached usage information, such as permissions, corresponding instructions, parsing methods, validity periods, etc.
[0038] For MQTT messages, there are three qualities of service (QoS) to ensure the reliability of messages in different network environments. Specifically: QoS 0: The message is delivered at most once. If the current client is unavailable, it will lose the message.
[0039] QoS 1: Messages are delivered at least once.
[0040] QoS 2: Messages are delivered only once.
[0041] The instruction table created is defined as follows: Fields type meaning id int Record number SN varchar Instruction 22-bit random sequence number Topic varchar Project Name client_name varchar The name of the client issuing the command client_id varchar The ID of the client issuing the command DevID varchar Local device ID DevName varchar Local device name QoS int Command message level InstructContent varchar Instruction text SourceInstructorID varchar The device ID that issues the command InstructorID varchar The name of the device issuing the command InstructorName varchar Command name HardWareName varchar To control the hardware device Value varchar Hardware Execution Value Enable int Has it been executed? datatime timestamp Timestamp of issuing command SendOrNot int Is this information sent? message varchar Instruction Attachment Information The instruction execution result table is defined as follows: Fields type meaning id int Record number SN varchar Execution result 22-digit random serial number Topic varchar Project Name client_name varchar The name of the client issuing the command client_id varchar The ID of the client issuing the command QoS int Local device ID DevID varchar Local device name DevName varchar Command message level InstructOrderResult varchar Instruction execution results SourceInstructorID varchar The device ID that issues the command InstructorID varchar The name of the device issuing the command InstructorName varchar Command name HardWareName varchar To control the hardware device Value varchar Hardware Execution Value Enable int Has it been executed? datatime timestamp Timestamp of issuing command SendOrNot int Is this information sent? message varchar Execution result information In this solution, the cloud platform is responsible for interacting with users and specifically recording business needs, including execution timing strategies, intended controlled devices, and authorized devices. The edge gateway is responsible for the execution of specific instructions and the implementation of specific controls on different functional terminals, such as circuit breaker control, street light switches, screen video playback, and audio broadcasting. At this time, in the command data system of the trinity of control instructions, preset strategies, and application data files, this solution establishes a server and a client on the cloud platform and the edge gateway at the same time to realize the transmission of instructions and data and the feedback and delivery of execution information. The server and the client belong to the definition of MQTT communication roles and run in the IoT client at the same time to realize MQTT network communication between different functional terminals and between functional terminals and the cloud platform.
[0042] The MQTT communication environment includes an MQTT communication server and several terminals in the MQTT network environment. For example, in an IoT MQTT communication environment, the broadcast address (such as "31035da069.wicp.vip"), broadcast port (such as 17905), client ID, MQTT service login username and MQTT service login password, and several custom communication topics are configured (such as heartbeat packets, data transmission and instruction parameters can be used as broadcast topics). When the broadcast address is enabled for broadcasting and the username and password are configured, the client can use these parameters to dial in to the MQTT communication server. In the MQTT communication server, the agreed topic (Topic) can be used to send broadcasts and listen to broadcast information sent by other clients.
[0043] Based on the above mechanism, this solution designs both server and client logic on the terminal to realize the sending and monitoring of information broadcast by the predetermined subject (Topic). Using MQTT broadcast, two sets of operation logic mechanisms are established for the server and client. All terminals, in the specified MQTT dedicated IoT communication network environment, publish or monitor broadcasts of different contents in the form of Topic fields (project names or subject names) in the data table. The server is responsible for monitoring broadcasts published by other clients in the MQTT network with the same Topic. When the information is received, it is immediately compared with the local preset Topic in the first stage. If it matches, it means that DevID and DevName can be further checked to see if they are the information that the local device should receive. Otherwise, the record is discarded.
[0044] For the client, when the MQTT IoT terminal needs to send data or instructions to other devices in the MQTT network (such as reporting data or remotely controlling a device), it packages the instruction content and accompanying data according to the fields defined in the instruction table.
[0045] For example, id is the serial number of this instruction data, which is convenient for subsequent queries.
[0046] SN is a 22-bit random serial number, which is convenient for subsequent association of instruction execution results. The client logic will query the execution result and tell the IoT terminal hardware that initiated the instruction the result of this instruction. The server copies the SN value recorded in the instruction to the SN in the instruction execution result after the execution result, realizing a complete closed-loop of the instruction and the execution result, and facilitating subsequent queries.
[0047] The field of Topic is the MQTT topic name, that is, the project name, to achieve the reuse of the same MQTT service for different projects.
[0048] client_name and client_id are the client device name and device serial number that issued this instruction record respectively. DevName and DevID are the target client device name and device serial number that received and executed this instruction respectively. QOS is the level of this MQTT message.
[0049] The specific execution process of the server (server algorithm) is as Figure 2 shown, including: 1. Establish a connection. Start the connection for MQTT device communication. The specific connection parameters include: EMQTT server address: mqtt_broker = "31035da069.wicp.vip"; EMQTT server port: mqtt_port = 17905; EMQTT client ID: client_id = "mqttx_WJ Jinri Xincheng"; EMQTT client name: client_name = "mqttx_Name_WJ Jinri Xincheng"; EMQTT username: username = "WJ003"; EMQTT password: password = "weizhang1211"; EMQTT subscription information topic: mqtt_topic = "Attitude Sensor", and the symbol "+" subscribes to all topics at the same level.
[0050] 2. Start MQTT listening. When the IoT edge gateway running the server code successfully establishes communication with the cloud platform, it will get a return value of a successful connection, and will synchronously start an MQTT network service listening in the link parameter network environment. At this time, two-way MQTT communication with other edge gateways under the same network conditions can be achieved. When other edge gateways send the element format definition information in the instruction table, the server program needs to convert the binary data stream into a string array in JSON data format. If the received data stream does not conform to the instruction table element format definition, the server algorithm will discard it.
[0051] 3. Convert JSON. The server algorithm will further segment and assign values to the parsed JSON data stream. The specific format corresponds to the order of the elements defined in the instruction table. At the same time, the value of the field InstructorName is read. If it is equal to 0 (string value FileTransport), it means that this MQTT message is a data file transmission. Otherwise, if its field value is other strings (such as SetGPUFanSpeed), it means it is a remote control instruction.
[0052] 4. Reading authority. Read the message to check whether the device ID is equal to the local gateway device ID. If the values are the same, it is a message that should be checked. Otherwise, it is not data sent to the local gateway device, and the message is discarded and returned to the listening link again, waiting for the next MQTT message to be received for the next round of processing.
[0053] 5. Check the data. Further decompose the JSON data in real time. If it is a command sent to the local gateway device, parse the command parameter table: command name, client, target device sequence, target device parameters. Store it in the local device command database. If it is a data file, parse the data variable table: file name, target client, file attached parameter sequence. The configuration parameters are stored in the local device database.
[0054] 6. Generate the text. If the type of information received is a command, parse the command text: serial number, project subject, client ID, key, device ID, device name, command issuance timestamp, command attached message, command source ID, target device ID, target device command parameter value. Store it in the local device command database. If it is a data file, parse the data text: data file full name (including extension), project subject, client ID, key, device ID, device name, data file issuance timestamp, file attached message, file issuance source ID, receiving device ID. The file data information is stored in the local device database. At this point, the interpretation of the received MQTT information stream is completed, and the corresponding record is stored in the data table. In addition, if the record is a command, the Enable field means whether the record has been executed. The value 0 means it has not been executed yet, and the value 1 means it has been executed.
[0055] 7. Execute instructions. A timing loop mechanism for executing instructions is formed on the server side to query the records that have not been executed, that is, the records with Enable value equal to 0, which have been stored in the instruction table. For information that has not been executed, if the preset execution time has expired, call the corresponding instruction type name in the InstructorName field, such as SetGPUFanSpeed, and call the corresponding instruction to complete the remote control of the corresponding device according to the preset parameters, such as HardWareName and Value. If the execution of the instruction requires supporting files and policies, parse the message value to read the corresponding file, such as playing the corresponding audio and video file at the scheduled time and frequency. After the execution is completed, the execution result is associated with the 22-bit random serial number, and the new device parameters after the execution of the instruction are queried, such as the latest status information of the HardWareName and Value fields, and the result is stored in the instruction execution result table and marked as not yet released, that is, the value of the field SendOrNot is assigned to 0. Wait for the local client algorithm to send the execution result information to the instruction source device to complete the feedback notification of the remote control result.
[0056] 8. Store data. If the information is stored as a data file, first cut off the usage policy of the file within the specified length, such as the full name of the data file (including the extension), project subject, client ID and other fields, and store them in the instruction data table. At the same time, for the remaining length of the file stream, start data stream splicing until the file stream ends, and store the file stream in the predetermined folder according to the full name of the file (including the extension) in the policy information.
[0057] 9. Generate a log. The above execution process is generated in the form of text and stored in a log file on the local edge gateway. In the process of checking information, parsing data, judging categories, judging whether to check, parsing data, parsing text, instruction execution and file storage, execution results and file processing results, the execution results of each step above (whether the execution is successful or the program fails) are written into a file (naming rule timestamp.nlog) in the format of [timestamp]+[INFO]+[program module]+[execution action]+[action content].
[0058] The specific execution process of the client (client algorithm) is as follows Figure 3 As shown, including: 1. Establish a link. Start the MQTT device communication link. The specific link parameters include: 1.EMQTT server address: mqtt_broker = "31035da069.wicp.vip"; 2. EMQTT server port: mqtt_port = 17905; 3. EMQTT Client ID: client_id = "mqttx_WJ New City Today"; 4. EMQTT Client Name: client_name = "mqttx_Name_WJ New City Today"; 5. EMQTT Username: username = "WJ003"; 6. EMQTT Password: password = "weizhang1211"; 7. EMQTT Subscription Information Topic: mqtt_topic = "Attitude Sensor", and the symbol '+' subscribes to all topics at the same level.
[0059] (2) Start the MQTT Timed Heartbeat. Regularly broadcast a heartbeat information packet carrying the edge gateway status in the above MQTT network environment. The significance of the heartbeat packet is to broadcast the latest status of the local edge gateway to other devices on the network, and at the same time inform other devices and the cloud platform monitoring mechanism of the last online time of the local gateway. When other devices have not received updated heartbeat information after a time T, it can be judged that the device is offline. Specifically, it includes the following key information: Fields type meaning id int Record number SN varchar 22-digit random code Topic varchar Project Name client_name varchar Client Name client_id varchar Client ID QoS int Command message level DevID varchar Local device ID DevName varchar Local device name DevCPURunStatus varchar Device CPU usage DevStatus varchar Device memory usage datatime timestamp Timestamp SendOrNot int Whether to send (0 not sent, 1 sent) message varchar Heartbeat packet attached information (3) Data Packing. When a control instruction needs to be sent to a remote device, the client algorithm sends an MQTT broadcast message in the format defined in the instruction table. The specific format corresponds one by one in the order defined by the elements in the instruction table. If the value of the field InstructorName is equal to 0 (string value FileTransport), it means that this MQTT message is for transmitting a data file. Otherwise, if its field value is other strings (such as SetGPUFanSpeed), then this message is a remote control instruction.
[0060] (4) Enable Broadcasting. According to the value of InstructorName, enable the corresponding Topic broadcasts. 0 is for data transmission broadcasts, and other values are for instruction topic broadcasts.
[0061] (5) Information Level. Assign the QoS of this MQTT message, with values of 0, 1, 2. To distinguish messages of different importance levels and ensure timely delivery to the specified device as needed.
[0062] (6) Construct Instructions. When an instruction needs to be sent to a remote device, it is necessary to construct according to the instruction parameter table: instruction name, client, target device sequence, target device parameters. Instruction Parameter Table: instruction name, client, target device sequence, target device parameters. Complete the assembly of the instruction data to prepare for subsequent information broadcasts.
[0063] (VII) Data body. Generate a data variable table: fixed-length file, target client, file attached parameter sequence. Fill in the data body: data file full name, project subject, client ID, key, device ID, device name, data file sending timestamp, file attached message, file sending source ID, receiving device ID. Complete the assembly of file data streams to prepare for subsequent information broadcasting.
[0064] (VIII) Send broadcast. For the information that has been assembled, the command is converted into a JSON data stream and then into a binary data stream. The data file is converted into a binary data stream. On this basis, the MQTT information broadcast is implemented to wait for other devices in the MQTT network segment to check.
[0065] (IX) Log generation. The above execution process is generated in the form of text and stored in a log file on the local edge gateway. In the process of sending information, packaging data, instruction text and file logs, the execution results of each of the above steps (whether the execution is successful or the program fails) are written into the file (naming rule timestamp.nlog) in the format of [timestamp]+[INFO]+[program module]+[execution action]+[action content], and the execution results of each of the above steps (whether the execution is successful or the program fails) are written into the file (naming rule timestamp.nlog).
[0066] Feedback mechanism for periodic feedback of remote execution results; the internal client algorithm of the remote terminal has a built-in polling mechanism for periodically querying the instruction execution result table. When it is found that there is an execution result that has not been sent back, the execution result is sent back to the source client in the form of MQTT broadcast. Specifically, the information of each field is queried first, and assembled into a JSON format data packet, and then serialized and converted into a string message stream, and finally submitted to the MQTT broadcast module of the client algorithm in an asynchronous manner. After hearing the broadcast information, the server algorithm of the source terminal completes the data parsing in the reverse order of the above process in an asynchronous manner. At the source terminal, the sent instruction record table and the received instruction execution result record are associated with the data table foreign key with the SN field. That is, when the source terminal generates a new instruction record, a system-unique SN serial number is generated synchronously. After sending to the remote target terminal, the SN number remains unchanged and is written into the instruction execution result table. Then it is sent back to the source terminal by the remote target terminal. In this way, the closed loop of sending and receiving instruction records and instruction execution result records is realized.
[0067] The edge gateway autonomous management mechanism can be separated from network communication for a short period of time to autonomously execute preset strategies. Since the main elements (instructions, thresholds, strategies and supporting data files) for smart terminals to implement specific functions can be sent to accurate terminals in a timely manner during periods when the network environment is unobstructed in the form of MQTT broadcasts. This enables the client algorithms and server algorithms in each terminal to form a relatively complete set of internal mechanisms for self-sustaining operation. When the network environment is interrupted, it can operate stably and self-stable according to the preset operating logic and data mechanism without interference. This mechanism has significant practical significance in the city-level IoT environment scenario, which can effectively prevent node function abnormalities caused by unstable network communications, and at the same time effectively improve the operating efficiency of the overall system.
[0068] The following is an example to illustrate: This solution deploys both server and client mechanisms in the terminal hardware devices in MQTT. The server is responsible for monitoring whether there is command information sent to the terminal hardware device in the MQTT network. The client is responsible for broadcasting remote control commands to other terminal hardware devices in this MQTT communication network.
[0069] For example, when terminal A needs to send a message to terminal B to control the fan speed installed in terminal B, adjust it from V1 to V2. The specific example process is as follows Figure 4 As shown, including the following: Instructions and parameters are initiated. Terminal A generates an instruction record. The SN number is converted to a 22-bit random number after adding a four-digit random number according to the year-month-day hour-minute-second timestamp. Topic is assigned the value of "test project" + "instruction". The client_name value is A_client_name, and the client_id value is A_client_id. DevID and DevName values are information about the target terminal hardware device B, such as DevID value is B_client_id, DevName value is B_client_name. Qos is the priority level of this information in MQTT communication (values range from 0 to 2). The field InstructContent is assigned a value, including various instruction parameters, preset strategies, thresholds, time control, etc., which are packaged and parsed in the form of JSON data packets. The SourceInstructorID field records the device ID that issued the instruction. For example, if the temperature controller installed under hardware terminal A needs to trigger the fan installed on hardware terminal B, then SourceInstructorID is the ID of the temperature controller under terminal A. InstructorID is the device name of the temperature controller. These two fields are used in combination to distinguish smart devices of the same model with different IDs installed under the same terminal. The meaning of the InstructorName field is to record the interface name of the control instruction to be issued, such as SetFanValue (set fan speed). This value requires the development of an interface caller with the corresponding name in advance to facilitate the accurate call of the instruction execution module. The Value value is the fan with the ID number SourceInstructorID and the device name InstructorID corresponding to the B hardware terminal, which is the new speed value to be adjusted. The meaning of Enable is whether this instruction has been executed. The value 0 means it has not been executed yet, and the value 1 means it has been executed. Datatime is the timestamp generated by this instruction, and the value is "year, month, day, hour, minute, second, millisecond", to facilitate the subsequent verification and calculation of the execution results and delays of the instruction record. The SendOrNot field is used to determine whether the MQTT information broadcast has sent this record. Message is the auxiliary information recorded by this instruction, which can provide more execution input parameters for complex instructions. Correspondingly, the file data required by this instruction (such as the video file to be played on the LED screen) is also the matching file parameters (file name, corresponding execution interface, file usage policy, etc.) written into the message field.
[0070] Instruction and data broadcast. After the above instruction set record is formed, each field is packaged into a JSON data packet according to the following format: var data = new { SN = sn, Topic = Topic, client_name = client_name, client_id = client_id, QoS = QoS, DevID = DevID, DevName = DevName, InstructOrderResult = InstructOrderResult, SourceInstructorID = InstructorID, InstructorID = SourceInstructorID, InstructorName = InstructorName, HardWareName = HardWareName, Value = Value, Enable = 1, message = message, CurrentTimeString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; The above JSON data is serialized and converted into a string using the following instance method: stringjsonData = JsonConvert.SerializeObject(data); 3. Command execution and file data usage. After the serialization string of the command data is completed, the hardware terminal A will broadcast it in the MQTT network environment in the format of PublishAsync(jsonData) using the Topic topic, which means that all other hardware terminal servers that have also enabled the Topic topic communication mode can check it.
[0071] When terminal B receives the broadcast message, it will listen to the jsonData string data in an asynchronous form. The listening sample format at this time is mqttClient_ApplicationMessageReceivedAsync. Since MQTT communication automatically attaches the terminal ID, topic, Qos and information body Payload when checking. Terminal B will judge the received topic. If it meets the preset broadcast topic equal to "test project + instruction", it means that it is an instruction information to adjust the fan speed. If the broadcast topic is "test project + data file", the information flow is file data, and the corresponding message field needs to be parsed to obtain the corresponding supporting file parameters (file name, corresponding execution interface, file usage policy, etc.). At this time, it is further judged whether the target gateway clientId sent by this message is equal to the clientId of the current gateway. If it is consistent, it means that it belongs to the instruction data that the network manager B should check and execute. At this time, the instructions are checked and written into the instruction data table of gateway B. The specific data parsing is performed according to the reverse process of step 1.
[0072] 4. Data preservation. If the message is "test project + data file", the corresponding file parameters (file name, corresponding execution interface, file usage policy, etc.) in the message field need to be parsed. Based on this, in the Payload module of the message, the first N bytes are intercepted (the fixed-length information is the file directory and verification information), and the remaining N+1 bytes until the end of the message stream are converted into the file body, and saved in the directory specified by terminal B according to the parsed file name, so as to facilitate the subsequent instruction call.
[0073] 5. Instruction execution. On the server side running on terminal B, a regular polling module for the instruction table is set. When the instruction data sent by other terminals (such as terminal A) is found in the instruction table and has not been executed (the Enable field value 0 means it has not been executed, and the value 1 means it has been executed), the terminal B server immediately calls the control instruction interface according to the record of the InstructorName field in the record, such as SetFanValue (set fan speed). The parameters required for this instruction (such as the new fan speed value) are parsed from the Value, InstructContent, HardWareName and message fields. For example, if the speed of fan No. 001 under terminal B needs to be set to 50% when the ambient temperature exceeds 35 degrees in July every year. At this time, terminal B executes according to the parsed instruction interface name and supporting execution parameters within this polling cycle, and the execution results are written into the instruction execution result table. The relevant field definitions are consistent with the instruction table definitions in the first step. At this time, it should be noted that terminal A is the initiator of this fan adjustment instruction, so the instruction source ID and device name need to be written into the corresponding instruction execution result table. The Enable of the original instruction table record is changed from 0 to 1, indicating that the instruction record has been executed. The SendOrNot field value is 0, indicating that the execution result has not yet been fed back to terminal A.
[0074] 6. Send back the result. After the execution of the periodic polling instruction module on the server, the result is written into the instruction execution result table. After that, the client module of gateway B starts the return of the execution result, and the data is packaged into JSON mode, refer to the data definition in step 1. The client algorithm of terminal B will query all the records in the instruction execution result table where the SendOrNot field is 0, and broadcast them one by one to the original instruction initiating terminal A in the form of MQTT broadcast. At this time, the client publishing method refers to 1.
[0075] 7. Check the command execution results. When the A terminal listens to the broadcast topic "test project + result feedback" in the MQTT network environment, it further analyzes whether the client ID and client name that received the message are the local machine. If the judgment is passed, it means that the MQTT broadcast is information that the local machine (A terminal) needs to check. At this time, further analyze the record and store it in the A terminal command execution result table. Refer to step 1 for the definition of the parsing method, and write SN into the message field of the A terminal command execution result table to associate the original remote control command issued by the A terminal, so as to realize the complete closed loop of command issuance and result checking.
[0076] In another embodiment, an Internet of Things remote control data transmission system includes: Client instruction generation and broadcast module. In the MQTT communication environment, the client forms an instruction set according to the preset instruction table, packages the instruction set into a JSON data packet, and broadcasts it in the form of MQTT broadcast; The server-side parsing and receiving module, after listening to the MQTT broadcast, decomposes the JSON data packet in real time. If it is a command sent to the local gateway device, the command parameter table is parsed and stored in the local device command database; if it is a data file, the data variable table is parsed and the file data is stored in the local device database; The instruction execution module queries the unexecuted instructions in the local device instruction database and calls the corresponding instructions to complete the remote control of the corresponding device; if it is a data file, the file matching usage policy is obtained and stored in the instruction data table, and the file stream is stored according to the policy information.
[0077] The specific implementation of each module is the same as the above IoT remote control data transmission method, which will not be repeated here.
[0078] In yet another embodiment, a computer storage medium stores a computer program, which implements the above-mentioned Internet of Things remote control data transmission method when executed.
[0079] The above IoT remote control data transmission method is adopted and will not be described in detail here.
[0080] It should be understood that the above specific embodiments of the present invention are only used to illustrate or explain the principles of the present invention, and do not constitute a limitation of the present invention. Therefore, any modifications, equivalent substitutions, improvements, etc. made without departing from the spirit and scope of the present invention should be included in the protection scope of the present invention. In addition, the appended claims of the present invention are intended to cover all changes and modifications that fall within the scope and boundaries of the appended claims, or the equivalent forms of such scope and boundaries.
Claims
1. A method for remote control data transmission in the Internet of Things, It is characterized in that The following steps are involved: S01: In the MQTT communication environment, the client forms an instruction set according to a preset instruction table, generates a JSON data packet from the instruction set, and broadcasts it in the form of MQTT broadcast; S02: After the server monitors the MQTT broadcast, it decomposes the JSON data packet in real time. If it is a command sent to the local gateway device, it parses the command parameter table and stores it in the local device command database; if it is a data file, it parses the data variable table and stores the file data in the local device database; S03: querying the unexecuted instructions in the local device instruction database, and calling the corresponding instructions to complete the remote control of the corresponding device; If it is a data file, obtain the usage policy of the file and store it in the instruction data table, and store the file stream according to the policy information.
2. The Internet of Things remote control data transmission method according to claim 1, It is characterized in that The MQTT communication environment includes at least one MQTT communication server and an edge gateway, the edge gateway is connected to at least one functional terminal, and the MQTT communication server, edge gateway and functional terminal all establish a server-side and client-side data transmission method.
3. The Internet of Things remote control data transmission method according to claim 1, It is characterized in that The instruction table preset in step S01 is: 。 4. The Internet of Things remote control data transmission method according to claim 1, It is characterized in that The method in step S01 in which the client forms an instruction set according to a preset instruction table includes: S11: correspond to the elements defined in the instruction table one by one; S12: When it is necessary to send a command to the remote device, construct the command according to the command parameter table: command name, client, target device sequence, target device parameters; S13: If there is file data that needs to be sent, generate a data variable table: fixed-length file, target client, file attached parameter sequence; fill in the data body: data file full name, project subject, client ID, key, device ID, device name, data file sending timestamp, file attached message, file sending source ID, receiving device ID, and complete the assembly of the file data stream.
5. The Internet of Things remote control data transmission method according to claim 3, It is characterized in that After the server monitors the MQTT broadcast in step S02, the following steps are also performed: The received topic is judged. If it matches the preset broadcast topic, the parsed JSON data stream is segmented and assigned fields according to the element definition in the instruction table. Read the value of the InstructorName field. If it is equal to 0, it means that this MQTT message is a transmission data file; otherwise, it is a remote control instruction. Read the target device ID of the message to see if it is equal to the local gateway device ID. If the values are the same, it is information that should be checked. Otherwise, it is not data sent to the local gateway device, and the message is discarded and returns to the listening link again, waiting to receive the next MQTT message for the next round of processing.
6. The Internet of Things remote control data transmission method according to claim 1, It is characterized in that Step S02 also includes: If the type of information received is a command, parse the command text: serial number, project subject, client ID, key, device ID, device name, command issuance timestamp, command attached message, command source ID, target device ID, target device command parameter value, and store it in the local device command database; If it is a data file, the data body is parsed: the full name of the data file, project subject, client ID, key, device ID, device name, data file issuance timestamp, file attachment message, file issuance source ID, receiving device ID, and the file data information is stored in the local device database.
7. The Internet of Things remote control data transmission method according to claim 3, It is characterized in that Step S03 also includes: A timing loop mechanism for executing instructions is formed on the server side, and unexecuted records in the local device instruction database are regularly queried at preset intervals. For unexecuted records, if the preset execution time has expired, the corresponding instruction type name in the InstructorName field is called according to the preset parameters to complete the remote control of the corresponding device; If the execution of the instruction requires supporting files and strategies, the message value is parsed to read the corresponding file and executed according to the strategy. After the execution is completed, the execution result is associated with the 22-bit random serial number, and the new device parameters after the execution of the instruction are queried and the results are stored in the instruction execution result table, and marked as not yet released. The execution result information is sent to the instruction source device to complete the feedback notification of the remote control result.
8. The method for remote control data transmission of the Internet of Things according to claim 7, It is characterized in that Step S03 also includes: A polling mechanism is formed on the target terminal to regularly query the instruction execution result table. When an execution result that has not been sent back is found, the execution result is sent back to the source terminal in the form of MQTT broadcast, the field information is queried and assembled into a JSON format data packet, which is serialized and converted into a string message stream and sent in the form of MQTT broadcast; After the source terminal receives the broadcast, it completes data parsing in an asynchronous manner. The instruction table sent by the source terminal and the instruction execution result table received are associated with the data table foreign key using the SN field. When the source terminal generates a new instruction record, a unique SN number is generated synchronously. After sending it to the remote target terminal, the SN number remains unchanged and is written into the instruction execution result table, which is then sent back to the source terminal by the remote target terminal. This realizes the closed loop of sending and receiving instruction records and instruction execution result records.
9. An Internet of Things remote control data transmission system, It is characterized in that include: Client instruction generation and broadcast module: In the MQTT communication environment, the client forms an instruction set according to the preset instruction table, generates a JSON data packet from the instruction set, and broadcasts it in the form of MQTT broadcast; The server-side parsing and receiving module, after listening to the MQTT broadcast, decomposes the JSON data packet in real time. If it is a command sent to the local gateway device, the command parameter table is parsed and stored in the local device command database; if it is a data file, the data variable table is parsed and the file data is stored in the local device database; The instruction execution module queries the unexecuted instructions in the local device instruction database and calls the corresponding instructions to complete the remote control of the corresponding device; if it is a data file, the file matching usage policy is obtained and stored in the instruction data table, and the file stream is stored according to the policy information.
10. A computer storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed, the Internet of Things remote control data transmission method according to any one of claims 1 to 8 is implemented.
Citation Information
Cited By
Remote control method and device, electronic equipment and storage medium
CN121056489A
