A message stream disorder correction method based on MQTT protocol and serial port waveform display system
Through the message flow out-of-order correction method and serial port waveform display system based on the MQTT protocol, the problem of lack of remote communication on the oscilloscope and MQTT message out-of-order is solved, achieving stable waveform display and communication in a resource-limited environment, and improving the portability of the system. performance and communication quality.
Patent Information
- Application Number
- CN202210521175.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-13
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2042-05-13
AI Technical Summary
In the existing technology, oscilloscopes lack remote communication capabilities, and in the Internet of Things and embedded terminal devices with fewer resources, the communication protocol based on the HTTP protocol cannot achieve stable waveform display in harsh network environments, and the MQTT message data flow is After passing through the cluster, there will be an out-of-order problem.
Using the message flow out-of-order correction method based on the MQTT protocol, the data is received through the mobile serial terminal and stored in the cache queue in order, and a specific data frame format is used to parse and reorder, combined with the MQTT cloud service instance and the Internet of Things platform to realize inter-device message transmission and correction, and cooperates with the waveform custom display module to display the corrected positive sequence message flow on the interface.
It achieves stable IoT communication in a low-bandwidth and high-latency network environment, reduces hardware performance costs, improves the portability of waveform display and overall system communication quality, and ensures the sequence of message flow and the accuracy of waveform display.
Smart Images

Figure CN114828094B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet of Things and embedded communication technology, and in particular to a message stream disorder correction method based on the MQTT protocol and a serial port waveform display system. Background Art
[0002] In the prior art, hardware devices such as oscilloscopes are commonly used as tools for waveform display, such as Chinese patent CN103869121A and Chinese patent CN101131404A and other related patents. It can achieve high-precision waveform display effects, but is limited by issues related to the use environment. Commonly used oscilloscopes do not have remote communication capabilities, and due to different functional requirements in the oscilloscope, the instrument equipment is ultimately large in size and not portable. If there is no oscilloscope locally, if you need to detect the signal waveform sent by the device, you need relevant professional instruments to meet the functional requirements.
[0003] In the related wireless waveform display methods, local WiFi hotspot LAN and local Bluetooth BLE point-to-point communication are usually used, both of which have certain limitations in geographical distance. For example, WiFi hotspots need to be within the physical broadcast coverage of the SSID, while Bluetooth BLE requires the distance between the two devices to maintain communication within a dozen meters. These methods cannot achieve remote waveform display in the true sense.
[0004] The advantage of using wireless communication for waveform display is that it can expand other communication methods. The waveform display of data is only a special communication method. In some commonly used communication protocols such as HTTP, since this type of communication protocol is mainly used for resource-rich intelligent computer devices, and it consumes a lot of network resources. This cannot show a stable communication effect in some IoT and embedded terminal devices with fewer resources. When the device is in some environments with poor network quality, the protocol cannot achieve the ideal communication effect.
[0005] The existing communication method based on the MQTT protocol can realize machine-to-machine IoT communication. However, during the communication process, the message order within the MQTT message data stream will be disrupted after passing through the cluster of MQTT instances. Summary of the invention
[0006] Purpose of the invention: In view of the problems existing in the prior art, the present invention provides a message flow disorder correction method and a serial port waveform display system based on the MQTT protocol, which realizes wireless communication based on the MQTT protocol, reduces the performance cost requirements of the hardware on the device, and corrects the message flow disorder during the communication process.
[0007] Technical solution: The present invention provides a method for correcting message flow disorder based on the MQTT protocol, comprising the following steps:
[0008] Step 1: The mobile serial terminal receives a frame of data and stores each frame of data in a cache queue in the order in which it is received;
[0009] Step 2: The mobile serial terminal and data acquisition equipment need to use a specific data frame format for corresponding data analysis, namely [HEAD][ID][MSG][#[SID]], where [HEAD] represents the data frame header, [ID] represents the ID of the currently received message frame, [MSG] represents the data carried by the currently received message frame, and [SID] represents the ID of the next received message frame. The [MSG] data carried after the [ID] of each message frame is the message. ;
[0010] Step 3: When you receive a message for the first time, directly The data in the [MSG] part is pushed into the corrected positive sequence message FIFO queue, and at the same time, a check is made to see if there is a # sign in the data frame; if so, go to step 4 and wait for the next message , otherwise the complete continuous message queue reception is completed;
[0011] Step 4: If the [ID] of the message data frame received again is consistent with the data frame [SID] received last time, the currently received The data in [MSG] are pushed into the corrected positive-sequence message FIFO queue. Otherwise, go to step 5 to scan the cache queue.
[0012] Step 5: When there is a corresponding cached message in the cache queue, the data consistent with the last received data frame [SID] is pushed into the corrected positive sequence message FIFO queue; if no data consistent with the last received data frame [SID] is found during the scanning process, the correct message is started to wait. Receiving completed.
[0013] Furthermore, in step 5, when the number of waiting frames exceeds a set range, the message buffer queue is directly cleared and continuous message reception is re-triggered.
[0014] Furthermore, each time data is pushed from the cache queue into the corrected FIFO queue, the position in the original cache queue is automatically Clear the data in.
[0015] The present invention also discloses a serial port waveform display system based on the MQTT protocol, including MQTT cloud service instance rules, a mobile serial port terminal, a data acquisition device, a message flow disorder correction method based on the MQTT protocol, and a waveform custom display module;
[0016] The MQTT cloud service instance rule uses the IoT platform and creates an MQTT service instance, adds multiple device message topics for device subscription and sending, and creates device-to-device message flow rules, which include transferring a message publishing topic tx of one device to a message topic rx subscribed by another device, and vice versa;
[0017] The mobile serial port terminal includes: subscribing to a message topic rx set by a cloud MQTT service instance, publishing a message topic tx to a cloud MQTT service instance, subscribing to a message topic rx from a cloud MQTT service instance, and receiving messages sent by other devices from the topic; receiving message streams from other devices and parsing them, wherein the messages have two types: text and data frames, and the text can be used for full-duplex communication of any message, and the data frame is used for the mobile serial port terminal to receive a data message stream sent by a data acquisition device, and the message data stream sent by the data acquisition device is parsed and reordered to complete waveform display;
[0018] The data collection device includes: subscribing to the message topic rx set by the cloud MQTT service instance, publishing the message topic tx to the cloud MQTT service instance, sending the collected data information to other devices through the message topic tx, receiving messages sent by other devices from the rx message topic, and making corresponding functional controls on itself according to different messages or custom instructions;
[0019] The message stream disorder correction method based on the MQTT protocol is based on the message stream disorder correction method described in any one of claims 1 to 3;
[0020] The waveform custom display module includes: the mobile serial port terminal corrects the disordered data message stream and extracts the data from the regular message stream into a buffer area for waveform display. When the buffer area needs to overflow or all data frames are moved to the buffer area, the buffer area update is triggered, and the data in the buffer area is sent to the interface and the waveform is displayed.
[0021] Furthermore, the buffer area in the waveform custom display method is a FIFO queue. When an update event is triggered, the data is mapped to the corresponding grid in sequence to display the waveform data in dots. The mobile serial port terminal uses a double grid display method in the waveform display, which includes: setting a large grid, evenly dividing the area to be displayed as a waveform into an appropriate number, and evenly dividing each small grid into several smaller grids; when the data in the waveform buffer area is mapped to the display interface one by one in sequence, each time a different waveform data point moves from the smallest grid after division to the next grid, when the waveform needs to be stretched and shrunk horizontally or vertically, the position distance between two adjacent data points in the waveform is changed by changing the number of equal divisions of the internal grid.
[0022] Beneficial effects:
[0023] 1. The present invention uses the MQTT protocol in the entire system to realize machine-to-machine IoT communication. Since MQTT is an extremely lightweight (publish / subscribe) message transmission protocol, it is specially designed for low-bandwidth, high-latency or unreliable network environments. The stability of the overall communication quality of the system and the performance of the hardware required by the system have good performance. In the entire system, the mobile serial port terminal is responsible for the final correction and display processing of the data, the data acquisition device is responsible for data transmission and other function expansions, and the IoT platform is only responsible for message forwarding. The entire system has little dependence on different IoT platforms. The system uses the applet on the mobile device as the mobile serial port terminal, so that the overall waveform display effect of the system has good portability.
[0024] 2. The present invention implements a method for correcting the disorder of continuous messages after passing through a service instance cluster when using MQTT as a remote communication protocol. A communication frame format is set and a cache queue is used to correct the disorder. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It is an error correction flow chart of the message stream disorder correction method based on the MQTT protocol of the present invention;
[0026] Figure 2 The connection relationship of the Internet of Things platform of the MQTT protocol of the present invention;
[0027] Figure 3 This is the data cache update process of the mobile serial port terminal of the present invention. DETAILED DESCRIPTION
[0028] The present invention will be further described below in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present invention, and cannot be used to limit the protection scope of the present invention.
[0029] The present invention discloses a serial port waveform display system based on the MQTT protocol, which mainly comprises an MQTT cloud service instance rule, a mobile serial port terminal, a data acquisition device, a message flow disorder correction method based on the MQTT protocol after the MQTT message flow passes through the back end of an MQTT service cluster, and a waveform custom display module.
[0030] The MQTT cloud service instance rules include: using the IoT platform and creating an MQTT service instance, adding multiple device message topics for device subscription and sending, and creating device-to-device message flow rules. The rules include transferring the message publishing topic tx of one device to the message topic rx subscribed by another device, and vice versa.
[0031] The content of the mobile serial terminal includes: subscribing to the message topic rx set by the cloud MQTT service instance. Publishing the message topic tx to the cloud MQTT service instance, subscribing to the message topic rx from the cloud MQTT service instance and receiving messages sent by other devices from the topic. Receive the message stream of other devices and parse it. The message has two types: text and data frame. The text can be used for full-duplex communication of any message. The data frame is used for the mobile serial terminal to receive the data message stream sent by the data acquisition device. Parse the message data stream sent by the data acquisition device and reorder it to complete the waveform display.
[0032] The data collection device content includes: subscribing to the message topic rx set by the cloud MQTT service instance. Publishing the message topic tx to the cloud MQTT service instance, and sending the collected data information to other devices through the message topic tx. Receive messages sent by other devices from the rx message topic, and make corresponding functional controls on itself according to different messages or custom instructions.
[0033] The method for correcting the disorder of the message flow based on the MQTT protocol after the MQTT message flow passes through the backend of the MQTT service cluster includes:
[0034] 1) Each frame message actually received by the mobile serial port terminal is collected Indicates that the actual The message received is .use Represents the corrected FIFO queue of the positive sequence message, where the actual The content of this message is When the mobile serial port terminal receives a frame of data, it stores each frame of data in the cache in the order in which it is received. Represents the message collection in all caches. The position is used to store the corrected The content of the message .
[0035] 2) During peer communication, the mobile serial terminal and data acquisition device must use a specific data frame format ([HEAD][ID][MSG][#[SID]]) to perform corresponding data analysis. The [MSG] data carried after the [ID] of each frame message is the message Among them, [HEAD] represents the data frame header, [ID] represents the ID of the currently received message frame, [MSG] represents the data carried by the currently received message frame, and [SID] represents the ID of the next received message frame.
[0036] 3) When a message is first received (i.e. ), directly send the message The data in the [MSG] section is pushed , and at the same time check whether there is a # sign in the data frame. If it exists, wait for the next message Otherwise, the complete continuous message queue reception is completed, and the [SID] in the data frame indicates the correct [ID] of the next message in the message queue.
[0037] 4) If the [ID] of the message data frame received again is the same as the [SID] of the data frame received last time, the currently received [MSG] Partial data push , otherwise the cache queue to scan.
[0038] 5) When there is a corresponding cache message in the cache queue (that is, it satisfies Condition) Pushing data into If no , then start waiting for the correct When the reception is completed and the number of frames to be waited exceeds the set range, the message buffer queue is directly cleared (i.e., manually set established), and re-trigger continuous message reception.
[0039] Each time the data is transferred from Push into FIFO queue In the cache queue, the original position is automatically Data in Empty. When overflow or reception is completed, an update event is automatically triggered to update the data of the waveform image.
[0040] The waveform custom display module includes: the mobile serial port terminal corrects the disordered data message stream and extracts the data from the positive message stream to the buffer area for waveform display. When the buffer area needs to overflow or all the data frames are moved to the buffer area, the buffer area update will be triggered, and the data in the buffer area will be sent to the interface and the waveform will be displayed. The buffer area is a FIFO queue. When an update event is triggered, the data is mapped to the corresponding grid in sequence to display the waveform data in a point-to-point manner. The mobile serial port terminal uses a double grid display method in the waveform display to facilitate the measurement of the waveform. The content includes: setting a large grid, evenly dividing the area to be displayed by the waveform into an appropriate number, and evenly dividing each divided small grid into several smaller grids. When the data in the waveform buffer area is mapped to the display interface one by one in sequence, each different waveform data point moves from the smallest grid after the division to the next grid. When the waveform needs to be stretched and shrunk horizontally or vertically, the position distance between two adjacent data points in the waveform is changed by changing the number of equal divisions of the internal grid.
[0041] In this embodiment, both the mobile serial terminal applet and the data acquisition device are first connected to the Internet of Things platform using the MQTT protocol. After the connection is successful, both subscribe to the rx topic to receive data sent by the other party. Both use the tx topic to send data to the other party. The Internet of Things platform implements the information flow rule of forwarding the information published by one device in the tx topic to the rx topic of another device in turn. The mobile serial terminal applet listens to the data stream, and the data acquisition device sends the data stream. After receiving the data, the mobile serial terminal applet processes the data for remote communication and waveform display. The data acquisition device uploads data in the format of a data frame. After processing the task of information parsing and extraction of the data frame, the mobile terminal needs to put the information in the buffer area. When the buffer area needs to overflow or all the data frames are moved to the buffer area, it will trigger a buffer update, and the data in the buffer area will be sent to the interface and the waveform will be displayed.
[0042] The mobile serial terminal applet uses the MQTT protocol to connect to the IoT platform. First, both the IoT device and the applet must be connected to the IoT platform. After the connection is successful, the IoT platform forwards messages through the Topic (topic) through rules to enable two devices to forward messages and achieve two-way communication. In the applet, the messages uploaded by the IoT device are read and displayed, and the data is processed in the waveform function to extract the information in the data frame, and the displayed waveform size is adjusted according to the customized waveform display range.
[0043] The above embodiments are only for illustrating the technical concept and features of the present invention, and their purpose is to enable people familiar with the technology to understand the content of the present invention and implement it accordingly, and they cannot be used to limit the protection scope of the present invention. Any equivalent transformation or modification made according to the spirit of the present invention should be included in the protection scope of the present invention.
Claims
1. A message flow disorder correction method based on the MQTT protocol, characterized in that: The steps include: Step 1: The mobile serial terminal receives a frame of data and stores each frame of data in a cache queue in the order in which it is received; Step 2: The mobile serial terminal and data acquisition equipment need to use a specific data frame format for corresponding data analysis, namely [HEAD][ID][MSG][#[SID]], where [HEAD] represents the data frame header, [ID] represents the ID of the currently received message frame, [MSG] represents the data carried by the currently received message frame, and [SID] represents the ID of the next received message frame. The [MSG] data carried after the [ID] of each message frame is the message. ; Step 3: When you receive a message for the first time, directly The data in the [MSG] part is pushed into the corrected positive sequence message FIFO queue, and at the same time, a check is made to see if there is a # sign in the data frame; if so, go to step 4 and wait for the next message , otherwise the complete continuous message queue reception is completed; Step 4: If the [ID] of the message data frame received again is consistent with the data frame [SID] received last time, the currently received The data in [MSG] are pushed into the corrected positive-sequence message FIFO queue. Otherwise, go to step 5 to scan the cache queue. Step 5: When there is a corresponding cached message in the cache queue, the data consistent with the last received data frame [SID] is pushed into the corrected positive sequence message FIFO queue; if no data consistent with the last received data frame [SID] is found during the scanning process, the correct message is started to wait. Receiving completed.
2. The method for correcting message flow disorder based on the MQTT protocol according to claim 1, characterized in that: In step 5, when the number of waiting frames exceeds the set range, the message buffer queue is directly cleared and continuous message reception is re-triggered.
3. The method for correcting message flow disorder based on the MQTT protocol according to claim 1, characterized in that: Each time data is pushed from the cache queue into the corrected FIFO queue, the position in the original cache queue is automatically Clear the data in.
4. A system using the message flow disorder correction method based on the MQTT protocol according to any one of claims 1 to 3, characterized in that: Including MQTT cloud service instance rules, mobile serial terminal, data acquisition equipment, message flow disorder correction based on MQTT protocol and waveform custom display module; The MQTT cloud service instance rule uses the IoT platform and creates an MQTT service instance, adds multiple device message topics for device subscription and sending, and creates device-to-device message flow rules, which include transferring a message publishing topic tx of one device to a message topic rx subscribed by another device, and vice versa; The mobile serial port terminal includes: subscribing to a message topic rx set by a cloud MQTT service instance, publishing a message topic tx to a cloud MQTT service instance, subscribing to a message topic rx from a cloud MQTT service instance, and receiving messages sent by other devices from the topic; receiving message streams from other devices and parsing them, wherein the messages have two types: text and data frames, and the text can be used for full-duplex communication of any message, and the data frame is used for the mobile serial port terminal to receive a data message stream sent by a data acquisition device, and the message data stream sent by the data acquisition device is parsed and reordered to complete waveform display; The data collection device includes: subscribing to the message topic rx set by the cloud MQTT service instance, publishing the message topic tx to the cloud MQTT service instance, sending the collected data information to other devices through the message topic tx, receiving messages sent by other devices from the rx message topic, and making corresponding functional controls on itself according to different messages or custom instructions; The waveform custom display module includes: the mobile serial terminal corrects the disordered data message stream and extracts the data from the normal message stream into a buffer area for waveform display, and when the buffer area needs to overflow or all data frames are moved to the buffer area, the buffer area update is triggered, and the data in the buffer area is sent to the interface and the waveform is displayed; The buffer area in the waveform custom display module is a FIFO queue. When an update event is triggered, the data is mapped to the corresponding grid in sequence to display the waveform data in dots. The mobile serial port terminal uses a double grid display method in the waveform display, which includes: setting a large grid, evenly dividing the area to be displayed by the waveform into an appropriate number, and evenly dividing each divided small grid into several smaller grids; when the data in the waveform buffer area is mapped to the display interface one by one in sequence, each time a different waveform data point moves from the smallest grid after the division to the next grid, when the waveform needs to be stretched and shrunk horizontally or vertically, the position distance between two adjacent data points in the waveform is changed by changing the number of equal divisions of the internal grid.
