Iot device data caching and resuming method and system
By scanning the free space at the end of the file system in IoT devices for data caching and breakpoint resume, the problems of storage media wear and storage space exhaustion are solved, thereby achieving data reliability and extending device lifespan.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHENGDU SENHE ELECTRONIC TECH CO LTD
- Filing Date
- 2026-05-12
- Publication Date
- 2026-06-09
AI Technical Summary
When IoT devices experience network outages in unstable environments, existing data caching methods lead to accelerated wear and tear on storage media and rapid depletion of storage space, failing to guarantee data integrity.
By scanning the last sector of each file in the file system to generate a list of temporary addresses, and writing data packets into these free spaces in segments when the network is down, reassembling the data packets using check bits and delimiters, and uploading them to the cloud after the network is restored.
It effectively avoids additional occupation of the formal storage area, reduces the number of times the storage medium is erased and rewritten, extends the life of the device, and ensures the integrity and reliability of the data, realizing dynamic expansion of cache capacity and breakpoint resume.
Smart Images

Figure CN122173033A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of Internet of Things (IoT) technology, specifically to a method and system for data caching and breakpoint resume transmission in IoT devices. Background Technology
[0002] IoT devices are widely deployed in environments with unstable network conditions, such as industrial sites, remote areas, or mobile devices. When the network connection is interrupted, the device needs to temporarily store the collected data on local non-volatile storage media (such as NAND Flash, eMMC, SD card, etc.) and upload it to the cloud after the network is restored to ensure that the data is not lost.
[0003] Currently, common data caching methods involve explicitly creating temporary files, circular buffers, or database tables in the storage medium and writing the data to be uploaded into these formal storage areas. However, these methods have the following drawbacks: First, frequent writing will accelerate the wear and tear of the storage medium, especially for Flash memory with a limited number of erase and write cycles, which will significantly shorten the device's lifespan. Second, when the network outage lasts for a long time, the limited formal storage space may be filled up, resulting in subsequent data being lost because it cannot be cached. Summary of the Invention
[0004] To address the shortcomings of existing technologies, this invention provides a method and system for data caching and breakpoint resumption in IoT devices, which solves the problems of local storage space being rapidly exhausted due to continuous writing and accelerated wear of storage media during network outages.
[0005] To achieve the above objectives, the present invention provides the following technical solution: a method for data caching and breakpoint resumption in Internet of Things (IoT) devices, comprising the following steps: When the device is disconnected from the network, scan the last sector of each file in the file system for the remaining free space, record the starting address and available length, and generate a temporary address list. Initialize the write cursor to the starting address of the first free space in the temporary address list, and reserve a check bit in the last byte of each free space; The data packets to be cached are written in segments to the free space pointed to by the current write cursor. When a sector is full and there is still data to be written, a jump flag is written to the parity bit of the current sector and the write cursor is moved to the next free space. When a data packet is written, the parity bit of the sector where the last byte is located is written with the parity flag of the data packet length and a separator is written at the end of the data packet. After the network is restored, each sector is read sequentially starting from the first free space in the temporary address list. The data packets are reassembled according to the jump flag, parity flag and delimiter in the check bit. Finally, all write traces are cleaned up and the data packets are uploaded to the cloud.
[0006] As a further aspect of the present invention: the free space at the end of the last sector of each file in the scanned file system is specifically: Read the length field L and physical sector size S of each file, and calculate the number of bytes free to use; The specific calculation formula is: free = SL / S; When L / S=0, free=0; The specific formula for calculating the starting address Start is: Start = addr + L / S, where addr is the physical address of the last sector of the file.
[0007] As a further aspect of the present invention: the jump flag is the value 0x5A; In the parity marker, odd numbers are marked with the value 0x01 and even numbers are marked with the value 0x00; The check bit is also used to write an end marker, which is the value 0xA5.
[0008] As a further aspect of the present invention: when the data packet to be cached is written in segments to the free space pointed to by the current write cursor, if the remaining available length of the current tail free space is greater than or equal to the number of remaining bytes of the data packet, then the writing is completed in one go. Otherwise, take the remaining available length as the write length for this time. After the current sector is filled, write a jump flag in the current sector's check bit, update the write cursor to the starting address of the next free space in the temporary address list, and update the remaining available length to the available length of the corresponding space. Repeat until all data packets are written.
[0009] As a further aspect of the present invention: the specific method for writing the parity marker of the data packet length is as follows: After a data packet is written, calculate the remainder when the length of the data packet is divided by 2. If the remainder is 1, write 0x01 to the check bit of the sector where the last byte of the data packet is located; otherwise, write 0x00. The delimiter 0x1F is written immediately after the last byte of the data packet. If there is insufficient space remaining, subsequent sectors are written according to the jump rules.
[0010] As a further aspect of the present invention: the jump rule is specifically as follows: When all the trailing free space in the temporary address list is full and there are still packets to be cached, perform recursive extension: Read the file allocation list of the file system, obtain an unallocated cluster marked as free, extract the physical location of the first sector of the cluster, use this sector as a new writable space with an available length equal to the size of the entire sector in bytes, and use the last byte as a check bit; The cursor will be written to the starting address of the sector, and the address of the extended sector will be recorded in the center of memory; Return to the packet writing step to continue caching, repeating this process until all packets are cached, without modifying the file allocation list of the file system; The physical sector is the smallest addressable read / write unit, and a cluster consists of a group of consecutive physical sectors.
[0011] As a further aspect of the present invention: after the network is restored: Get a temporary buffer Buf; Starting from the first free space address in the temporary address list, read and append the valid data bytes of the current sector to the end of the temporary buffer Buf; Read the current sector check bit. If it is the jump flag 0x5A, jump to the next free space or extended sector in sequence and continue reading. If the odd number is 0x01 or the even number is 0x00, the delimiter is searched in the temporary buffer Buf. The bytes before the delimiter are extracted as a data packet and the parity of the length is verified. If the end mark is found, reading is stopped. Finally, the remaining bytes in the temporary buffer Buf are separated according to the delimiter to obtain the complete data packet.
[0012] As a further aspect of the present invention: the cleaning of all write traces includes: For each free space at the end of the temporary address list, restore its checksum to the original value that the device read and temporarily stored before caching; For each extended sector used in the recursive extension process, write its check bit to 0xFF, and write all the remaining data areas of that sector to 0xFF; Clear the temporary address list and extended address list in runtime memory, and write and read the temporary buffer Buf to and from the cursor.
[0013] As a further aspect of the present invention: the delimiter is a fixed value 0x1F, which is written immediately after the last byte of each data packet and is not included in the data packet length; During reading, each unique 0x1F indicates the end of the current data packet, and this delimiter is not included in the recovered data packet. If the original content of the data packet to be cached contains the value 0x1F, then an escaping process is performed before caching: each 0x1F in the original data is replaced with two consecutive bytes 0x1F, 0x1F; After reading and reassembling, two consecutive 0x1Fs are restored to a single 0x1F, which is treated as ordinary data rather than a delimiter.
[0014] IoT device data caching and breakpoint resume system, including: The scan initialization module is used to scan the free space at the end of each file when the device is disconnected from the network, record the starting address and available length and generate a temporary address list, initialize the cursor to point to the starting address of the first free space in the list, and reserve the last byte of each free space as a check bit; The cache writing module is used to write the data packets to be cached into segments into the free space pointed to by the current write cursor. When the sector is full and the data is not finished writing, a jump flag is written in the parity bit and the cursor is moved to the next free space. When the data packet is finished writing, a length parity flag is written in the parity bit and a separator is written at the end of the packet. The recursive extension module is used to read the allocation bitmap to obtain a free cluster when there is no next free space in the list and there is still data, and to continue caching its sectors as new write space without modifying the allocation state. The read and reassemble module is used to read each sector sequentially from the first free space in the list after network recovery, and reassemble the data packets according to the jump flag, parity flag and delimiter in the check bit. The cleanup upload module is used to clean up write traces and upload the reconstructed data packets to the cloud in sequence.
[0015] This invention provides a method for data caching and breakpoint resumption in Internet of Things (IoT) devices. Compared with existing technologies, it has the following advantages: (1) This invention scans the free space at the end of the last sector of each file in the file system and writes the data to be cached into these unused fragment areas. There is no need to create temporary files or open up formal storage space, thereby avoiding the extra occupation of formal storage areas during network outages and effectively alleviating the problem of tight storage capacity. Moreover, the free space at the end of the file and unallocated clusters are used for cache writing without modifying the allocation bitmap and metadata of the file system. All write operations occur in the physical areas that have been marked as idle, which significantly reduces the number of times the storage medium is erased and rewritten, and extends the service life of IoT devices. (2) By setting a check bit and a data packet separator, the present invention realizes the segmented writing and precise reading of cached data. After the network is restored, the original data packet can be completely reconstructed according to the check bit and separator, ensuring zero data loss during network outage and reliable interruption resumption. (3) When the pre-scanned tail free space is exhausted, the present invention automatically finds the unallocated cluster marked as free in the file system and uses its sector as a new writable space to continue caching, realizing the dynamic expansion of the cache capacity. The whole process does not modify the allocation state of the file system, has good scalability and compatibility, and performs a cleanup operation after reading, restoring all written check bits to their original values and erasing the data area of the extended sector, leaving no cache traces and not affecting the normal operation of the file system and subsequent data storage. Attached Figure Description
[0016] Figure 1 This is a flowchart of the method of the present invention; Figure 2 This is a system flowchart of the present invention. Detailed Implementation
[0017] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0018] Example 1
[0019] Please see Figure 1 This application provides a method for data caching and breakpoint resumption for IoT devices, including the following steps: when the device is disconnected from the network, scan the last sector of each file in the file system for the remaining free space, record the starting address and available length, and generate a temporary address list; Initialize the write cursor to the starting address of the first free space in the temporary address list, and reserve a check bit in the last byte of each free space; The data packets to be cached are written in segments to the free space pointed to by the current write cursor. When a sector is full and there is still data to be written, a jump flag is written to the parity bit of the current sector and the write cursor is moved to the next free space. When a data packet is written, the parity bit of the sector where the last byte is located is written with the parity flag of the data packet length and a separator is written at the end of the data packet. After the network is restored, each sector is read sequentially starting from the first free space in the temporary address list. The data packets are reassembled according to the jump flag, parity flag and delimiter in the check bit. Finally, all write traces are cleaned up and the data packets are uploaded to the cloud.
[0020] Example 2
[0021] Furthermore, based on Embodiment 1, the method for data caching and breakpoint resumption in IoT devices is described in more detail, specifically including the following steps: Step 1: 1.1 After detecting a network disconnection, the IoT device immediately calls the underlying storage driver interface to read the physical sector size parameter S (in bytes, with values of 512, 2048, or 4096) of the local non-volatile storage medium (such as NAND Flash, eMMC, or SD card), where the physical sector is the smallest addressable read / write unit. 1.2 Further read the cluster size parameter C (in bytes) of the file system, and obtain the starting address of the file system allocation table and the structure of each file record. The cluster is the basic logical unit for the file system to manage storage space, which consists of a set of contiguous physical sectors. 1.3 Traverse all existing files in the file system (such as regular files, directory entry files, etc.). For each file, perform the following operations: Read the length field L of the file (in bytes); Calculate the number of unused bytes in the last sector of the file: free = S - (L / S), if L / S = 0, then free = 0; If free>0, then based on the first cluster number and cluster size C of the file, and the offset within the cluster, locate the last sector to obtain the physical address addr of the last sector of the file; Record the starting physical position of the tail free space: Start = addr + L / S, and the available length: free; 1.4 Store all tail space record entries (Start, free) that satisfy free>0 in ascending order of Start into a temporary address list P. This array is only stored in the device's runtime memory and is not written to non-volatile storage.
[0022] Step 2: 2.1 Take the first record item P[0] from P. Set the initial value of the current write cursor Cur to P[0].Start, which is in bytes and represents the physical address that can be written. At the same time, set the initial value of the current remaining available length Rem to P[0].free, which is in bytes and represents the number of bytes that are not yet used in the tail space. 2.2 Allocate a 4-byte next address variable in the memory during device runtime, with an initial value of 0. This variable is used to record the physical address of the next tail free space during recursive extension. For each free space at the end of P, its last byte, i.e., the position offset by free-1 from the starting address of that space, is regarded as the check bit area. In subsequent write operations, this check bit will be written with one of the following values: 0x5A, 0xA5, 0x01, or 0x00, which are used to indicate: there is a subsequent sector after the current sector is full (called the jump mark), the current sector is the last sector of the write chain (called the end mark), the current sector contains a complete data packet ending and the data packet length is odd, and the current sector contains a complete data packet ending and the data packet length is even. 2.4 Read the original values of the current test region of each tail space and temporarily store the original values in the runtime memory array O1d[] in the order of P.
[0023] Step 3: 3.1 Obtain the first data packet to be cached, and denote its total byte content as D1 and the total length of D1 as L1. Extract the data sequentially from the first byte of D1. Scan all bytes of the data packet. If the value 0x1F is found, replace the byte with two consecutive bytes 0x1F, and increase the data packet length L1 accordingly (L1 increases by 1 for each 0x1F replacement). Repeat this process until there are no more individual 0x1F bytes in the entire data packet. 3.2 Repeat the following write operation until all bytes of D1 have been written: 3.21 Compare the number of bytes that D1 has not yet been written with the remaining available length Rem of the current tail free space, and take the smaller value as the number of bytes W that can be written this time; 3.22 Starting from the first byte that has not yet been written to D1, W bytes are continuously retrieved and written to a contiguous storage area starting at the current write cursor Cur using the underlying physical address write function. During the write operation, the file system is bypassed and the physical address is directly manipulated. 3.23 Synchronous Update: Increase the number of bytes written in D1 by W, move the current write cursor Cur backward by W bytes, and decrease the current remaining available length Rem by W; 3.24 If the number of bytes not yet written to D1 is greater than 0 and the current remaining available length Rem is equal to 0, meaning the current sector is full, then perform the following operation: Write the value 0x5A at the physical address of the last byte in the current sector, i.e., Cur-1; Update the value of the next address variable to the starting address of the next tail free space in P, P[next].Start. If the current address is the last element of P, then treat the next address variable as 0xFFFF. Treat the current write cursor Cur as the value of the next address variable (if the next address variable is 0xFFFF, skip to step 4), and set the current remaining available length Rem to the free value of the corresponding tail space; Continue with step 3.21; 3.3 Once all bytes in D1 have been written, meaning there are no more unwritten bytes in D1, perform the following operations: 3.31 Calculate the physical address ChkAddr of the last byte in the sector where the last byte of D1 is located. The calculation method is to add S-1 to the starting address of the last sector used in this write operation. 3.32 Calculate the remainder Par when L1 is divided by 2. If Par equals 1, write the value 0x01 at ChkAddr. If Par equals 0, write the value 0x00 at ChkAddr. 3.33 After the last byte of D1, a fixed delimiter value of 0x1F is written. If there is insufficient space remaining in the current sector during writing, the next sector is written according to step 3.24. 3.4 Repeat steps 3.1 to 3.3 to process the next data packet to be cached until all data packets to be cached have been written. 3.5 After all data packets have been written, write the value 0xA5 to the last byte of the last used sector. If 0x01 or 0x00 has already been written to this position, write 0xA5 to the next free byte adjacent to this sector. If there are no free bytes in this sector, write 0xA5 to the first byte of the next sector.
[0024] Step 4: 4.1 When the next address variable in step 3.24 is 0xFFFF and there are still unwritten cached data packets, a recursive extension operation is triggered to find new available storage space; 4.2 Read the file allocation table of the file system, scan the entire storage medium, traverse the status of each cluster, and obtain a cluster marked as free, that is, a cluster not used by any file; 4.3 Obtain the physical address of the first sector of this free cluster, denoted as ExtA; 4.4 Treat this sector as a new writable space with a usable length equal to the entire sector size S, in bytes. The last byte of this sector, i.e., the physical address ExtA+S-1, is used as a check area for subsequent writing of jump flags, end flags, or parity flags. 4.5 Set the current cursor Cur to the starting address ExtA of the sector, set the remaining available length Rem to S, and record the starting address of the sector in the extended address list Extl in runtime memory for subsequent cleanup; 4.6 Return to step 3.21 and continue writing the remaining cached data packets. Each time the current sector is full and there is still data to be written, repeat steps 4.2 to 4.5 to obtain the next unallocated cluster in turn until all cached data packets are written. During the entire recursive extension process, the file system allocation table is not modified. That is, these unallocated clusters remain in an idle state from the perspective of the file system. Their physical content is temporarily covered by cached data. After the network is restored and the data is read, the content of these clusters is erased.
[0025] Step 5: 5.1 After the network connection is restored, start reading from the first record item P[0].Start in P, set the initial value of the current reading cursor RC to P[0].Start, set the initial value of the remaining readable length Rm of the current sector to P[0].free, and clear a temporary storage area Buf at the same time; 5.2 Repeat the following steps until you encounter the value 0xA5: 5.21 Starting from the current read cursor RC, read byte by byte until the last byte of the current sector is read, i.e., the position of the sector start address plus S-1 or Rm is exhausted. Then, append the read valid data bytes (excluding the last byte of the sector) to the end of Buf in sequence. 5.22 Read the value of the last byte of the current sector and determine its value: If the value is equal to 0x5A, it means that there is another sector after this sector. Then, according to the writing order, retrieve the starting address of the next tail free space from the temporary address list P. If P has been retrieved, retrieve the starting address of the next extended sector from the extended address list Extl, update the current read cursor RC to this address, update the remaining scale length Rm of the current sector to the available length of the space (take the corresponding free value for the space in P, and take the S value for the space in Extl), and continue to execute step 5.21. If the value is equal to 0x01 or 0x00, it means that the current sector contains the end of a complete data packet. Then, look up the value 0x1F in the Buf. When looking up the delimiter 0x1F in the Buf buffer, perform the following restoration: if the current byte is 0x1F and the next byte is also 0x1F, then treat these two bytes as an escape sequence, output a 0x1F as normal data, and skip the next byte (i.e., move the pointer two positions forward) and continue scanning. If the current byte is 0x1F and the next byte is not 0x1F (or there is no next byte), then 0x1F is regarded as the end of the data packet, the bytes before it are extracted as a complete data packet, and the extracted byte and 0x1F are removed from Buf. At the same time, the remainder of the extracted data packet length divided by 2 is calculated. If it does not match the value of the last byte of the current sector (0x01 represents odd number, 0x00 represents even number), then the data packet is marked as corrupt, and step 5.21 is continued. If the value is equal to 0xA5, stop reading and exit the loop; 5.3 After the reading loop ends, all remaining bytes in Buf are split into segments with the value 0x1F to obtain the last batch of data packets. All recovered data packets are stored in the queue to be uploaded in the order they were retrieved. 5.4 Clean up write traces: 5.41 For each free space at the end of P, restore the content of its last byte (i.e., the parity bit area) to the original value temporarily stored in the array Old[] in step 2.4; 5.42 Traverse each extended sector in Extl, write the content of its last byte to the value 0xFF, and write the last byte and the remaining data area (from the start address of the sector to the second to last byte) to the value 0xFF to erase the temporary cached data; 5.43 Clear temporary variables such as P, Extl, Buf, next address variable, current write cursor Cur, and current read cursor RC in runtime memory; 5.5 Upload the data packets in the queue to the cloud server sequentially through the newly established network connection according to the original writing order, thus completing the interrupted resume upload.
[0026] Example 3
[0027] Please see Figure 2 This application provides an IoT device data caching and breakpoint resume system, and the method applied to any of the above includes: The scan initialization module is used to scan the free space at the end of each file when the device is disconnected from the network, record the starting address and available length and generate a temporary address list, initialize the cursor to point to the starting address of the first free space in the list, and reserve the last byte of each free space as a check bit; The cache writing module is used to write the data packets to be cached into segments into the free space pointed to by the current write cursor. When the sector is full and the data is not finished writing, a jump flag is written in the parity bit and the cursor is moved to the next free space. When the data packet is finished writing, a length parity flag is written in the parity bit and a separator is written at the end of the packet. The recursive extension module is used to read the allocation bitmap to obtain a free cluster when there is no next free space in the list and there is still data, and to continue caching its sectors as new write space without modifying the allocation state. The read and reassemble module is used to read each sector sequentially from the first free space in the list after network recovery, and reassemble the data packets according to the jump flag, parity flag and delimiter in the check bit. The cleanup upload module is used to clean up write traces and upload the reconstructed data packets to the cloud in sequence.
[0028] Some of the data in the above formulas are numerical calculations with dimensions removed, and the contents not described in detail in this specification are all prior art known to those skilled in the art.
[0029] The above embodiments are only used to illustrate the technical methods of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical methods of the present invention without departing from the spirit and scope of the technical methods of the present invention.
Claims
1. A method for data caching and breakpoint resumption in Internet of Things (IoT) devices, characterized in that, Includes the following steps: When the device is disconnected from the network, scan the last sector of each file in the file system for the remaining free space, record the starting address and available length, and generate a temporary address list. Initialize the write cursor to the starting address of the first free space in the temporary address list, and reserve a check bit in the last byte of each free space; The data packets to be cached are written in segments to the free space pointed to by the current write cursor. When a sector is full and there is still data to be written, a jump flag is written to the parity bit of the current sector and the write cursor is moved to the next free space. When a data packet is written, the parity bit of the sector where the last byte is located is written with the parity flag of the data packet length and a separator is written at the end of the data packet. After the network is restored, each sector is read sequentially starting from the first free space in the temporary address list. The data packets are reassembled according to the jump flag, parity flag and delimiter in the check bit. Finally, all write traces are cleaned up and the data packets are uploaded to the cloud.
2. The method for data caching and breakpoint resumption in IoT devices according to claim 1, characterized in that, The specific free space at the end of the last sector of each file in the scanned file system is: Read the length field L and physical sector size S of each file, and calculate the number of bytes free to use; The specific calculation formula is: free = SL / S; When L / S=0, free=0; The specific formula for calculating the starting address Start is: Start = addr + L / S, where addr is the physical address of the last sector of the file.
3. The method for data caching and breakpoint resumption in IoT devices according to claim 1, characterized in that, The jump marker is the value 0x5A; In the parity marker, odd numbers are marked with the value 0x01 and even numbers are marked with the value 0x00; The check bit is also used to write an end marker, which is the value 0xA5.
4. The method for data caching and breakpoint resumption in IoT devices according to claim 1, characterized in that, When the data packet to be cached is written in segments to the free space pointed to by the current write cursor, if the remaining available length of the current tail free space is greater than or equal to the number of remaining bytes of the data packet, then the write is completed in one go. Otherwise, take the remaining available length as the write length for this time. After the current sector is filled, write a jump flag in the current sector's check bit, update the write cursor to the starting address of the next free space in the temporary address list, and update the remaining available length to the available length of the corresponding space. Repeat until all data packets are written.
5. The method for data caching and breakpoint resumption in IoT devices according to claim 1, characterized in that, The specific method for writing the parity marker into the length of the data packet is as follows: After a data packet is written, calculate the remainder when the length of the data packet is divided by 2. If the remainder is 1, write 0x01 to the check bit of the sector where the last byte of the data packet is located; otherwise, write 0x00. The delimiter 0x1F is written immediately after the last byte of the data packet. If there is insufficient space remaining, subsequent sectors are written according to the jump rules.
6. The method for data caching and breakpoint resumption in IoT devices according to claim 5, characterized in that, The specific redirection rules are as follows: When all the trailing free space in the temporary address list is full and there are still packets to be cached, perform recursive extension: Read the file allocation list of the file system, obtain an unallocated cluster marked as free, extract the physical location of the first sector of the cluster, use this sector as a new writable space with an available length equal to the size of the entire sector in bytes, and use the last byte as a check bit; The cursor will be written to the starting address of the sector, and the address of the extended sector will be recorded in the center of memory; Return to the packet writing step to continue caching, repeating this process until all packets are cached, without modifying the file allocation list of the file system; The physical sector is the smallest addressable read / write unit, and a cluster consists of a group of consecutive physical sectors.
7. The method for data caching and breakpoint resumption in IoT devices according to claim 1, characterized in that, After the network is restored: Get a temporary buffer Buf; Starting from the first free space address in the temporary address list, read and append the valid data bytes of the current sector to the end of the temporary buffer Buf; Read the current sector check bit. If it is the jump flag 0x5A, jump to the next free space or extended sector in sequence and continue reading. If the odd number is 0x01 or the even number is 0x00, the delimiter is searched in the temporary buffer Buf. The bytes before the delimiter are extracted as a data packet and the parity of the length is verified. If the end mark is found, reading is stopped. Finally, the remaining bytes in the temporary buffer Buf are separated according to the delimiter to obtain the complete data packet.
8. The method for data caching and breakpoint resumption in IoT devices according to claim 1, characterized in that, The process of cleaning up all write traces includes: For each free space at the end of the temporary address list, restore its checksum to the original value that the device read and temporarily stored before caching; For each extended sector used in the recursive extension process, write its check bit to 0xFF, and write all the remaining data areas of that sector to 0xFF; Clear the temporary address list and extended address list in runtime memory, and write and read the temporary buffer Buf to and from the cursor.
9. The method for data caching and breakpoint resumption in IoT devices according to claim 1, characterized in that, The delimiter is a fixed value of 0x1F, which is written immediately after the last byte of each data packet and is not included in the data packet length. During reading, each unique 0x1F indicates the end of the current data packet, and this delimiter is not included in the recovered data packet. If the original content of the data packet to be cached contains the value 0x1F, then an escaping process is performed before caching: each 0x1F in the original data is replaced with two consecutive bytes 0x1F, 0x1F; After reading and reassembling, two consecutive 0x1Fs are restored to a single 0x1F, which is treated as ordinary data rather than a delimiter.
10. An IoT device data caching and breakpoint resume system, used to execute the method of any one of claims 1 to 9, characterized in that, include: The scan initialization module is used to scan the free space at the end of each file when the device is disconnected from the network, record the starting address and available length and generate a temporary address list, initialize the cursor to point to the starting address of the first free space in the list, and reserve the last byte of each free space as a check bit; The cache writing module is used to write the data packets to be cached into segments into the free space pointed to by the current write cursor. When the sector is full and the data is not finished writing, a jump flag is written in the parity bit and the cursor is moved to the next free space. When the data packet is finished writing, a length parity flag is written in the parity bit and a separator is written at the end of the packet. The recursive extension module is used to read the allocation bitmap to obtain a free cluster when there is no next free space in the list and there is still data, and to continue caching its sectors as new write space without modifying the allocation state. The read and reassemble module is used to read each sector sequentially from the first free space in the list after network recovery, and reassemble the data packets according to the jump flag, parity flag and delimiter in the check bit. The cleanup upload module is used to clean up write traces and upload the reconstructed data packets to the cloud in sequence.