Message transmission method and device, computer device and storage medium

By connecting the message transmission device to the requesting end and the message broker via web sockets, the problem of requiring user terminals to install MQTT clients is solved, and device compatibility and synchronous listening to response messages are achieved.

CN117527773BActive Publication Date: 2026-05-29SF TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SF TECH CO LTD
Filing Date
2022-07-27
Publication Date
2026-05-29

Smart Images

  • Figure CN117527773B_ABST
    Figure CN117527773B_ABST
Patent Text Reader

Abstract

The application discloses a message transmission method and device, computer equipment and a storage medium. The message transmission method comprises the following steps: receiving a message transmission request of a request end for a target device, determining whether the target device is online based on the message transmission request, establishing a web socket connection with the request end when the target device is online; receiving a device instruction sent by the request end, and sending the device instruction to a message agent; setting a state of an execution thread to a blocked state before a first response message is received, releasing the blocked state of the execution thread when the first response message is received, and sending the first response message to the request end according to the web socket connection. In the application, when the target device is connected and a topic associated with the target device is subscribed, manual maintenance of related information is avoided, the error of manual operation is reduced, the request end does not need to additionally install an MQTT client, the device compatibility is good, and the synchronous listening of the response message can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of Internet of Things (IoT) technology, specifically to a message transmission method, apparatus, computer device, and storage medium. Background Technology

[0002] With the development of IoT technology, user terminals can remotely control devices by sending device commands, attribute settings, and other device messages. Current technologies typically use tools such as MQTT X and MQTT.fx to send these device messages from the user terminal to the device, and then these tools return the response messages from the device after executing the device messages to the user terminal. This method requires the user terminal to have an additional MQTT client installed, resulting in poor device compatibility and a high risk of operational errors. Summary of the Invention

[0003] This application provides a message transmission method, apparatus, computer device, and storage medium. When connecting devices and subscribing to related topics, it can avoid manually maintaining relevant information, reduce human error, and eliminate the need for the requesting end to install an additional MQTT client, resulting in good device compatibility.

[0004] On one hand, this application provides a message transmission method applied to a message transmission device, wherein the message transmission device is communicatively connected to a requesting end and a message broker, and the message broker is communicatively connected to a target device. The message transmission method includes:

[0005] The receiving end receives a message transmission request for the target device and obtains the device status information of the target device based on the message transmission request.

[0006] Based on the device status information, determine whether the target device is online. When the target device is online, establish a web socket connection with the requesting end.

[0007] The system receives a device instruction sent by the requesting end, creates an execution thread corresponding to the device instruction, and sends the device instruction to the message broker. The device instruction includes an attribute query instruction and / or a device control instruction. The execution thread is used to send the device instruction to the message broker and send a first response message to the requesting end. The first response message is a response message returned by the target device based on the device instruction.

[0008] Before receiving the first response message, the execution thread is set to a blocked state, and it is monitored whether the first response message sent by the message broker is received;

[0009] Upon receiving the first response message, the execution thread is unblocked, and the first response message is sent to the requesting end according to the web socket connection.

[0010] In some embodiments of this application, obtaining the device status information of the target device based on the message transmission request includes:

[0011] According to the message transmission request, a status acquisition request is sent to the message broker, and the status acquisition request includes the device identifier of the target device;

[0012] The message broker receives the device status information returned by the status acquisition request.

[0013] In some embodiments of this application, receiving the device instruction sent by the requesting end and sending the device instruction to the message broker includes:

[0014] Receive the device instruction sent by the requesting end, and create a callback function based on the device instruction;

[0015] The device instruction is sent to the message broker via the callback function.

[0016] In some embodiments of this application, after monitoring whether the first response message sent by the message broker is received, the method includes:

[0017] If the first response message is not received after a preset waiting time, first display information is generated;

[0018] The first display information is sent to the requesting client for display.

[0019] After receiving the first response message, the method further includes:

[0020] Based on the first response message, generate the second display information;

[0021] The second display information is sent to the requesting end for display.

[0022] In some embodiments of this application, setting the state of the execution thread to a blocked state includes:

[0023] A synchronization queue is generated based on the device instructions to set the state of the execution thread to a blocked state. The synchronization queue is used to block the execution thread. When the synchronization queue is empty, the execution thread is in a blocked state. When the synchronization queue is not empty, the blocking state of the execution thread is released.

[0024] The process of releasing the blocked state of the thread corresponding to the device instruction includes:

[0025] The first response message is forwarded to the synchronization queue to unblock the execution thread.

[0026] In some embodiments of this application, sending the first response message to the requesting end based on the web socket connection includes:

[0027] Encapsulate the first response message;

[0028] The encapsulated first response message is sent to the requesting end via the execution thread according to the web socket connection.

[0029] In some embodiments of this application, after sending the device instruction to the message broker, the method further includes:

[0030] Receive the second response message returned by the message broker based on the device instruction;

[0031] Based on the second response message, generate the third display information;

[0032] The third display information is sent to the requesting end for display.

[0033] On the other hand, this application provides a message transmission device, which is communicatively connected to a message broker and a requesting end, respectively. The message broker is communicatively connected to a target device. The message transmission device includes:

[0034] A request receiving unit is used to receive a message transmission request from a requesting end for a target device, and to obtain device status information of the target device based on the message transmission request.

[0035] A connection establishment unit is used to determine whether the target device is online based on the device status information, and when the target device is online, to establish a web socket connection with the requesting end.

[0036] The first sending unit is configured to receive a device instruction sent by the requesting end, create an execution thread corresponding to the device instruction, and send the device instruction to the message broker. The device instruction includes an attribute query instruction and / or a device control instruction. The execution thread is configured to send the device instruction to the message broker and send a first response message to the requesting end. The first response message is a response message returned by the target device based on the device instruction.

[0037] The message listening unit is used to set the state of the execution thread to a blocked state before receiving the first response message, and to monitor whether the first response message sent by the message broker is received.

[0038] The second sending unit is used to, upon receiving the first response message, release the blocking state of the execution thread and send the first response message to the requesting end according to the web socket connection.

[0039] In some embodiments of this application, the request receiving unit is specifically used for:

[0040] According to the message transmission request, a status acquisition request is sent to the message broker, and the status acquisition request includes the device identifier of the target device;

[0041] The message broker receives the device status information returned by the status acquisition request.

[0042] In some embodiments of this application, the first sending unit is specifically used for:

[0043] Receive the device instruction sent by the requesting end, and create a callback function based on the device instruction;

[0044] The device instruction is sent to the message broker via the callback function.

[0045] In some embodiments of this application, the message listening unit is specifically used for:

[0046] A synchronization queue is generated based on the device instructions to set the execution thread to a blocked state. The synchronization queue is used to block the execution thread. When the synchronization queue is empty, the execution thread is in a blocked state. When the synchronization queue is not empty, the blocking state of the execution thread is released.

[0047] In some embodiments of this application, the second transmitting unit is specifically used for:

[0048] The first response message is forwarded to the synchronization queue to unblock the execution thread.

[0049] In some embodiments of this application, the second sending unit is further configured to:

[0050] Encapsulate the first response message;

[0051] The encapsulated first response message is sent to the requesting end via the execution thread according to the web socket connection.

[0052] In some embodiments of this application, the message transmission device further includes:

[0053] An information generation unit is used to generate first display information when the first response message is not received after a preset waiting time.

[0054] The third sending unit is used to send the first display information to the requesting end for display.

[0055] In some embodiments of this application, the message transmission device further includes:

[0056] A message receiving unit is used to receive a second response message returned by the message broker based on the device instruction.

[0057] In some embodiments of this application, the information generation unit is further configured to:

[0058] Based on the first response message, generate the second display information;

[0059] Based on the second response message, third display information is generated.

[0060] In some embodiments of this application, the third sending unit is further configured to:

[0061] The second display information is sent to the requesting end for display.

[0062] The third display information is sent to the requesting end for display.

[0063] On the other hand, this application also provides a computer device, the computer device comprising:

[0064] One or more processors;

[0065] Memory; and

[0066] One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the message transmission method described in any one of the first aspects.

[0067] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, the computer program being loaded by a processor to perform the steps of the message transmission method described in any of the first aspects.

[0068] This application uses a message transmission device to forward device instructions to the target device through a message broker. The requesting end only needs to send a message transmission request and device instructions to the message transmission device to achieve device instruction issuance. No additional MQTT client needs to be installed. Since the requesting end and the message transmission device communicate based on a web socket connection, the requesting end does not need to subscribe to topics to send and receive data, avoiding manual maintenance of relevant information and reducing human error. The execution thread is set to a blocked state and the blocked state of the execution thread is released after receiving the first response message, which can realize synchronous listening to the first response message. Attached Figure Description

[0069] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0070] Figure 1 This is a schematic diagram of a message transmission system provided in an embodiment of this application;

[0071] Figure 2 This is a schematic flowchart of an embodiment of the message transmission method provided in this application.

[0072] Figure 3 This is a schematic flowchart of a specific embodiment of the message transmission method provided in this application.

[0073] Figure 4 This is a schematic diagram of an embodiment of the message transmission device provided in this application.

[0074] Figure 5 This is a schematic diagram of an embodiment of the computer device provided in this application. Detailed Implementation

[0075] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0076] In the description of this application, it should be understood that the terms "center," "longitudinal," "lateral," "length," "width," "thickness," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," and "outer," etc., indicating orientation or positional relationships based on the orientation or positional relationships shown in the accompanying drawings, are used only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this application. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, features defined with "first" and "second" may explicitly or implicitly include one or more of the stated features. In the description of this application, "a plurality of" means two or more, unless otherwise explicitly specified.

[0077] In this application, the term "exemplary" is used to mean "used as an example, illustration, or description." Any embodiment described as "exemplary" in this application is not necessarily to be construed as being more preferred or advantageous than other embodiments. The following description is provided to enable any person skilled in the art to make and use this application. Details are set forth in the following description for purposes of explanation. It should be understood that those skilled in the art will recognize that this application can be made without using these specific details. In other instances, well-known structures and processes are not described in detail to avoid obscuring the description of this application with unnecessary detail. Therefore, this application is not intended to be limited to the embodiments shown, but is consistent with the broadest scope of the principles and features disclosed in this application.

[0078] It should be noted that since the method in this application embodiment is executed in a computer device, the processing objects of each computer device exist in the form of data or information, such as time, which is essentially time information. It is understood that if size, quantity, position, etc. are mentioned in subsequent embodiments, they are all corresponding data that exist so that the computer device can process them. Specific details will not be elaborated here.

[0079] This application provides a message transmission method, apparatus, computer device, and storage medium, which will be described in detail below.

[0080] Please see Figure 1 , Figure 1 This is a schematic diagram of a message transmission system provided in an embodiment of this application. The message transmission system may include a computer device 100, which integrates a message transmission unit. The message transmission unit is communicatively connected to a message broker, such as... Figure 1 Computer equipment in the country.

[0081] In this embodiment, the computer device 100 is mainly used to receive message transmission requests from the requesting end for a target device, obtain device status information of the target device based on the message transmission requests, determine whether the target device is online based on the device status information, and establish a web socket connection with the requesting end when the target device is online; receive device instructions sent by the requesting end, create an execution thread corresponding to the device instructions, and send the device instructions to a message broker. The device instructions include attribute query instructions and / or device control instructions. The execution thread is used to send the device instructions to the message broker and send a first response message to the requesting end. The first response message is a response message returned by the target device based on the device instructions. Before receiving the first response message, the execution thread is set to a blocked state, and the system monitors whether the first response message sent by the message broker is received. When the first response message is received, the execution thread is unblocked, and the first response message is sent to the requesting end according to the web socket connection. In this embodiment, the computer device 100 forwards the device instruction to the target device through a message broker. The requesting end only needs to send a message transmission request and the device instruction to the computer device 100 to realize the device instruction issuance. There is no need to install an additional MQTT client. Since the requesting end and the computer device 100 communicate based on a web socket connection, the requesting end does not need to subscribe to topics to send and receive data, avoiding manual maintenance of relevant information and reducing human error. The execution thread is set to a blocked state, and the blocked state of the execution thread is released after receiving the first response message, which can realize synchronous listening to the first response message.

[0082] In this embodiment, the computer device 100 can be a standalone server, a server network, or a server cluster. For example, the computer device 100 described in this embodiment includes, but is not limited to, a computer, a network host, a single network server, a set of multiple network servers, or a cloud server composed of multiple servers. The cloud server is composed of a large number of computers or network servers based on cloud computing.

[0083] It is understood that the computer device 100 used in the embodiments of this application can be a device that includes both receiving and transmitting hardware, that is, a device having receiving and transmitting hardware capable of performing bidirectional communication on a bidirectional communication link. Such a device may include: cellular or other communication devices having a single-line display, a multi-line display, or a cellular or other communication device without a multi-line display. Specifically, the computer device 100 may be a desktop terminal or a mobile terminal, and may also be one of a mobile phone, tablet computer, laptop computer, etc.

[0084] Those skilled in the art will understand that Figure 1The application environment shown is merely one application scenario of the solution in this application and does not constitute a limitation on the application scenario of the solution in this application. Other application environments may include those that are more specific to this application. Figure 1 The number of computer devices shown is more or less, for example Figure 1 Only one computer device is shown in the document. It is understood that the message transmission system may also include one or more other services, which are not limited here.

[0085] In addition, such as Figure 1 As shown, the message transmission system may also include a memory 200 for storing data, such as request information, such as message transmission requests, status acquisition requests, etc., and device instructions, such as instructions to query the device attributes of the target device, instructions to control the target device to set attributes, instructions to control the target device to adjust device parameters, etc.

[0086] It should be noted that, Figure 1 The schematic diagram of the message transmission system shown is merely an example. The message transmission system and scenario described in this application are intended to more clearly illustrate the technical solutions of this application and do not constitute a limitation on the technical solutions provided in this application. As those skilled in the art will know, with the evolution of message transmission systems and the emergence of new business scenarios, the technical solutions provided in this application are also applicable to similar technical problems.

[0087] First, this application provides a message transmission method. The execution subject of this message transmission method is a message transmission device, which is communicatively connected to a requesting end and a message broker, respectively. The message broker is communicatively connected to a target device. The message transmission device is applied to a computer device. The message transmission method includes: receiving a message transmission request from a requesting end for a target device; obtaining device status information of the target device based on the message transmission request; determining whether the target device is online based on the device status information; and establishing a web socket connection with the requesting end when the target device is online; receiving a device instruction sent by the requesting end; creating an execution thread corresponding to the device instruction; and sending the device instruction to the message broker. The device instruction includes an attribute query instruction and / or a device control instruction. The execution thread is used to send the device instruction to the message broker and send a first response message to the requesting end. The first response message is a response message returned by the target device based on the device instruction; before receiving the first response message, setting the state of the execution thread to a blocked state and monitoring whether the first response message sent by the message broker is received; and when the first response message is received, releasing the blocked state of the execution thread and sending the first response message to the requesting end according to the web socket connection.

[0088] like Figure 2The diagram shown is a flowchart of an embodiment of the message transmission method in this application. The message transmission method may include the following steps 301 to 305, as detailed below:

[0089] 301. The receiving end receives a message transmission request for the target device and obtains the device status information of the target device based on the message transmission request.

[0090] The requesting end is the request initiating end, which is the user-side terminal, including but not limited to smartphones, tablets, smartwatches, smart bracelets, PDAs (Personal Digital Assistants), etc. Users can use the requesting end to set attributes or issue commands to the target device. The target device is the device whose attributes need to be set or whose commands need to be issued by the user. For example, if a user issues commands to an air conditioner through a smartphone, the smartphone is the requesting end, and the air conditioner is the target device. A message transmission request is a message transmission instruction sent by the user to the message transmission device through the requesting end. The message transmission request includes the device identifier of the target device, which is a unique identifier used to uniquely identify the target device. The message transmission device can determine the device whose attributes need to be set or whose commands need to be issued by the user based on the device identifier in the message transmission request. This message transmission request includes, but is not limited to, touch commands, mouse commands, remote control commands, voice commands, etc. For example, clicking the "Message Transmission" icon on the requesting end through a mouse or direct touch operation, or issuing a voice command for "Message Transmission".

[0091] To address the issue that existing methods using tools like MQTT X and MQTT.fx to send device commands to target devices require users to switch between multiple pages to view the command delivery status, a new approach is needed. When sending a message transmission request to the message transmission device from the requesting end, users can first open the device's browser page and then send a message transmission request for the target device through the browser. This allows the message transmission device to send information related to the device command delivery status to the requesting end's browser page for display in subsequent steps, avoiding the need to switch pages repeatedly when viewing the command delivery status.

[0092] Device status information is used to characterize the online status of the target device. The message transmission device can determine whether the target device is online based on the device status information. Considering that the target device needs to be online when the user wants to set attributes or issue commands, after receiving a message transmission request for the target device from the requesting end, the message transmission device obtains the device status information of the target device based on the message transmission request, so as to execute subsequent message transmission steps based on the device status information.

[0093] In one specific implementation, such as Figure 3 As shown, the step 301 of obtaining the device status information of the target device based on the message transmission request may include the following steps 401-402, as detailed below:

[0094] 401. Based on the message transmission request, send a status acquisition request to the message broker, wherein the status acquisition request includes the device identifier of the target device;

[0095] 402. Receive the device status information returned by the message broker based on the status acquisition request.

[0096] A status retrieval request is a status retrieval instruction sent by the message transmission device to the message broker to retrieve the device status of a target device. The status retrieval request includes the device identifier of the target device; therefore, the message broker can determine the target device whose device status needs to be retrieved based on the status retrieval request. After receiving the message transmission request for the target device from the requesting end, the message transmission device sends a status retrieval request to the message broker based on the device identifier in the message transmission request. Upon receiving the status retrieval request, the message broker retrieves the device status information of the target device and pushes the device status information to the message transmission device.

[0097] 302. Determine whether the target device is online based on the device status information. When the target device is online, establish a web socket connection with the requesting end.

[0098] WebSocket is a protocol for full-duplex communication over a single TCP connection. WebSocket connections allow the requesting end and the message transmission device to establish a persistent connection with only a single handshake, enabling bidirectional data transmission. To allow the message transmission device to proactively push data to the requesting end, in this embodiment, after obtaining the target device's device status information, the message transmission device determines whether the target device is online based on this information. When the target device is determined to be online, a WebSocket connection is established with the requesting end.

[0099] 303. Receive the device instruction sent by the requesting end, create an execution thread corresponding to the device instruction, and send the device instruction to the message broker. The device instruction includes an attribute query instruction and / or a device control instruction. The execution thread is used to send the device instruction to the message broker and send a first response message to the requesting end. The first response message is a response message returned by the target device based on the device instruction.

[0100] The message broker receives messages published by all publishers, filters and distributes them to the corresponding subscribers. Message brokers include, but are not limited to, Mosquitto and Emqtted (EMQ). Device commands are attribute query commands sent by the requesting end to the target device via the message transmission device to query the target device's attributes and / or device control commands to control the target device. The execution thread is a task execution thread created by the message transmission device to send device commands to the message broker and to the requesting end the first response message returned by the target device based on the device commands. The first response message is the execution result of the target device after executing the device command. For example, when the device command is an attribute query command, the first response message is the attribute query result of the target device; when the device command is a device control command, the first response message is the control result of the target device.

[0101] When a user needs to send a device command to a target device, they can input the command on the requesting end. The requesting end then sends the command to the message transmission device by calling its command delivery interface. Upon receiving the command, the message transmission device creates an execution thread corresponding to the command and sends it to the message broker, which then forwards the command to the target device. Users can input device commands on the requesting end in various ways, including but not limited to text input, voice input, and point-based input. For example, to adjust the air conditioner temperature, a user can directly input "increase the temperature by 2℃" on the requesting end, or issue a voice command to "increase the temperature by 2℃," or directly click the corresponding temperature-increasing button on the requesting end.

[0102] In one specific implementation, refer to Figure 3 As shown, step 303, which involves receiving the device instruction sent by the requesting end and sending the device instruction to the message broker, may include the following steps 403-404, as detailed below:

[0103] 403. Receive the device instruction sent by the requesting end, and create a callback function according to the device instruction;

[0104] 404. The device instruction is sent to the message broker through the callback function.

[0105] A callback function is used to send device commands to the message broker. After receiving a device command from the requesting end, the message transmission device creates a callback function and defines the content to be sent, i.e., the device command, within it. Then, the execution thread calls this callback function to send the device command to the message broker. In one specific embodiment, the callback function is an `onSend` function. After creating the `onSend` function, the message transmission device defines the device command within it and then calls the `onSend` function through the execution thread to send the device command to the message broker.

[0106] 304. Before receiving the first response message, set the execution thread to a blocked state and monitor whether the first response message sent by the message broker is received.

[0107] Setting an execution thread to a blocked state means pausing the execution thread that is currently executing a task. After setting an execution thread to a blocked state, the execution thread cannot continue to execute the task. Only after the execution thread is unblocked can it continue to execute the task. For example, after setting an execution thread to a blocked state, the message transmission device cannot send the first response message returned by the target device based on the device instruction to the requesting end through the execution thread.

[0108] After receiving a message published by a publisher, the message broker sends the message to subscribers who have subscribed to that topic, based on the corresponding topic. For the message transmission device to receive the first response message, it needs to subscribe to the topic corresponding to the first response message from the message broker. After sending the device message to the message broker, the message transmission device sets its execution thread to a blocked state and monitors whether it has received the first response message from the message broker before receiving it.

[0109] The blocking state of the execution thread requires a triggering condition. In this embodiment, the synchronization queue being empty is used as the triggering condition for the blocking state of the execution thread. When the message transmission device blocks the execution thread, it specifically generates a synchronization queue according to the device instruction. Since the message transmission device has not yet received the first response message, the synchronization queue is empty, which satisfies the triggering condition for the blocking state of the execution thread, and the execution thread is set to the blocking state.

[0110] 305. Upon receiving the response message, the blocking state of the execution thread is released, and the first response message is sent to the requesting end according to the web socket connection.

[0111] In one specific implementation, when the first response message returned by the target device based on the device instruction sent by the message broker is received, the blocking state of the execution thread is released, and the first response message is sent to the requesting end through the execution thread according to the WebSocket connection. This embodiment monitors whether the first response message has been received based on a blocking mechanism. After the message transmission device receives the response message, the blocking state of the execution thread is released, which can realize synchronous listening of the first response message. After receiving the first response message, it can be sent to the requesting end in a timely manner. Moreover, since the execution thread is in a blocked state, there is no need to allocate processor resources to the execution thread, which can reduce the power consumption of the message transmission device.

[0112] In one specific implementation, refer to Figure 3 As shown, step 305, which involves releasing the blocked state of the execution thread, may include step 405, as detailed below:

[0113] 405. Forward the first response message to the synchronization queue to release the blocking state of the execution thread.

[0114] The aforementioned steps mentioned that the blocking state of the execution thread is triggered by an empty synchronization queue. When the message transmission device does not receive the first response message, the blocking queue is empty, and the execution thread will remain blocked. When the message transmission device receives the first response message, in order to send the first response message to the requesting end, the synchronization queue needs to be made non-empty to release the execution thread from its blocking state. In this embodiment, to release the execution thread from its blocking state, after receiving the first response message, the first response message is forwarded to the synchronization queue. At this time, the synchronization queue is not empty, and the triggering condition for the execution thread's blocking state is not met, meaning the execution thread's blocking state is released.

[0115] In one specific implementation, refer to Figure 3 As shown, sending the first response message to the requesting end in step 305 may include the following steps 406-407, as detailed below:

[0116] 406. Encapsulate the first response message;

[0117] 407. Based on the web socket connection, the encapsulated first response message is sent to the requesting end through the execution thread.

[0118] When the message transmission device sends the first response message to the requesting end, it first encapsulates the first response message, and then sends the encapsulated first response message to the requesting end through the execution thread according to the web socket connection. In one specific embodiment, after receiving the device message sent by the requesting end, the message transmission device also creates an onComplete callback function. When sending the first response message to the requesting end, it first encapsulates the first response message into an MqttCountDownInfo, then defines the encapsulated first response message in the onComplete callback function, and finally sends the encapsulated first response message to the requesting end by calling the onComplete callback function through the execution thread.

[0119] In one specific implementation, refer to Figure 3 As shown, after monitoring whether the first response message sent by the message broker is received in step 304, the following steps 306-307 may be included, as follows:

[0120] 306. If the first response message is not received after a preset waiting time, generate the first display information;

[0121] 307. Send the first display information to the requesting end for display.

[0122] The waiting time is a pre-set threshold used to measure whether the message transmission device has timed out of receiving the first response message. The first display information is used to characterize whether the message transmission device has timed out of receiving the first response message. The display methods of the first display information include, but are not limited to, video, images, and audio. To enable users to intuitively understand whether the message transmission device has timed out of receiving the first response message, when the message transmission device has not received the first response message sent by the message broker after the preset waiting time, it generates the first display information and sends it to the requesting end for display. Based on the first display information displayed by the requesting end, the user can determine that the message transmission device has not received the first response message after the preset waiting time. In a specific embodiment, after receiving the device instruction sent by the requesting end, the message transmission device also creates an onTimeOut callback function, generates the first display information, defines the first display information in the onTimeOut callback function, and then sends the first display information to the requesting end for display by calling the onTimeOut callback function. For example, after the message transmission device generates the first display information "Received device response timed out", it defines the first display information in the onTimeOut callback function and then sends the first display information to the requesting end for display by calling the onTimeOut callback function. This embodiment displays multiple monitoring results on the same page by sending the first display information to the requesting end. The monitoring results do not need to be manually aggregated, which improves monitoring efficiency.

[0123] In one specific embodiment, after sending the device message to the message broker in step 303, the following steps 408-410 may be included, as follows:

[0124] 408. Receive the second response message returned by the message broker based on the device instruction;

[0125] 409. Based on the second response message, generate third display information;

[0126] 410. Send the third display information to the requesting end for display.

[0127] The second response message is a response message returned by the message broker to the message transmission device based on the device instruction. The second response message can be the same content as the device instruction, or it can be other content that indicates the target device has received the device instruction. In order to receive the second response message, the message transmission device also needs to subscribe to the topic corresponding to the second response message from the message broker. The third display information is used to indicate that the target device has received the device instruction. The display methods for the third display information include, but are not limited to, video, images, and audio. In this embodiment, after the message transmission device sends the device instruction to the message broker, the message broker returns a second response message to the message transmission device based on the device instruction. After receiving the second response message, the message transmission device generates third display information based on the second response message and sends the third display information to the requesting end for display. Through the third display information displayed on the requesting end, the user can know that the target device has received the device message. For example, the message transmission device generates third display information stating "The target device has received the device message" and sends this third display information to the requesting end for display. This embodiment, by sending the third display information to the requesting end for display, can display multiple monitoring results on the same page, eliminating the need for manual aggregation of monitoring results and improving monitoring efficiency.

[0128] In one specific embodiment, after receiving the first response message, step 305 may include the following steps 411-412, as follows:

[0129] 411. Based on the first response message, generate second display information;

[0130] 412. Send the second display information to the requesting end for display.

[0131] The second display information is used to indicate that the target device has responded to the device command. The display methods of the second display information include, but are not limited to, video, images, and audio. In this embodiment, after the message transmission device receives the first response message returned by the target device based on the device command from the message broker, it generates the second display information based on the first response message and sends the second display information to the requesting end for display. For example, the message transmission device generates the second display information "The target device has responded to the device message" and sends this second display information to the requesting end for display. By sending the second display information to the requesting end for display, this embodiment can display multiple monitoring results on the same page, eliminating the need for manual aggregation of monitoring results, improving monitoring efficiency, and allowing for customized business development based on the link monitoring situation.

[0132] To better implement the message transmission method in the embodiments of this application, a message transmission device is also provided in the embodiments of this application, such as... Figure 4 As shown, the message transmission device 500 includes:

[0133] The request receiving unit 501 is used to receive a message transmission request from the requesting end for the target device, and to obtain the device status information of the target device based on the message transmission request.

[0134] The connection establishment unit 502 is used to determine whether the target device is online based on the device status information, and when the target device is online, to establish a web socket connection with the requesting end.

[0135] The first sending unit 503 is used to receive a device instruction sent by the requesting end, create an execution thread corresponding to the device instruction, and send the device instruction to the message broker. The device instruction includes an attribute query instruction and / or a device control instruction. The execution thread is used to send the device instruction to the message broker and send a first response message to the requesting end. The first response message is a response message returned by the target device based on the device instruction.

[0136] The message listening unit 504 is used to set the state of the execution thread to a blocked state before receiving the first response message, and to monitor whether the first response message sent by the message broker is received.

[0137] The second sending unit 505 is used to, upon receiving the first response message, release the blocking state of the execution thread and send the first response message to the requesting end according to the web socket connection.

[0138] In this embodiment, the message transmission device forwards the device instruction to the target device through a message broker. The requesting end only needs to send a message transmission request and the device instruction to the message transmission device to realize the device instruction issuance. There is no need to install an additional MQTT client. Since the requesting end and the message transmission device communicate based on a web socket connection, the requesting end does not need to subscribe to topics to send and receive data, avoiding manual maintenance of relevant information and reducing human error. The execution thread is set to a blocked state, and the blocked state of the execution thread is released after receiving the first response message, which can realize synchronous listening to the first response message.

[0139] In some embodiments of this application, the request receiving unit 501 is specifically used for:

[0140] According to the message transmission request, a status acquisition request is sent to the message broker, and the status acquisition request includes the device identifier of the target device;

[0141] The message broker receives the device status information returned by the status acquisition request.

[0142] In some embodiments of this application, the first sending unit 503 is specifically used for:

[0143] Receive the device instruction sent by the requesting end, and create a callback function based on the device instruction;

[0144] The device instruction is sent to the message broker via the callback function.

[0145] In some embodiments of this application, the message listening unit 504 is specifically used for:

[0146] A synchronization queue is generated based on the device instructions to set the execution thread to a blocked state. The synchronization queue is used to block the execution thread. When the synchronization queue is empty, the execution thread is in a blocked state. When the synchronization queue is not empty, the blocking state of the execution thread is released.

[0147] In some embodiments of this application, the second sending unit 505 is specifically used for:

[0148] The first response message is forwarded to the synchronization queue to unblock the execution thread.

[0149] In some embodiments of this application, the second sending unit 505 is further configured to:

[0150] The first response message is encapsulated;

[0151] The encapsulated first response message is sent to the requesting end via the execution thread according to the web socket connection.

[0152] In some embodiments of this application, the message transmission device 500 further includes:

[0153] An information generation unit is used to generate first display information when the first response message is not received after a preset waiting time.

[0154] The third sending unit is used to send the first display information to the requesting end for display.

[0155] In some embodiments of this application, the message transmission device 500 further includes:

[0156] A message receiving unit is used to receive a second response message returned by the message broker based on the device instruction.

[0157] In some embodiments of this application, the information generation unit is further configured to:

[0158] Based on the first response message, generate the second display information;

[0159] Based on the second response message, third display information is generated.

[0160] In some embodiments of this application, the third sending unit is further configured to:

[0161] The second display information is sent to the requesting end for display.

[0162] The third display information is sent to the requesting end for display.

[0163] This application also provides a computer device that integrates any of the message transmission devices provided in this application, the computer device comprising:

[0164] One or more processors;

[0165] Memory; and

[0166] One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor of the steps in the message transmission method described in any of the above-described message transmission method embodiments.

[0167] This application also provides a computer device that integrates any of the message transmission devices provided in this application. For example... Figure 5 As shown, it illustrates a structural schematic diagram of the computer device involved in the embodiments of this application, specifically:

[0168] The computer device may include components such as a processor 601 with one or more processing cores, a memory 602 with one or more computer-readable storage media, a power supply 603, and an input unit 604. Those skilled in the art will understand that... Figure 5 The computer device structure shown does not constitute a limitation on the computer device and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein:

[0169] The processor 601 is the control center of the computer device. It connects various parts of the computer device via various interfaces and lines, and performs various functions and processes data by running or executing software programs and / or modules stored in the memory 602, and by calling data stored in the memory 602, thereby providing overall monitoring of the computer device. Optionally, the processor 601 may include one or more processing cores; preferably, the processor 601 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 601.

[0170] The memory 602 can be used to store software programs and modules. The processor 601 executes various functional applications and data processing by running the software programs and modules stored in the memory 602. The memory 602 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 602 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 602 may also include a memory controller to provide the processor 601 with access to the memory 602.

[0171] The computer device also includes a power supply 603 that supplies power to the various components. Preferably, the power supply 603 can be logically connected to the processor 601 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 603 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0172] The computer device may also include an input unit 604, which can be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.

[0173] Although not shown, the computer device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 601 in the computer device loads the executable files corresponding to the processes of one or more application programs into the memory 602 according to the following instructions, and the processor 601 runs the application programs stored in the memory 602 to realize various functions, as follows:

[0174] The receiving end receives a message transmission request for the target device and obtains the device status information of the target device based on the message transmission request.

[0175] Based on the device status information, determine whether the target device is online. When the target device is online, establish a web socket connection with the requesting end.

[0176] The system receives a device instruction sent by the requesting end, creates an execution thread corresponding to the device instruction, and sends the device instruction to the message broker. The device instruction includes an attribute query instruction and / or a device control instruction. The execution thread is used to send the device instruction to the message broker and send a first response message to the requesting end. The first response message is a response message returned by the target device based on the device instruction.

[0177] Before receiving the first response message, the execution thread is set to a blocked state, and it is monitored whether the first response message sent by the message broker is received;

[0178] Upon receiving the first response message, the execution thread is unblocked and the first response message is sent to the requesting end according to the web socket connection.

[0179] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0180] Therefore, embodiments of this application provide a computer-readable storage medium, which may include: read-only memory (ROM), random access memory (RAM), a magnetic disk, or an optical disk, etc. A computer program is stored thereon, which is loaded by a processor to execute the steps in any of the message transmission methods provided in embodiments of this application. For example, the computer program loaded by the processor can execute the following steps:

[0181] The receiving end receives a message transmission request for the target device and obtains the device status information of the target device based on the message transmission request.

[0182] Based on the device status information, determine whether the target device is online. When the target device is online, establish a web socket connection with the requesting end.

[0183] The system receives a device instruction sent by the requesting end, creates an execution thread corresponding to the device instruction, and sends the device instruction to the message broker. The device instruction includes an attribute query instruction and / or a device control instruction. The execution thread is used to send the device instruction to the message broker and send a first response message to the requesting end. The first response message is a response message returned by the target device based on the device instruction.

[0184] Before receiving the first response message, the execution thread is set to a blocked state, and it is monitored whether the first response message sent by the message broker is received;

[0185] Upon receiving the first response message, the execution thread is unblocked and the first response message is sent to the requesting end according to the web socket connection.

[0186] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the detailed descriptions of other embodiments above, which will not be repeated here.

[0187] In practice, each of the above units or structures can be implemented as an independent entity or can be arbitrarily combined to be implemented as the same or several entities. For the specific implementation of each of the above units or structures, please refer to the previous method embodiments, which will not be repeated here.

[0188] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.

[0189] The above provides a detailed description of a message transmission method, apparatus, computer device, and storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A message transmission method, characterized in that, The message transmission method is applied to a message transmission device, which is communicatively connected to a requesting end and a message broker, and the message broker is communicatively connected to a target device. The message transmission method includes: The receiving end receives a message transmission request for the target device and obtains the device status information of the target device based on the message transmission request. Based on the device status information, determine whether the target device is online. When the target device is online, establish a web socket connection with the requesting end. The system receives a device instruction sent by the requesting end, creates an execution thread corresponding to the device instruction, and sends the device instruction to the message broker. The device instruction includes an attribute query instruction and / or a device control instruction. The execution thread is used to send the device instruction to the message broker and send a first response message to the requesting end. The first response message is a response message returned by the target device based on the device instruction. Before receiving the first response message, the execution thread is set to a blocked state, and it is monitored whether the first response message sent by the message broker is received; Upon receiving the first response message, the execution thread is unblocked and the first response message is sent to the requesting end according to the web socket connection.

2. The message transmission method according to claim 1, characterized in that, The step of obtaining the device status information of the target device based on the message transmission request includes: According to the message transmission request, a status acquisition request is sent to the message broker, and the status acquisition request includes the device identifier of the target device; The message broker receives the device status information returned by the status acquisition request.

3. The message transmission method according to claim 1, characterized in that, The step of receiving the device instruction sent by the requesting end and sending the device instruction to the message broker includes: Receive the device instruction sent by the requesting end, and create a callback function based on the device instruction; The device instruction is sent to the message broker via the callback function.

4. The message transmission method according to claim 1, characterized in that, After monitoring whether the first response message sent by the message broker has been received, the method includes: If the first response message is not received after a preset waiting time, first display information is generated; The first display information is sent to the requesting client for display. After receiving the first response message, the method further includes: Based on the first response message, generate the second display information; The second display information is sent to the requesting end for display.

5. The message transmission method according to claim 1, characterized in that, Setting the state of the execution thread to a blocked state includes: A synchronization queue is generated based on the device instructions to set the state of the execution thread to a blocked state. The synchronization queue is used to block the execution thread. When the synchronization queue is empty, the execution thread is in a blocked state. When the synchronization queue is not empty, the blocking state of the execution thread is released. The process of releasing the execution thread from its blocked state includes: The first response message is forwarded to the synchronization queue to unblock the execution thread.

6. The message transmission method according to claim 1, characterized in that, Sending the first response message to the requesting end based on the web socket connection includes: Encapsulate the first response message; The encapsulated first response message is sent to the requesting end via the execution thread according to the web socket connection.

7. The message transmission method according to claim 1, characterized in that, After sending the device instruction to the message broker, the method further includes: Receive the second response message returned by the message broker based on the device instruction; Based on the second response message, generate the third display information; The third display information is sent to the requesting end for display.

8. A message transmission device, characterized in that, The message transmission device is communicatively connected to both the message broker and the requesting end, and the message broker is communicatively connected to the target device. The message transmission device includes: A request receiving unit is used to receive a message transmission request from a requesting end for a target device, and to obtain device status information of the target device based on the message transmission request. A connection establishment unit is used to determine whether the target device is online based on the device status information, and when the target device is online, to establish a web socket connection with the requesting end. The first sending unit is configured to receive a device instruction sent by the requesting end, create an execution thread corresponding to the device instruction, and send the device instruction to the message broker. The device instruction includes an attribute query instruction and / or a device control instruction. The execution thread is configured to send the device instruction to the message broker and send a first response message to the requesting end. The first response message is a response message returned by the target device based on the device instruction. The message listening unit is used to set the state of the execution thread to a blocked state before receiving the first response message, and to monitor whether the first response message sent by the message broker is received. The second sending unit is used to, upon receiving the first response message, release the blocking state of the execution thread and send the first response message to the requesting end according to the web socket connection.

9. A computer device, characterized in that, The computer device includes: One or more processors; Memory; and One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the message transmission method of any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, It stores a computer program, which is loaded by a processor to perform the steps of the message transmission method according to any one of claims 1 to 7.