MQTT protocol-based firmware upgrading system and method

By introducing shard transmission, ack confirmation and retransmission mechanisms into the firmware upgrade system, the reliability problem of firmware upgrade in the prior art in the case of unstable network and insufficient hardware is solved, and a more efficient and reliable firmware upgrade process is achieved.

CN119892627APending Publication Date: 2025-04-25SHENZHEN KAIFA TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311389105.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-24
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

The existing firmware upgrade method based on the MQTT protocol is difficult to receive firmware packages at one time when the network environment is unstable and hardware capabilities are insufficient, resulting in slow firmware upgrade speed, low efficiency and error-prone, resulting in insufficient reliability of firmware upgrade operations.

Method used

It provides a firmware upgrade system and method based on the MQTT protocol, which supports shard transmission of firmware packets and ack confirmation and retransmission mechanisms to ensure that the firmware upgrade process is more reliable in unstable network environments.

Benefits of technology

Through the shard transmission of firmware packets and ack confirmation and retransmission mechanisms, the reliability and efficiency of firmware upgrades in unstable network environments and insufficient hardware capabilities are achieved, ensuring the successful transmission of firmware packets.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119892627A_ABST
    Figure CN119892627A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of industrial control equipment, and discloses an MQTT protocol-based firmware upgrading method, which comprises the following steps: S1, terminal equipment receives an upgrading instruction sent by an upgrading server after uploading a to-be-upgraded firmware package on the upgrading server; s2, the terminal equipment compares the version information and judges an upgrade package fragment needing to be downloaded; s3, the terminal equipment sends an upgrade patch fragment downloading request to the upgrade server successively, and receives and stores the upgrade patch fragments; s3, after the terminal equipment sends an upgrade patch fragment downloading request, the upgrade patch fragment index and content sent by the upgrade server are received; s32, the terminal equipment performs ack confirmation on the index and feeds back a result to the upgrading server; and S33, the terminal equipment receives and stores the next upgrade package fragment or the retransmitted current upgrade package fragment. The method and the system for implementing the method support firmware packet fragmentation transmission and an ack confirmation and retransmission mechanism, so that the firmware upgrading process in an unstable network environment is more reliable.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of industrial control equipment, and in particular to a firmware upgrade system and method based on the MQTT protocol. Background Art

[0002] MQTT (Message Queue Telemetry Transport) is a message protocol based on the publish / subscribe paradigm under the ISO standard (ISO / IEC PRF 20922). It works on the TCP / IP protocol family and is a publish / subscribe message protocol designed for remote devices with low hardware performance and insufficient network conditions. It is also a protocol designed for communication between remote sensors and control devices with limited computing power and working on low-bandwidth, unreliable networks. It has the following characteristics: 1) Use the publish / subscribe message mode to provide one-to-many message publishing and decouple applications; 2) Message transmission with load content shielding; 3) Use TCP / IP to provide network connection; 4) There are three message publishing service qualities; 5) Small transmission, low overhead, minimized protocol exchange, and reduced network traffic; 6) Use the Last Will and Testament features to notify relevant parties of abnormal client interruptions. Therefore, the MQTT protocol is often used for firmware upgrades of industrial control equipment to reduce the difficulty and cost of firmware upgrades of industrial control equipment. However, most of the firmware upgrade methods based on the MQTT communication protocol in the industry can only achieve the goal of firmware upgrade. When in an unstable network environment and when the terminal hardware capabilities are insufficient, the firmware package is difficult to receive at one time. The firmware upgrade is slow, inefficient, and prone to errors, which results in insufficient reliability of the firmware upgrade operation. Summary of the invention

[0003] Based on this, it is necessary to provide a firmware upgrade system and method based on the MQTT protocol to address the above-mentioned shortcomings. The firmware upgrade system and method support fragmented transmission of firmware packages and ack confirmation and retransmission mechanism, making the firmware upgrade process more reliable in an unstable network environment.

[0004] A firmware upgrade system based on the MQTT protocol, comprising an upgrade server, a terminal device, and an MQTT middleware for receiving and forwarding data between the upgrade server and the terminal device;

[0005] The upgrade server includes an instruction issuing module for uploading a firmware package to be upgraded and sending an upgrade instruction, an index issuing module for sending an upgrade package fragment index and content according to a request for downloading an upgrade package fragment, and an upgrade package issuing module for selecting to send the next upgrade package fragment or resend the current upgrade package fragment according to the index confirmation situation;

[0006] The terminal device includes an instruction receiving module for receiving an upgrade instruction sent by an instruction issuing module, an upgrade package fragment request module for comparing the current version and the version to be upgraded according to the upgrade instruction and sending a request to download the upgrade package fragment to the index issuing module, an index confirmation judgment module for receiving the upgrade package fragment index and content sent by the index issuing module and performing ack confirmation, and a storage module for receiving the upgrade package fragment sent by the upgrade package issuing module and saving and version updating.

[0007] In one of the embodiments, the firmware package includes a full package and a differential package.

[0008] In one of the embodiments, the upgrade instruction includes the firmware package version number, the number of sub-packages and the md5 value of the firmware package.

[0009] In one embodiment, the storage module is also used to send a new firmware version number to the upgrade server after all upgrade package fragments are downloaded. The upgrade server also includes an upgrade judgment module for judging whether the upgrade is successful based on whether the firmware version number is received.

[0010] In one of the embodiments, when the upgrade judgment module determines that the current upgrade is not completed and the version information to be upgraded received by the upgrade package fragment request module is an upgrade interrupted version, the upgrade package fragment request module queries the upgrade package fragment information in the storage module and sends a download request for the remaining upgrade package fragments of the upgrade interrupted version to the upgrade package release module.

[0011] The present invention also discloses a firmware upgrade method based on the MQTT protocol. The firmware upgrade method is implemented by the above-mentioned firmware upgrade system. The firmware upgrade method comprises the following steps:

[0012] S1. After the terminal device uploads the firmware package to be upgraded on the upgrade server, it receives the upgrade instruction sent by the upgrade server through the MQTT middleware;

[0013] S2. The terminal device compares the current version with the version to be upgraded, and determines the upgrade package segment to be downloaded;

[0014] S3, the terminal device sends a request to download the upgrade package fragments to the upgrade server one by one through the MQTT middleware, and receives and saves the upgrade package fragments sent by the upgrade server;

[0015] The step S3 comprises:

[0016] S31, after the terminal device sends a request to download the upgrade package fragment to the upgrade server, it receives the upgrade package fragment index and content sent by the upgrade server;

[0017] S32, the terminal device performs ack confirmation on the upgrade package fragment index and feeds back the confirmation result to the upgrade server;

[0018] S33: The terminal device receives and saves the next upgrade package segment sent by the upgrade server according to the ack confirmation feedback or the current upgrade package segment resent by the upgrade server.

[0019] In one of the embodiments, the firmware package includes a full package and a differential package.

[0020] In one of the embodiments, the upgrade instruction includes the firmware package version number, the number of sub-packages and the md5 value of the firmware package.

[0021] In one embodiment, the step S3 further includes:

[0022] S4. After all upgrade package fragments are downloaded, the terminal device sends the new firmware version number to the upgrade server;

[0023] S5. The upgrade server determines whether the upgrade is successful based on whether the firmware version number is received.

[0024] In one embodiment, the step S5 further includes:

[0025] S6. When the terminal device version upgrade is interrupted and the version information to be upgraded received again by the terminal device is the upgrade interrupted version, the terminal device sends a download request for the remaining upgrade package fragments of the upgrade interrupted version to the upgrade server.

[0026] In the implementation of the MQTT protocol-based firmware upgrade system and method of the present invention, the terminal device sends a request to download the upgrade package fragment to the upgrade server one by one according to the version information to be upgraded, and the upgrade server sends the upgrade package fragment to the terminal device fragment by fragment according to the request, so that the terminal device can save and update it, thereby realizing the fragmented transmission of the firmware package, which can meet the version upgrade of the firmware in the case of unstable network and insufficient firmware storage capacity; when each upgrade package fragment is updated, the upgrade package fragment index and content are sent through the upgrade server, and the index is ack confirmed, and the next upgrade package fragment is sent or the current fragment is resent, and the ack confirmation and resend mechanism is adopted to ensure the successful transmission of the firmware package, so that the firmware upgrade process in an unstable network environment is more reliable. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 A module connection diagram of a firmware upgrade system in one embodiment of the present invention;

[0028] Figure 2 A flowchart of a firmware upgrade method in one embodiment of the present invention;

[0029] Figure 3 This is a schematic diagram of information transmission of a firmware upgrade method in one embodiment of the present invention;

[0030] Figure 4 The figure is a logic judgment diagram of a firmware upgrade method in one embodiment of the present invention. DETAILED DESCRIPTION

[0031] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways different from those described herein, and those skilled in the art can make similar improvements without violating the connotation of the present invention, so the present invention is not limited by the specific embodiments disclosed below.

[0032] See also Figure 1 The present invention discloses a highly reliable firmware upgrade system based on the MQTT protocol, the firmware upgrade system comprises an upgrade server 100, a terminal device 200, and an MQTT middleware 300 (MQTT broker) for receiving and forwarding data between the upgrade server 100 and the terminal device 200, that is, the upgrade server 100 and the terminal device 200 perform data interaction through the MQTT protocol, the terminal device 200 is a firmware that needs to be upgraded, the terminal device 200 stores the currently running version, and the upgrade server 100 is used to upgrade the version of the terminal device 200. Specifically, in this embodiment, the upgrade server 100 comprises an instruction publishing module for uploading a firmware package to be upgraded and sending an upgrade instruction, an index publishing module for sending an upgrade package fragment index and content according to a request to download an upgrade package fragment, and an upgrade package publishing module for selecting to send the next upgrade package fragment or resending the current upgrade package fragment according to the index confirmation situation. The terminal device 200 includes an instruction receiving module for receiving an upgrade instruction sent by an instruction publishing module, an upgrade package fragment request module for comparing the current version and the version to be upgraded according to the upgrade instruction and sending a request to download the upgrade package fragment to the index publishing module, an index confirmation judgment module for receiving the upgrade package fragment index and content sent by the index publishing module and performing ack confirmation, and a storage module for receiving the upgrade package fragment sent by the upgrade package publishing module and saving and version updating.

[0033] When the firmware upgrade system is working, each module of the upgrade server 100 and each module of the terminal device 200 work alternately, that is, after the upgrade server 100 sends an instruction to the terminal device 200, the terminal device 200 responds to the instruction and feeds back information to the upgrade server 100, and then the upgrade server 100 sends instructions or information to the terminal device 200 again according to the feedback information, until the terminal device 200 receives and saves the upgrade package fragment from the upgrade server 100. Specifically, when it is necessary to upgrade the firmware version of the terminal device 200, the instruction issuing module of the upgrade server 100 uploads the firmware package to be upgraded according to the input version information to be upgraded, and then sends the version upgrade instruction to the instruction receiving module of the terminal device 200. The upgrade package fragment request module receives the upgrade instruction transmitted by the instruction receiving module, and compares whether the current version of the terminal device 200 is consistent with the information of the version to be upgraded. If they are consistent, there is no need to further upgrade the firmware. If they are inconsistent, the upgrade package fragment request module sends a request to download the upgrade package fragment to the index issuing module. After receiving the request to download the upgrade package fragment, the index publishing module of the upgrade server 100 sends the upgrade package fragment index and content to the index confirmation judgment module of the terminal device 200, and the index confirmation judgment module performs ack (Acknowledgement, confirmation character) confirmation. After the index confirmation judgment module performs ack confirmation, the index confirmation situation is fed back to the upgrade package publishing module. If the upgrade package publishing module receives ack confirmation, that is, receives index confirmation information, the upgrade package publishing module sends the next upgrade package fragment to the storage module of the terminal device 200. If the upgrade package publishing module does not receive ack confirmation, the upgrade package publishing module resends the current upgrade package fragment until timeout to ensure successful firmware package transmission.

[0034] In the above-mentioned firmware upgrade system, the terminal device 200 sends a request to download the upgrade package fragment to the upgrade server 100 one by one according to the version information to be upgraded, and the upgrade server 100 sends the upgrade package fragments to the terminal device 200 fragment by fragment according to the request, so that the terminal device 200 can save and update it, thereby realizing the fragmented transmission of the firmware package, which can meet the version upgrade of the firmware in the case of unstable network and insufficient firmware storage capacity; when each upgrade package fragment is updated, the upgrade package fragment index and content are sent through the upgrade server 100, and the index is confirmed by ack, and the next upgrade package fragment is sent or the current fragment is resent, and the ack confirmation and resend mechanism is adopted to ensure the successful transmission of the firmware package, making the firmware upgrade process more reliable in an unstable network environment.

[0035] In one embodiment, the firmware package includes a full package and a differential package, wherein the full package is a complete package. When the system needs to be reinstalled on the terminal device 200, the new system needs to be completely installed on the terminal device 200. The full package upgrade is to upgrade the complete firmware. Generally, major version upgrades are basically full package upgrades, and the upgrade package is relatively large, generally several GB. The differential package is also called an incremental package, which mainly updates the different parts of the terminal device 200 version, adding patches or making modifications on the basis of the original system. The differential package upgrade is generally a non-major version upgrade, which only upgrades the difference part, and the upgrade package is relatively small, generally a few to hundreds of MB in size. In this embodiment, the full package and the differential package are uploaded through the instruction release module, and both full package upgrade and differential package upgrade are supported, providing multiple options for firmware upgrades.

[0036] Furthermore, the upgrade instruction includes the firmware package version number, the number of sub-packages and the firmware package md5 value. In other words, the instruction issuing module publishes the firmware package version number, the number of sub-packages and the firmware package md5 value of the version to be upgraded to the instruction receiving module, so that the upgrade package fragment request module can compare the firmware package version number with the current firmware package version number in the terminal device 200 to determine whether an upgrade is required. In the case of a need for an upgrade, the upgrade package fragment request module divides the upgrade content into multiple upgrade package fragments according to the content to be upgraded and the number of sub-packages, so as to download and save each upgrade package fragment one by one. The upgrade content of this embodiment includes: when a full package upgrade is adopted, the upgrade content is a complete upgrade package; when a differential package upgrade is adopted, the upgrade content is the part of the version to be upgraded that is different from the current version. When the upgrade package fragments are transmitted between the upgrade server 100 and the terminal device 200, the md5 algorithm is used to encrypt and decrypt the upgrade package fragments to improve the accuracy of information transmission. In this embodiment, the instruction receiving module receives the md5 value of the firmware package, and compares the md5 value of the firmware package to be upgraded sent by the instruction issuing module with the md5 value of the current version of the firmware package to determine the content that needs to be upgraded.

[0037] In one embodiment, the storage module is also used to send a new firmware version number to the upgrade server 100 after all upgrade package fragments are downloaded. The upgrade server 100 also includes an upgrade judgment module for judging whether the upgrade is successful according to whether the firmware version number is received. Further, when the upgrade judgment module determines that the current upgrade is not completed, and the version information to be upgraded received by the upgrade package fragment request module is an upgrade interruption version, the upgrade package fragment request module queries the upgrade package fragment information in the storage module and sends a download request for the remaining upgrade package fragments of the upgrade interruption version to the upgrade package release module. In other words, during the firmware upgrade process, the storage module of the terminal device 200 stores the received upgrade package fragments in real time. If the upgrade is interrupted due to network or other reasons during the process, the upgrade package fragments in the storage module will not be lost. When the network is restored or the firmware upgrade action is restarted, if the instruction receiving module receives the upgrade instruction of the same version again, it can continue to request the undownloaded upgrade package fragments until the upgrade is successful. By continuing the upgrade at the breakpoint, the continuity of the firmware upgrade process is guaranteed, and the problem of the terminal device 200 memory being occupied due to repeated downloading of the upgrade package fragments in the terminal device 200 is avoided.

[0038] Please combine Figure 2-4 The present invention also discloses a firmware upgrade method based on the MQTT protocol. The firmware upgrade method is implemented through the above-mentioned firmware upgrade system. It is based on the MQTT communication protocol and adopts a segmented transmission firmware package upgrade method to meet the firmware upgrade requirements of resource-constrained devices. At the same time, each packet of data uses an ack confirmation and retransmission mechanism to ensure that the firmware package is successfully transmitted, making the upgrade in an unstable network environment more reliable and stable. Specifically, the firmware upgrade method includes the following steps:

[0039] S1. After the terminal device uploads the firmware package to be upgraded on the upgrade server, it receives the upgrade instruction sent by the upgrade server through the MQTT middleware. In this embodiment, the firmware package includes a full package and a differential package. By uploading the full package and the differential package, the upgrade server can support both full package upgrade and differential package upgrade, providing multiple options for firmware upgrade.

[0040] S2. The terminal device compares the current version and the version to be upgraded, and determines the upgrade package fragments that need to be downloaded. In this embodiment, the upgrade instruction includes the firmware package version number, the number of sub-packages, and the firmware package md5 value. In this way, the terminal device can compare the firmware package version number with the current firmware package version number in the terminal device to determine whether an upgrade is required. In the case of a need for an upgrade, the terminal device divides the upgrade content into multiple upgrade package fragments according to the content to be upgraded and the number of sub-packages, so as to download and save each upgrade package fragment one by one. The upgrade content of this embodiment includes: when a full package upgrade is adopted, the upgrade content is a complete upgrade package; when a differential package upgrade is adopted, the upgrade content is the part of the version to be upgraded that is different from the current version. In this embodiment, the terminal device receives the firmware package md5 value, and determines the content that needs to be upgraded by comparing the firmware package md5 value with the firmware package md5 value of the current version. In other words, the terminal device confirms the upgrade package that needs to be downloaded by comparing the firmware package md5 value and the number of sub-packages, and sub-packages the upgrade package into multiple upgrade package fragments.

[0041] S3. The terminal device sends a request to download the upgrade package fragments to the upgrade server one by one through the MQTT middleware, and receives and saves the upgrade package fragments sent by the upgrade server. In this embodiment, after confirming the number of upgrade package fragments to be downloaded and the content of each fragment, the terminal device sends a packet of upgrade package fragments to the upgrade server each time. Similarly, the upgrade server sends a single packet of upgrade package fragments to the terminal device each time according to the request to download the upgrade package fragments, so as to solve the problem of difficulty in receiving the upgrade package due to insufficient hardware capabilities of the terminal device.

[0042] Further, step S3 includes:

[0043] S31, after the terminal device sends a request to download the upgrade package fragment to the upgrade server, it receives the upgrade package fragment index and content sent by the upgrade server; S32, the terminal device acks the upgrade package fragment index and feeds back the confirmation result to the upgrade server; S33, the terminal device receives and saves the next upgrade package fragment sent by the upgrade server according to the ack confirmation feedback or the current upgrade package fragment resent by the upgrade server. Specifically, after the terminal device acks the upgrade package fragment index, if the upgrade server receives the ack confirmation, that is, receives the index confirmation information, the upgrade server sends the next upgrade package fragment to the terminal device for storage; if the upgrade server does not receive the ack confirmation, the upgrade server resends the current upgrade package fragment until it times out to ensure that the firmware package is successfully transmitted.

[0044] In this embodiment, after step S3, the following steps are further included:

[0045] S4. After all upgrade package fragments are downloaded, the terminal device sends the new firmware version number to the upgrade server; S5. The upgrade server determines whether the upgrade is successful based on whether the firmware version number is received. By sending the new firmware version number to the upgrade server, the upgrade server can compare the firmware version number with the firmware version number to be upgraded the next time it performs a firmware upgrade on the terminal device, so as to avoid repeated queries of the terminal device when the firmware version of the terminal device is the latest version, thereby causing system occupancy problems. In addition, when the upgrade server receives the firmware version number, it determines that the current firmware upgrade is successful; if the upgrade server continues to not receive the firmware version number fed back by the terminal device, and the upgrade server does not receive the request to download the upgrade package fragment sent by the terminal device, it determines that the current firmware upgrade operation is interrupted.

[0046] After step S5, the following steps are also included:

[0047] S6. When the terminal device version upgrade is interrupted and the version information to be upgraded received by the terminal device again is the upgrade interrupted version, the terminal device sends a download request for the remaining upgrade package fragments of the upgrade interrupted version to the upgrade server. That is to say, during the firmware upgrade process, the terminal device stores the received upgrade package fragments in real time. If the upgrade is interrupted due to network or other reasons during the process, the upgrade package fragments stored in the terminal device will not be lost. When the network is restored or the firmware upgrade action is restarted, if the terminal device receives the upgrade instruction of the same version again, it can continue to download the undownloaded firmware package fragments when upgrading again until the upgrade is successful. By continuing to upgrade at the breakpoint, the continuity of the firmware upgrade process is guaranteed, and the problem of the terminal device memory being occupied due to repeated downloading of upgrade package fragments in the terminal device is avoided.

[0048] The specific process of the above firmware upgrade method is as follows:

[0049] After the process starts, first make and upload a full package or differential package (i.e. firmware) to the upgrade server. The upgrade server issues an upgrade instruction to the MQTT middleware, which forwards the upgrade instruction to the terminal device. The terminal device packages the contents of the firmware package that needs to be downloaded and upgraded according to the upgrade quality, and sends a request to download the upgrade package fragments package by package. For example, the terminal device first sends a request to download the first package of firmware to the MQTT middleware, and the MQTT middleware forwards the request to the upgrade server. After receiving the request, the upgrade server reads the first package of firmware content, and forwards the index and content of the first package of firmware to the terminal device via the MQTT middleware, and the terminal device acks the first package of firmware content. If the upgrade server does not receive the ack confirmation of the first package of firmware, the upgrade server will re-issue the upgrade instruction or exit the process within the specified time. If the upgrade server receives the ack confirmation of the first package of firmware, it will send the firmware package information such as the upgrade package size, version, type, etc. to the terminal device. After receiving the above information, the terminal device determines whether there is already a fragment of this version. If there is already a fragment of this version, it will request the next package of fragments from the upgrade server, so that the upgrade server sends the next upgrade package fragment to the terminal device; if the terminal device does not have the fragment of this version, it will request the first package of fragments from the upgrade server. The upgrade server sends the first package of firmware content to the terminal device based on the ack confirmation. After the terminal device parses the first package of firmware content, it stores the first package of firmware content, the current number of packages, and the total number of packages, and performs ack confirmation on the first package of firmware content. After confirmation, the terminal device forwards the first package of firmware content confirmation information and the second package of firmware download request information to the upgrade server via the MQTT middleware, and performs the download operation of the second package of firmware, and so on, until the terminal device has received all the firmware fragments.

[0050] After receiving all the firmware fragments, the terminal device determines the upgrade package type and can directly modify the upgrade start flag and reset it, or use the bsdiff differential algorithm to restore the query upgrade package, write the restored upgrade package to the flash, modify the upgrade start flag again and reset it. After resetting, the terminal device runs the boot program and upgrades, then modifies the upgrade completion flag and jumps to the app application, ending the firmware upgrade operation. Finally, the terminal device publishes the latest version of the firmware to the upgrade server via the MQTT middleware, and the upgrade server updates the firmware version information.

[0051] The technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0052] The above-mentioned embodiments only express several implementation methods of the present invention, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.

Claims

1. A firmware upgrade system based on the MQTT protocol, characterized in that: Including upgrading servers, terminal devices, and MQTT middleware for receiving and forwarding data between upgrading servers and terminal devices; The upgrade server includes an instruction issuing module for uploading a firmware package to be upgraded and sending an upgrade instruction, an index issuing module for sending an upgrade package fragment index and content according to a request for downloading an upgrade package fragment, and an upgrade package issuing module for selecting to send the next upgrade package fragment or resend the current upgrade package fragment according to the index confirmation situation; The terminal device includes an instruction receiving module for receiving an upgrade instruction sent by an instruction issuing module, an upgrade package fragment request module for comparing the current version and the version to be upgraded according to the upgrade instruction and sending a request to download the upgrade package fragment to the index issuing module, an index confirmation judgment module for receiving the upgrade package fragment index and content sent by the index issuing module and performing ack confirmation, and a storage module for receiving the upgrade package fragment sent by the upgrade package issuing module and saving and version updating.

2. The firmware upgrade system according to claim 1, characterized in that: The firmware package includes a full package and a differential package.

3. The firmware upgrade system according to claim 1, characterized in that: The upgrade instruction includes the firmware package version number, the number of sub-packages and the firmware package md5 value.

4. The firmware upgrade system according to claim 1, characterized in that: The storage module is also used to send the new firmware version number to the upgrade server after all upgrade package fragments are downloaded. The upgrade server also includes an upgrade judgment module for judging whether the upgrade is successful based on whether the firmware version number is received.

5. The firmware upgrade system according to claim 4, characterized in that: When the upgrade judgment module determines that the current upgrade is not completed and the version information to be upgraded received by the upgrade package fragment request module is an upgrade interrupted version, the upgrade package fragment request module queries the upgrade package fragment information in the storage module and sends a download request for the remaining upgrade package fragments of the upgrade interrupted version to the upgrade package publishing module.

6. A firmware upgrade method based on the MQTT protocol, characterized in that: The firmware upgrade method is implemented by the firmware upgrade system according to any one of claims 1 to 5, and the firmware upgrade method comprises the following steps: S1. After the terminal device uploads the firmware package to be upgraded on the upgrade server, it receives the upgrade instruction sent by the upgrade server through the MQTT middleware; S2. The terminal device compares the current version with the version to be upgraded, and determines the upgrade package segment to be downloaded; S3, the terminal device sends a request to download the upgrade package fragments to the upgrade server one by one through the MQTT middleware, and receives and saves the upgrade package fragments sent by the upgrade server; The step S3 comprises: S31, after the terminal device sends a request to download the upgrade package fragment to the upgrade server, it receives the upgrade package fragment index and content sent by the upgrade server; S32, the terminal device performs ack confirmation on the upgrade package fragment index and feeds back the confirmation result to the upgrade server; S33: The terminal device receives and saves the next upgrade package segment sent by the upgrade server according to the ack confirmation feedback or the current upgrade package segment resent by the upgrade server.

7. The firmware upgrade method based on the MQTT protocol according to claim 6, characterized in that: The firmware package includes a full package and a differential package.

8. The firmware upgrade method based on the MQTT protocol according to claim 6, characterized in that: The upgrade instruction includes the firmware package version number, the number of sub-packages and the firmware package md5 value.

9. The firmware upgrade method based on the MQTT protocol according to claim 6, characterized in that: After step S3, the following steps are also included: S4. After all upgrade package fragments are downloaded, the terminal device sends the new firmware version number to the upgrade server; S5. The upgrade server determines whether the upgrade is successful based on whether the firmware version number is received.

10. The firmware upgrade method based on the MQTT protocol according to claim 9, characterized in that: After step S5, the following steps are also included: S6. When the terminal device version upgrade is interrupted and the version information to be upgraded received again by the terminal device is the upgrade interrupted version, the terminal device sends a download request for the remaining upgrade package fragments of the upgrade interrupted version to the upgrade server.