Communication method and device of industrial intelligent machine based on MQTT message protocol, and program product
By using the MQTT message protocol and real-time operating system in industrial intelligence machines, the high cost problem caused by the use of PLCs and industrial control machines is solved, real-time control and data transmission of industrial intelligence machines are realized, the cost of use is reduced, and it is suitable for industrial automation. control.
Patent Information
- Application Number
- CN202410747498.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-11
- Publication Date
- 2024-09-24
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing PLCs and industrial control machines need to be used together in industrial automation control, resulting in high costs and the inability to support real-time control and data transmission functions at the same time.
Using an industrial intelligence machine based on the MQTT message protocol, a message channel is established in the artificial intelligence machine through a real-time operating system and the MQTT protocol to realize real-time collection of PLC data and execution of equipment control instructions, and through buffer queues for data transmission and control instructions. Caching and processing.
It realizes that the artificial intelligence machine can be used as a PLC for equipment control and as a data transmission carrier, which reduces the cost of use and is suitable for large-scale applications in the field of industrial automation control.
Smart Images

Figure CN118694784A
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of industrial automation control technology, and specifically relates to a communication method, device and program product of an industrial intelligent machine based on the MQTT message protocol. Background Art
[0002] At present, in the field of industrial automation control, PLC (Programmable Logic Controller) is mostly used for real-time control of industrial equipment, and industrial control machines are used for data transmission. Among them, PLC is a digital computing and operating electronic system specially designed for use in industrial environments. It uses a programmable memory, which stores instructions for performing logical operations, sequential control, timing, counting and arithmetic operations. It can control various types of mechanical equipment through digital or analog input and output, thereby completing various production industrial activities.
[0003] However, the existing PLCs and industrial control machines have the following shortcomings: most PLC devices support real-time control, but do not support data transmission based on the MQTT protocol. At the same time, traditional industrial control machines support data transmission but do not support real-time control. Therefore, the two need to be used in combination, that is, when collecting and transmitting PLC data, an additional device is required to realize data transmission, which increases the cost of use. Based on this, providing an industrial intelligent machine communication method that can support the MQTT protocol for data transmission, so as to simultaneously complete device control and data transmission based on the industrial intelligent machine, has become an urgent problem to be solved. Summary of the invention
[0004] The purpose of the present invention is to provide a communication method, device and program product for an industrial intelligent machine based on the MQTT message protocol, so as to solve the problem of high cost caused by the need to use PLC and industrial control machines in combination in the prior art.
[0005] In order to achieve the above object, the present invention adopts the following technical solutions:
[0006] In a first aspect, a communication method of an artificial intelligence machine based on the MQTT message protocol is provided, which is applied to the artificial intelligence machine, wherein a real-time operating system is installed in the artificial intelligence machine, and the method includes:
[0007] Receiving an MQTT configuration file transmitted by an MQTT server, and establishing an MQTT message channel with the MQTT server based on the MQTT configuration file, wherein the MQTT configuration file is sent from a host computer to the MQTT server;
[0008] Establish a send buffer queue and a receive buffer queue;
[0009] Collecting PLC data on the real-time side of the real-time operating system, wherein the real-time side is the execution side of the task with the highest current execution priority in the real-time operating system;
[0010] Cache the PLC data into the sending buffer queue, and / or cache the received device control instructions into the receiving buffer queue, wherein the device control instructions are transmitted from the host computer to the MQTT server, and transmitted from the MQTT server to the IIoT machine through the MQTT message channel;
[0011] Read the device control instructions in the receiving buffer queue, execute the device control instructions, and / or send all PLC data cached in the sending buffer queue to the MQTT server through the MQTT message channel, so that the MQTT server forwards the received PLC data to the host computer, so as to complete the data transmission and / or device control of the artificial intelligence machine after all the cached PLC data are sent and / or after the device control instructions are executed.
[0012] Based on the above disclosed content, the present invention installs a real-time operating system in the industrial intelligent machine, wherein the real-time operating system uses a preemptive scheduling method to execute tasks, that is, high-priority tasks can forcibly interrupt the execution of low-priority tasks. Therefore, based on the operating system, the real-time control requirements of industrial equipment can be met; at the same time, the present invention also establishes an MQTT message channel between the host computer and the MQTT server through the MQTT configuration file issued by the host computer, and establishes corresponding sending and receiving buffer queues; based on this, when data transmission is required, the PLC data of the real-time side in the operating system can be collected in real time and cached in the sending buffer queue, thereby recording the complete data change process, and then, the PLC data cached in the sending buffer queue can be sent to the MQTT server through the MQTT message channel, and the MQTT server can forward it to the host computer; in this way, the transmission of the collected PLC data can be completed; at the same time, the industrial intelligent machine can also receive device control instructions through the MQTT message channel; wherein, after receiving, it can be cached in the receiving buffer queue; then, the device control instruction in the receiving buffer queue is read and executed, and the real-time control of the device can be completed.
[0013] Through the above design, the present invention realizes the data transmission and equipment control of the IIoT machine simultaneously through the real-time operating system and the MQTT protocol, wherein, by capturing PLC data on the real-time side of the real-time operating system and caching the data; then, using the MQTT protocol to upload the cached data, the PLC data transmission can be completed; at the same time, the control instructions sent by the upper computer are received through the MQTT protocol, and cached in the same way, and then the instructions are read from the cache and executed, so that the real-time control of the equipment can be completed; thus, the present invention enables the IIoT machine not only to control the equipment as a PLC, but also to be used as a data transmission carrier for data transmission. Based on this, one IIoT machine can complete the work of multiple machines before, thereby greatly reducing the cost of use. Therefore, the present invention is very suitable for large-scale application and promotion in the field of industrial automation control.
[0014] In a possible design, after collecting the PLC data, the method further includes:
[0015] Generate an encryption private key, and use the encryption private key to encrypt the PLC data to obtain encrypted PCL data;
[0016] The encrypted PLC data is cached in the sending buffer queue.
[0017] In one possible design, the MQTT profile also includes quality of service;
[0018] Wherein, sending all PLC data cached in the sending buffer queue to the MQTT server through the MQTT message channel includes:
[0019] Based on the quality of service and through the MQTT message channel, all PLC data cached in the sending buffer queue are sent to the MQTT server.
[0020] In a possible design, the quality of service includes three quality of service levels, wherein each quality of service level is respectively associated with corresponding designated data and corresponding transmission rules;
[0021] Wherein, according to the quality of service and through the MQTT message channel, all PLC data cached in the sending buffer queue are sent to the MQTT server, which includes:
[0022] Determine whether there is designated data corresponding to the highest service quality level in the PLC data cached in the sending buffer queue;
[0023] If so, all cached PLC data are transmitted to the MQTT server according to the transmission rule corresponding to the highest service quality level and using the MQTT message channel.
[0024] In a possible design, all cached PLC data are transmitted to the MQTT server according to the transmission rules corresponding to the highest service quality level and using the MQTT message channel, including:
[0025] Utilizing the MQTT message channel, transmitting the cached PLC data to the MQTT server;
[0026] Determine whether a first message response frame sent by the MQTT server is received, wherein the first message response frame is generated by the MQTT server after receiving a second message response frame sent by the host computer, and the second message response frame is generated by the host computer after receiving PLC data sent by the MQTT server;
[0027] If not, the MQTT message channel is reused to transmit the cached PLC data to the MQTT server until the first message response frame sent by the MQTT server is received, and after receiving the first message response frame, the cached PLC data is deleted from the sending buffer queue.
[0028] In one possible design, the method further includes:
[0029] If not, determining whether there is designated data corresponding to a target service quality level in the PLC data cached in the sending buffer queue, wherein the target service quality level is a service quality level between a highest service quality level and a lowest service quality level;
[0030] If so, the cached PLC data is transmitted to the MQTT server according to the transmission rule corresponding to the target service quality level and using the MQTT message channel.
[0031] In one possible design, according to the transmission rule corresponding to the target service quality level and using the MQTT message channel, the cached PLC data is transmitted to the MQTT server, including:
[0032] Initialize the number of transmissions t to 1, and transmit the cached PCL data for the tth time through the MQTT message channel;
[0033] Determine whether a third message response frame sent by the MQTT server is received, wherein the third message response frame is generated by the MQTT server after receiving a fourth message response frame sent by the host computer, and the fourth message response frame is generated by the host computer after receiving the PLC data uploaded by the MQTT server;
[0034] If not, then increment t by 1 and determine whether t is greater than the maximum number of transmissions;
[0035] If not, the cached PCL data is transmitted again for the tth time through the MQTT message channel until t is equal to the maximum number of transmissions or the third message response frame is received, then the transmission of the PCL data is stopped and the cached PLC data is deleted from the sending buffer queue.
[0036] In one possible design, if there is no designated data corresponding to the target service quality level in the PLC data cached in the sending buffer queue, the method further includes:
[0037] According to the transmission rules corresponding to the lowest service quality level and using the MQTT message channel, the cached PLC data is transmitted to the MQTT server.
[0038] In a second aspect, a communication device for an artificial intelligence machine based on the MQTT message protocol is provided, taking the device as an artificial intelligence machine as an example, wherein a real-time operating system is installed in the artificial intelligence machine, and the device includes:
[0039] A communication establishing unit, configured to receive an MQTT configuration file transmitted by an MQTT server, and to establish an MQTT message channel with the MQTT server based on the MQTT configuration file, wherein the MQTT configuration file is sent from a host computer to the MQTT server;
[0040] A buffer queue establishment unit, used to establish a sending buffer queue and a receiving buffer queue;
[0041] A data acquisition unit, used to collect PLC data on the real-time side of the real-time operating system, wherein the real-time side is the execution side of the task with the highest current execution priority in the real-time operating system;
[0042] A cache unit, used for caching the PLC data into the sending buffer queue, and / or caching the received device control instructions into the receiving buffer queue, wherein the device control instructions are transmitted from the host computer to the MQTT server, and transmitted from the MQTT server to the IIoT machine through the MQTT message channel;
[0043] A data processing unit is used to read the device control instructions in the receiving buffer queue and execute the device control instructions, and / or send all PLC data cached in the sending buffer queue to the MQTT server through the MQTT message channel, so that the MQTT server forwards the received PLC data to the host computer, so as to complete the data transmission and / or device control of the artificial intelligence machine after all the cached PLC data are sent and / or after the device control instructions are executed.
[0044] In a third aspect, another communication device for an artificial intelligence machine based on the MQTT message protocol is provided. Taking the device as an electronic device as an example, the device includes a memory, a processor and a transceiver which are communicatively connected in sequence, wherein the memory is used to store computer programs, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute the communication method for an artificial intelligence machine based on the MQTT message protocol as described in the first aspect or any possible design of the first aspect.
[0045] In a fourth aspect, a storage medium is provided, on which instructions are stored. When the instructions are executed on a computer, the communication method of an artificial intelligence machine based on the MQTT message protocol as described in the first aspect or any possible design of the first aspect is executed.
[0046] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, causes the computer to execute the artificial intelligence machine communication method based on the MQTT message protocol as described in the first aspect or any possible design of the first aspect.
[0047] Beneficial effects:
[0048] (1) The present invention enables the artificial intelligence machine to not only be used as a PLC to control equipment, but also to be used as a data transmission carrier to transmit data. Based on this, a single artificial intelligence machine can complete the work of multiple machines in the past, thereby greatly reducing the cost of use. Therefore, the present invention is very suitable for large-scale application and promotion in the field of industrial automation control.
[0049] (2) The present invention can set the QoS network transmission service quality and can set different transmission rules for different data, thereby ensuring the reliability of message transmission.
[0050] (3) The data transmission security of the present invention is high. Among them, the MQTT protocol supports the use of keys to encrypt data transmission, thereby ensuring the security of message transmission.
[0051] (4) The present invention supports real-time data recording and preservation. Specifically, the present invention is provided with a cache mechanism to cope with usage scenarios where PLC data changes rapidly, that is, the collected PLC data is recorded in a buffer queue. In this way, the entire data change process can be saved internally, thereby ensuring the integrity of the data.
[0052] (5) The present invention provides a customized solution that can provide customized data transmission according to the business needs of the enterprise, thereby meeting the personalized needs of the enterprise.
[0053] (6) The present invention can provide application integration services, wherein communication services and third-party applications can be integrated using a communication method, thereby providing scalability and integration of communication services; thus, flexibility of use can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 A schematic flow chart of the steps of a communication method for an artificial intelligence machine based on the MQTT message protocol provided in an embodiment of the present invention;
[0055] Figure 2 A schematic diagram of the structure of a communication device for an artificial intelligence machine based on the MQTT message protocol provided in an embodiment of the present invention;
[0056] Figure 3 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0057] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the present invention will be briefly introduced below in combination with the drawings and the description of the embodiments or the prior art. Obviously, the following description of the structure of the drawings is only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. It should be noted that the description of these embodiments is used to help understand the present invention, but does not constitute a limitation of the present invention.
[0058] It should be understood that although the terms first, second, etc. may be used herein to describe various units, these units should not be limited by these terms. These terms are only used to distinguish one unit from another unit. For example, a first unit can be referred to as a second unit, and similarly, a second unit can be referred to as a first unit without departing from the scope of the exemplary embodiments of the present invention.
[0059] It should be understood that the term "and / or" that may appear in this article is merely a description of the association relationship between associated objects, indicating that three relationships may exist. For example, A and / or B can represent three situations: A exists alone, B exists alone, and A and B exist at the same time. The term " / and" that may appear in this article describes another type of association object relationship, indicating that two relationships may exist. For example, A / and B can represent two situations: A exists alone, and A and B exist alone. In addition, the character " / " that may appear in this article generally indicates that the previous and next associated objects are in an "or" relationship.
[0060] Example:
[0061] See also Figure 1 As shown, the communication method of the IIM based on the MQTT message protocol provided in this embodiment realizes the data transmission and equipment control of the IIM at the same time through the real-time operating system and the MQTT protocol. In this way, the IIM can not only be used as a PLC to control the equipment, but also as a data transmission carrier for data transmission. Based on this, one IIM can complete the work of multiple machines in the past, thereby greatly reducing the cost of use. Therefore, this method is very suitable for large-scale application and promotion in the field of industrial automation control; wherein, for example, this method can be but not limited to running on the IIM, MQTT server and host computer side. Optionally, this embodiment is explained by running on the IIM side as an example. wherein, in this embodiment, a real-time operating system is installed in the IIM to meet the real-time control requirements of industrial equipment based on the system's preemptive task execution mode (i.e., high-priority tasks can forcibly interrupt the execution of low-priority tasks). It can be understood that the aforementioned execution subject does not constitute a limitation on the embodiments of the present application. Accordingly, the operation steps of this method can be but not limited to the following steps S1 to S5.
[0062] S1. Receive an MQTT configuration file transmitted by an MQTT server, and establish an MQTT message channel with the MQTT server based on the MQTT configuration file, wherein the MQTT configuration file is sent by a host computer to the MQTT server; in this embodiment, the MQTT configuration file is constructed by a user in the host computer according to the identity information of the IIoT machine, the option to maintain connection, QLS (clean up session), quality of service and other information, and by creating a new function module (i.e., FB module), which can be pre-stored in the host computer. In this way, when in use, the host computer can send the configuration file to the MQTT server, and then send it to the IIoT machine via the MQTT server; based on this, the IIoT machine can establish an MQTT message channel with the MQTT server based on the configuration file.
[0063] Optionally, the process of establishing the MQTT message channel may be but is not limited to: the IAM sends a CONNECT message to the MQTT server (the message includes the identity information of the IAM, an option to maintain the connection, and QLS); after receiving the CONNECT message, the MQTT server sends a CONNACK message to the IAM as a response (including information confirming that the connection has been established); wherein, if the connection is successfully established, an MQTT message channel is successfully established between the IAM and the MQTT server, and PUBLISH messages can be started to be sent and received; in this way, based on the aforementioned method, an MQTT connection can be established between the IAM and the MQTT server and the host computer.
[0064] At the same time, the aforementioned service quality can include but is not limited to three service quality levels, wherein each service quality level is respectively associated with corresponding designated data and corresponding transmission rules. Therefore, the corresponding service quality level can be determined according to the data to be transmitted, so as to transmit the data according to the corresponding transmission rules; of course, the designated data corresponding to each service quality level can be specifically set according to actual use, which is not specifically limited here, and the aforementioned data transmission process is transmitted in detail in the following steps.
[0065] After establishing the MQTT message channel based on the aforementioned step S1, the present embodiment also takes into account the fact that the time for PLC data changes is very short. Therefore, in order to ensure the real-time nature of the recorded PLC data, the present embodiment also establishes corresponding sending buffer queues and receiving buffer queues so that the collected and received data can be cached in the corresponding queues, thereby performing data transmission and instruction execution based on the sending and receiving buffer queues; wherein, the buffer queue establishment process can be but is not limited to as shown in the following step S2.
[0066] S2. Establish a sending buffer queue and a receiving buffer queue; in the present embodiment, the sending buffer queue is used in data transmission, and is mainly used to store the collected PLC data; and the receiving buffer queue is used in device control, and is mainly used to store the device control instructions sent by the host computer; in this way, data transmission and device control can be completed simultaneously based on the sending buffer queue and the receiving buffer queue; of course, the specific number of the sending buffer queue and the receiving buffer queue can be set according to actual use, and is not specifically limited here.
[0067] After the sending buffer queue and the receiving buffer queue are constructed, data transmission and device control can be performed, and the process can be but not limited to the following steps S3 to S5.
[0068] S3. Collecting PLC data on the real-time side of the real-time operating system, wherein the real-time side is the execution side of the task with the highest current priority in the real-time operating system; in this embodiment, it has been explained above that the task execution mode of the real-time operating system is a preemptive execution mode, that is, a high-priority task can forcibly interrupt the execution of a low-priority task; therefore, the real-time side of the real-time operating system always executes the task with the highest current priority, based on this, the collected PLC data is equivalent to the data corresponding to the task with the highest current priority; and after the PLC data is collected, since the PLC data changes very quickly, the speed of data transmission is lower than the speed of change of the PLC data; therefore, in order to ensure the integrity of the transmitted data, this embodiment caches the collected PLC data to the sending buffer queue, so as to completely record all data corresponding to the task with the highest current priority; wherein, the caching process of PLC data can be but is not limited to as shown in the following step S4.
[0069] S4. Cache the PLC data into the sending buffer queue, and / or cache the received device control instructions into the receiving buffer queue, wherein the device control instructions are transmitted from the host computer to the MQTT server, and transmitted from the MQTT server to the IIM through the MQTT message channel; in specific implementation, the IIM provided in this embodiment supports sending and receiving data at the same time, therefore, when caching the collected PLC data, the device control instructions issued by the MQTT server can also be received through the MQTT message channel; similarly, the received device control instructions also need to be cached so that they can be executed preferentially according to the specified priority level later; of course, the received device control instructions are cached in the receiving buffer queue; in this way, based on the sending buffer queue and the receiving buffer queue, data transmission and device control can be completed simultaneously.
[0070] In a specific implementation, since the MQTT protocol supports secure transmission, that is, it supports username and password verification, supports server-side single authentication, supports two-way authentication and other functions; therefore, users can generate their own private keys and open public keys, and use asymmetric encryption to encrypt data; based on this, after collecting PLC data, this embodiment can also generate an encrypted private key, and use the encrypted private key to encrypt the PLC data to obtain encrypted PCL data; then, the encrypted PLC data can be cached in the sending buffer queue; of course, a conventional asymmetric encryption algorithm can be used to generate a private key and encrypt PLC data, and its principle will not be repeated.
[0071] After the data is cached, data transmission and device control can be performed; the example data transmission and device control process may be, but is not limited to, as shown in the following step S5.
[0072] S5. Read the device control instructions in the receiving buffer queue, and execute the device control instructions, and / or send all the PLC data cached in the sending buffer queue to the MQTT server through the MQTT message channel, so that the MQTT server forwards the received PLC data to the host computer, so as to complete the data transmission and / or device control of the artificial intelligence machine after all the cached PLC data are sent, and / or after the device control instructions are executed.
[0073] In this embodiment, since it has been explained above that the MQTT configuration file also includes service quality, the transmission process of PLC data in this embodiment is: based on the service quality and through the MQTT message channel, all PLC data cached in the sending buffer queue are sent to the MQTT server.
[0074] At the same time, it is also explained above that the service quality includes three service quality levels, and each service quality level is associated with corresponding specified data and corresponding transmission rules; therefore, this embodiment takes the above three service quality levels as an example to illustrate the specific transmission process of PLC data, which can be but not limited to as shown in the following steps S51 to S54.
[0075] S51. Determine whether there is designated data corresponding to the highest service quality level in the PLC data cached in the sending buffer queue; in this embodiment, the highest service quality level is represented by QoS2, and the lowest service quality level is represented by QoS0; the service quality level between the highest and lowest service quality levels is represented by QoS1; optionally, QoS2 is used to indicate that the receiving end can ensure that the message can be received once, that is, for very important data points, this transmission mode is adopted when the data cannot be lost, wherein MQTT must ensure that the data is reachable, so the sending end can stop the message push only after ensuring that the other end subscriber has received the message; and QoS1 means at least one transmission, that is, for more important data points, in some weak network conditions, after the data is sent once, if the sending end does not receive the response frame of the receiving end receiving the data, it needs to be sent again, and after multiple attempts, if no reply is received, then stop sending; similarly, QoS0 means at most one transmission, that is, for some data variables of industrial control, data that is not particularly important can be selected to be transmitted at most once, and it is not necessary to ensure that each data arrives safely; therefore, this embodiment determines the service quality level used for this transmission according to the data contained in the cached PLC data.
[0076] If the PLC data cached in the sending buffer queue contains designated data corresponding to the highest service quality level, then data transmission is performed according to the transmission rule corresponding to QoS2, and the process may be but is not limited to the following step S52.
[0077] S52. If so, all cached PLC data are transmitted to the MQTT server according to the transmission rules corresponding to the highest service quality level and using the MQTT message channel; in this embodiment, the transmission process corresponding to QoS2 can be but is not limited to the following steps S52a to S52c.
[0078] S52a. Utilize the MQTT message channel to transmit the cached PLC data to the MQTT server.
[0079] S52b. Determine whether the first message response frame sent by the MQTT server is received, wherein the first message response frame is generated by the MQTT server after receiving the second message response frame sent by the host computer, and the second message response frame is generated by the host computer after receiving the PLC data sent by the MQTT server.
[0080] S52c. If not, reuse the MQTT message channel to transmit the cached PLC data to the MQTT server until the first message response frame sent by the MQTT server is received, and after receiving the first message response frame, delete the cached PLC data from the sending buffer queue.
[0081] In this embodiment, the transmission process corresponding to S52a~S52c is essentially as follows: after the IIoT sends the current message (data can be read from the sending buffer queue according to the preset interval as the message sent this time) to the MQTT server, the server will store the message and send a response frame to the IIoT to indicate that the message has been received; at this time, the MQTT server will send the received message to the host computer (i.e., the subscriber), and after receiving the message, the host computer will send a response frame (i.e., the aforementioned second message response frame) to the MQTT server, and after receiving the response frame, the MQTT server will send a response frame to the sender. The publisher (i.e., the IAM) returns the corresponding response frame (i.e., the first message response frame). At this time, the publisher can determine that the subscriber has received the message, and can stop sending and delete the message. If the host computer does not receive the message sent by the IAM this time, it will not return the corresponding response frame to the MQTT server. At this time, the IAM cannot receive the response frame returned by the MQTT server. Therefore, it needs to send it again and repeat the above process until the response frame returned by the MQTT server is received. In this way, by adopting the above transmission rules, it can be guaranteed that the subscriber can definitely receive the message sent by the IAM.
[0082] Similarly, when there is no designated data corresponding to the highest service quality level in the PLC data cached in the sending buffer queue, then the following steps S53 and S54 need to be executed.
[0083] S53. Determine whether there is designated data corresponding to a target service quality level in the PLC data cached in the sending buffer queue, wherein the target service quality level is a service quality level between a highest service quality level and a lowest service quality level.
[0084] S54. If so, the cached PLC data is transmitted to the MQTT server according to the transmission rules corresponding to the target service quality level and using the MQTT message channel; specifically, this embodiment performs data transmission according to the transmission rules corresponding to QoS1, and the process can be but is not limited to the following steps S54a to S54d.
[0085] S54a. Initialize the number of transmissions t to 1, and transmit the cached PCL data for the tth time through the MQTT message channel.
[0086] S54b. Determine whether the third message response frame sent by the MQTT server is received, wherein the third message response frame is generated by the MQTT server after receiving the fourth message response frame sent by the host computer, and the fourth message response frame is generated by the host computer after receiving the PLC data uploaded by the MQTT server.
[0087] S54c. If not, then increment t by 1 and determine whether t is greater than the maximum number of transmissions.
[0088] S54d. If not, retransmit the cached PCL data for the tth time through the MQTT message channel until t is equal to the maximum number of transmissions or the third message response frame is received, then stop transmitting the PCL data and delete the cached PLC data from the sending buffer queue.
[0089] In this embodiment, the transmission process corresponding to steps S54a~S54d is similar to steps S52a~S52c, that is, when the response frame transmitted by the MQTT server is not received, the message needs to be transmitted again; but different from the aforementioned steps S52a~S52c is: this transmission rule is set with a maximum number of transmissions, that is, when the number of transmissions of the message to be transmitted this time is greater than the maximum number of transmissions, the transmission needs to be stopped, and it does not need to guarantee that the subscriber can definitely receive the message; in this way, this transmission level is lower than the aforementioned first transmission level, and is suitable for the transmission of some relatively important data; of course, the importance of the data can be specifically set according to the actual usage scenario, and is not specifically limited here, and the same is true for the maximum number of transmissions.
[0090] In addition, when the PLC data cached in the sending buffer queue does not contain the specified data corresponding to the target service quality level, it is necessary to transmit the cached PLC data to the MQTT server according to the transmission rule corresponding to the lowest service quality level and using the MQTT message channel; wherein, this transmission method is: the ICM transmits the PLC data to the MQTT server through the MQTT message channel, and deletes the PLC data after transmission; in this way, the transmission rule corresponding to QoS0 is to transmit only once, and the next data can be transmitted after the transmission is completed; therefore, this transmission method does not need to ensure that each data reaches the subscriber.
[0091] Through the above description of the three transmission modes, this embodiment can flexibly set the network's QoS network transmission service quality according to the usage scenario and requirements, thereby ensuring the reliability of message transmission.
[0092] Therefore, through the communication method of the IIM based on the MQTT message protocol described in detail in the aforementioned steps S1 to S5, the present invention simultaneously realizes the data transmission and device control of the IIM through the real-time operating system and the MQTT protocol. In this way, the IIM can not only be used as a PLC to control the device, but also as a data transmission carrier to transmit data. Based on this, one IIM can complete the work of multiple machines before, thereby greatly reducing the cost of use. Therefore, the present invention is very suitable for large-scale application and promotion in the field of industrial automation control.
[0093] like Figure 2 As shown, the second aspect of this embodiment provides a hardware device for implementing the communication method of an artificial intelligence machine based on the MQTT message protocol described in the first aspect of the embodiment, taking the device as an artificial intelligence machine as an example, including:
[0094] The communication establishing unit is used to receive an MQTT configuration file transmitted by an MQTT server, and to establish an MQTT message channel with the MQTT server based on the MQTT configuration file, wherein the MQTT configuration file is sent from a host computer to the MQTT server.
[0095] The buffer queue establishing unit is used to establish a sending buffer queue and a receiving buffer queue.
[0096] The data acquisition unit is used to collect PLC data on the real-time side of the real-time operating system, wherein the real-time side is the execution side of the task with the highest current execution priority in the real-time operating system.
[0097] A cache unit is used to cache the PLC data into the sending buffer queue, and / or cache the received device control instructions into the receiving buffer queue, wherein the device control instructions are transmitted from the host computer to the MQTT server, and transmitted from the MQTT server to the artificial intelligence machine through the MQTT message channel.
[0098] A data processing unit is used to read the device control instructions in the receiving buffer queue and execute the device control instructions, and / or send all PLC data cached in the sending buffer queue to the MQTT server through the MQTT message channel, so that the MQTT server forwards the received PLC data to the host computer, so as to complete the data transmission and / or device control of the artificial intelligence machine after all the cached PLC data are sent and / or after the device control instructions are executed.
[0099] The working process, working details and technical effects of the device provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.
[0100] like Figure 3 As shown, the third aspect of this embodiment provides another communication device for an artificial intelligence machine based on the MQTT message protocol. Taking the device as an electronic device as an example, it includes: a memory, a processor and a transceiver that are communicatively connected in sequence, wherein the memory is used to store computer programs, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute the communication method for an artificial intelligence machine based on the MQTT message protocol as described in the first aspect of the embodiment.
[0101] For example, the memory may include, but is not limited to, random access memory (RAM), read-only memory (ROM), flash memory, first-in-first-out memory (FIFO) and / or first-in-last-out memory (FILO), etc. Specifically, the processor may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). At the same time, the processor may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state.
[0102] In some embodiments, the processor may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. For example, the processor may not be limited to a microprocessor of the STM32F105 series, a reduced instruction set computer (RISC) microprocessor, an X86 or other architecture processor, or a processor with an integrated embedded neural network processor (NPU); the transceiver may be, but is not limited to, a wireless fidelity (WIFI) wireless transceiver, a Bluetooth wireless transceiver, a general packet radio service technology (Genera l Packet Rad ioService, GPRS) wireless transceiver, a ZigBee protocol (a low-power LAN protocol based on the IEEE 802.15.4 standard, ZigBee) wireless transceiver, a 3G transceiver, a 4G transceiver and / or a 5G transceiver, etc. In addition, the device may also include, but is not limited to, a power module, a display screen and other necessary components.
[0103] The working process, working details and technical effects of the electronic device provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.
[0104] The fourth aspect of this embodiment provides a storage medium storing instructions for the communication method of an artificial intelligence machine based on the MQTT message protocol as described in the first aspect of the embodiment, that is, the storage medium stores instructions, and when the instructions are run on a computer, the communication method of an artificial intelligence machine based on the MQTT message protocol as described in the first aspect of the embodiment is executed.
[0105] The storage medium refers to a carrier for storing data, which may include but is not limited to a floppy disk, a CD, a hard disk, a flash memory, a USB flash drive and / or a memory stick, etc. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
[0106] The working process, working details and technical effects of the storage medium provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.
[0107] The fifth aspect of this embodiment provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the communication method of an artificial intelligence machine based on the MQTT message protocol as described in the first aspect of the embodiment, wherein the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
[0108] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A communication method for an artificial intelligence machine based on the MQTT message protocol, characterized in that: Applied to an artificial intelligence machine, wherein a real-time operating system is installed in the artificial intelligence machine, and the method comprises: Receiving an MQTT configuration file transmitted by an MQTT server, and establishing an MQTT message channel with the MQTT server based on the MQTT configuration file, wherein the MQTT configuration file is sent from a host computer to the MQTT server; Establish a send buffer queue and a receive buffer queue; Collecting PLC data on the real-time side of the real-time operating system, wherein the real-time side is the execution side of the task with the highest current execution priority in the real-time operating system; Cache the PLC data into the sending buffer queue, and / or cache the received device control instructions into the receiving buffer queue, wherein the device control instructions are transmitted from the host computer to the MQTT server, and transmitted from the MQTT server to the IIoT machine through the MQTT message channel; Read the device control instructions in the receiving buffer queue, execute the device control instructions, and / or send all PLC data cached in the sending buffer queue to the MQTT server through the MQTT message channel, so that the MQTT server forwards the received PLC data to the host computer, so as to complete the data transmission and / or device control of the artificial intelligence machine after all the cached PLC data are sent and / or after the device control instructions are executed.
2. The method according to claim 1, characterized in that After the PLC data is collected, the method further includes: Generate an encryption private key, and use the encryption private key to encrypt the PLC data to obtain encrypted PCL data; The encrypted PLC data is cached in the sending buffer queue.
3. The method according to claim 1, characterized in that The MQTT profile also includes quality of service; Wherein, sending all PLC data cached in the sending buffer queue to the MQTT server through the MQTT message channel includes: Based on the quality of service and through the MQTT message channel, all PLC data cached in the sending buffer queue are sent to the MQTT server.
4. The method according to claim 3, characterized in that The quality of service includes three quality of service levels, wherein each quality of service level is respectively associated with corresponding designated data and corresponding transmission rules; Wherein, according to the quality of service and through the MQTT message channel, all PLC data cached in the sending buffer queue are sent to the MQTT server, which includes: Determine whether there is designated data corresponding to the highest service quality level in the PLC data cached in the sending buffer queue; If so, all cached PLC data are transmitted to the MQTT server according to the transmission rule corresponding to the highest service quality level and using the MQTT message channel.
5. The method according to claim 4, characterized in that According to the transmission rules corresponding to the highest service quality level and using the MQTT message channel, all cached PLC data are transmitted to the MQTT server, including: Utilizing the MQTT message channel, transmitting the cached PLC data to the MQTT server; Determine whether a first message response frame sent by the MQTT server is received, wherein the first message response frame is generated by the MQTT server after receiving a second message response frame sent by the host computer, and the second message response frame is generated by the host computer after receiving PLC data sent by the MQTT server; If not, the MQTT message channel is reused to transmit the cached PLC data to the MQTT server until the first message response frame sent by the MQTT server is received, and after receiving the first message response frame, the cached PLC data is deleted from the sending buffer queue.
6. The method according to claim 4, characterized in that The method further comprises: If not, determining whether there is designated data corresponding to a target service quality level in the PLC data cached in the sending buffer queue, wherein the target service quality level is a service quality level between a highest service quality level and a lowest service quality level; If so, the cached PLC data is transmitted to the MQTT server according to the transmission rule corresponding to the target service quality level and using the MQTT message channel.
7. The method according to claim 6, characterized in that According to the transmission rule corresponding to the target service quality level and using the MQTT message channel, the cached PLC data is transmitted to the MQTT server, including: Initialize the number of transmissions t to 1, and transmit the cached PCL data for the tth time through the MQTT message channel; Determine whether a third message response frame sent by the MQTT server is received, wherein the third message response frame is generated by the MQTT server after receiving a fourth message response frame sent by the host computer, and the fourth message response frame is generated by the host computer after receiving the PLC data uploaded by the MQTT server; If not, then increment t by 1 and determine whether t is greater than the maximum number of transmissions; If not, the cached PCL data is transmitted again for the tth time through the MQTT message channel until t is equal to the maximum number of transmissions or the third message response frame is received, then the transmission of the PCL data is stopped and the cached PLC data is deleted from the sending buffer queue.
8. The method according to claim 6, characterized in that If there is no designated data corresponding to the target service quality level in the PLC data cached in the sending buffer queue, the method further includes: According to the transmission rules corresponding to the lowest service quality level and using the MQTT message channel, the cached PLC data is transmitted to the MQTT server.
9. A communication device for an artificial intelligence machine based on the MQTT message protocol, characterized in that: Applied to an artificial intelligence machine, wherein a real-time operating system is installed in the artificial intelligence machine, and the device comprises: A communication establishing unit, configured to receive an MQTT configuration file transmitted by an MQTT server, and to establish an MQTT message channel with the MQTT server based on the MQTT configuration file, wherein the MQTT configuration file is sent from a host computer to the MQTT server; A buffer queue establishment unit, used to establish a sending buffer queue and a receiving buffer queue; A data acquisition unit, used to collect PLC data on the real-time side of the real-time operating system, wherein the real-time side is the execution side of the task with the highest current execution priority in the real-time operating system; A cache unit, used for caching the PLC data into the sending buffer queue, and / or caching the received device control instructions into the receiving buffer queue, wherein the device control instructions are transmitted from the host computer to the MQTT server, and transmitted from the MQTT server to the IIoT machine through the MQTT message channel; A data processing unit is used to read the device control instructions in the receiving buffer queue and execute the device control instructions, and / or send all PLC data cached in the sending buffer queue to the MQTT server through the MQTT message channel, so that the MQTT server forwards the received PLC data to the host computer, so as to complete the data transmission and / or device control of the artificial intelligence machine after all the cached PLC data are sent and / or after the device control instructions are executed.
10. A computer program product comprising instructions, characterized in that When the instruction is executed on a computer, the computer is enabled to execute the communication method of an artificial intelligence machine based on the MQTT message protocol as described in any one of claims 1 to 8.
Citation Information
Cited By
Multi-protocol mixed distributed edge communication platform of gluing developing machine and implementation method of multi-protocol mixed distributed edge communication platform
CN120896996A
Emergency equipment intelligent sensing system and method thereof
CN121619342A
