A device shadow management method and a device monitoring method using the same
By realizing two-way synchronization of device shadows in the Internet of Things platform, the synchronization efficiency and performance problems of device shadows between cache middleware and database are solved, efficient reading and writing and data persistence are achieved, and real-time and high availability of device monitoring are improved.
Patent Information
- Application Number
- CN202210038631.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-13
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2042-01-13
AI Technical Summary
The persistence and reliability of device shadows in IoT platforms, especially in terms of synchronization efficiency and performance between cache middleware and databases.
By realizing two-way synchronization of device shadows in the Internet of Things platform, efficient reading and writing are used for cache middleware, and timed synchronization is performed in the database, ensuring data persistence and reliability.
Improves the read speed of device shadows and the persistence and reliability of data storage, reduces database pressure, and improves the real-time and high availability of device monitoring.
Smart Images

Figure CN114490759B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of Internet of Things, and more specifically, to a method for managing device shadows and a method for using the same to monitor devices. Background Art
[0002] Device shadow is an important component in the IoT platform. It is a JSON document that stores the latest attribute status reported and sent by the device. It is a buffer between users and devices, avoiding the pressure caused by users directly requesting devices and avoiding the problem that the device cannot receive data when it is not online. At present, the definition and implementation of device shadow in various IoT platforms are quite different. Most of the implementation mechanisms are simple uplink and downlink data caches, and the functions of device shadow are not deeply explored. Given the importance of device shadow in the IoT platform, device shadow needs to be persisted so that the device shadow can maintain its original state after system restart or data migration. Device shadow is usually maintained in cache middleware or database. When maintained in cache middleware, the read and write efficiency is high, but the persistence and reliability are low, and data loss is prone to occur. Once a failure occurs, data recovery is difficult. When maintained in the database, the reliability is high and the read and write performance is poor. However, device shadow is read and written very frequently in the IoT platform. The slow read and write speed will cause many functions to respond slowly, resulting in poor user experience.
[0003] On the other hand, since a large number of devices on the IoT platform are low-power, they cannot stay connected to the server for a long time to maintain an online state, and cannot sense whether the device is offline, so device operation status monitoring is also a pain point for the IoT platform. In related technologies, the device operation status is usually refreshed by setting a scheduled task, and the maximum idle time and data reporting time of the device are queried from the database to determine the device operation status. In the case of a large number of devices, this method is inefficient and has poor real-time performance. The operation status of the device in the platform and the actual operation status of the device often have a large deviation. If the device has the ability to send and receive messages, it can also actively send messages to the device to detect the operation status through polling. If the device responds to the message within a limited time, then the device is considered online, but additional message sending and receiving will increase the network load and performance consumption of the device, and this method is inefficient in the case of a large number of devices. Summary of the invention
[0004] Based on the above technical problems, the present invention aims to achieve two-way synchronization between the device shadow cache middleware and the database, improve the data reading speed, and make the data storage persistent and reliable.
[0005] A first aspect of the present invention provides a device shadow management method, which is applied to an Internet of Things platform, and the method includes:
[0006] Query the cache middleware and the device shadow in the database based on the device ID;
[0007] If the query results fed back by the cache middleware and the database are both empty, a new device shadow is created for the queried device and saved to the cache middleware and the database at the same time;
[0008] If one of the query results fed back by the cache middleware and the database is empty, the corresponding device shadow is saved in the cache middleware or database where the query result is empty;
[0009] If the query results fed back by the cache middleware and the database are not empty, compare whether the version numbers of the device shadow in the cache middleware and the device shadow in the database are the same.
[0010] Specifically, if one of the query results fed back by the cache middleware and the database is empty, then the corresponding device shadow is saved in the cache middleware or database whose query result is empty, including:
[0011] If the query result of the cache middleware is empty and the query result of the database is not empty, the device shadow of the device in the database is saved to the cache middleware;
[0012] If the query result of the database is empty and the query result of the cache middleware is not empty, the device shadow of the device in the cache middleware is saved in the database.
[0013] Furthermore, if the query results fed back by the cache middleware and the database are not empty, comparing whether the version numbers of the device shadow in the cache middleware and the device shadow in the database are the same includes:
[0014] If the device shadow in the cache middleware has the same version number as the device shadow in the database, determine whether the device attributes have changed;
[0015] If the device shadow version numbers in the cache middleware and the device shadow version numbers in the database are different, compare the device shadow version numbers.
[0016] Specifically, the determining whether the device attribute has been changed includes: if the device attribute has been changed, saving the changed content to the cache middleware; if not, neither the cache middleware nor the database is updated.
[0017] Furthermore, if the version numbers of the device shadow in the cache middleware and the device shadow in the database are different, comparing the device shadow version numbers includes:
[0018] If the device shadow version number in the database is greater than the device shadow version number in the cache middleware, determine whether the device attributes have changed. If so, save the changed content to the cache middleware;
[0019] If the device shadow version number in the database is smaller than the device shadow version number in the cache middleware, the device shadow version number in the cache middleware is updated to the database.
[0020] A second aspect of the present invention provides a method for device monitoring using the device shadow management method described in each embodiment of the present invention, wherein when a device is created or activated, a device shadow of the device is created and stored in a cache middleware and a database at the same time, wherein the device shadow includes a device ID, a maximum idle time of the device, a device operating status, and a device shadow version number, and the device shadows of all devices constitute a device shadow set;
[0021] When the device reports data to the device gateway, the device shadow of the device is queried based on the device ID. If the device running status changes, the device shadow version number is increased by one and the corresponding device shadow is saved to the cache middleware;
[0022] Use the message middleware to broadcast the queried device operation status to each service node in the IoT platform;
[0023] The last idle time of the device is calculated based on the current time and the maximum idle time of the device, and the last idle time of the device is used as the sorting weight of each device ID in the device shadow set.
[0024] Further preferably, after taking the last idle time of the device as the sorting weight of each device ID in the device shadow set, the method further includes:
[0025] The last idle time of the device is used as the sorting weight of each device ID in the device shadow set to sort the set as the offline notification task set, where the offline notification task set is stored in the cache middleware;
[0026] Add the offline notification task set to the time wheel timer, and set the task delay time to the maximum idle time of the device;
[0027] The time wheel timer triggers the offline notification task set, and broadcasts it through the message middleware and stores it through the cache middleware;
[0028] Wherein, before the time wheel timer triggers the offline notification task set and broadcasts it through the message middleware, if a device reports data, the task corresponding to the device is deleted from the offline notification task set.
[0029] Furthermore, the time wheel timer triggers the offline notification task set and stores it through the cache middleware, including: when adding or deleting a task of a certain device ID in the offline notification task set, adding or deleting it synchronously in the offline notification task set of the cache middleware.
[0030] A third aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the following steps:
[0031] Query the cache middleware and the device shadow in the database based on the device ID;
[0032] If the query results fed back by the cache middleware and the database are both empty, a new device shadow is created for the queried device and saved to the cache middleware and the database at the same time;
[0033] If one of the query results fed back by the cache middleware and the database is empty, the corresponding device shadow is saved in the cache middleware or database where the query result is empty;
[0034] If the query results fed back by the cache middleware and the database are not empty, compare whether the version numbers of the device shadow in the cache middleware and the device shadow in the database are the same.
[0035] A fourth aspect of the present invention provides a computer program product, comprising a computer program, which, when executed by a processor, implements the following steps:
[0036] Query the cache middleware and the device shadow in the database based on the device ID;
[0037] If the query results fed back by the cache middleware and the database are both empty, a new device shadow is created for the queried device and saved to the cache middleware and the database at the same time;
[0038] If one of the query results fed back by the cache middleware and the database is empty, the corresponding device shadow is saved in the cache middleware or database where the query result is empty;
[0039] If the query results fed back by the cache middleware and the database are not empty, compare whether the version numbers of the device shadow in the cache middleware and the device shadow in the database are the same.
[0040] The beneficial effects of the present application are as follows: the device shadow management method described in the present application synchronizes the device shadow bidirectionally between the cache middleware and the database, and on the one hand requires that the device shadow reading and writing be performed in the cache middleware, thereby ensuring high performance of reading and writing, and on the other hand requires that the device shadow be synchronized to the database periodically according to the maximum idle time of the device, thereby ensuring both high availability and reliability of the device shadow and high efficiency of bidirectional synchronization; at the same time, the device shadow version number reduces the frequency of synchronization, greatly reducing the database pressure caused by synchronization.
[0041] Furthermore, the application scenarios of the method for device monitoring using the device shadow management method applied in the present application will be wider. On the one hand, a time wheel timer is used to execute offline notification tasks, with low server performance consumption and high real-time performance, and other service nodes can be notified as soon as the device is found to be offline; on the other hand, scheduled tasks at other service nodes obtain tasks from the offline task set for operation status monitoring, avoiding the loss of offline tasks caused by device gateway failure, and ensuring the high availability of operation status monitoring. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The accompanying drawings, which constitute a part of the specification, illustrate embodiments of the present application and, together with the description, serve to explain the principles of the present application.
[0043] The present application can be more clearly understood from the following detailed description with reference to the accompanying drawings, in which:
[0044] Figure 1 A schematic diagram showing the steps of a method for managing device shadows in an exemplary embodiment of the present application is shown;
[0045] Figure 2 A flow chart of a method for managing device shadows in an exemplary embodiment of the present application is shown;
[0046] Figure 3 A process schematic diagram of a method for performing device monitoring by applying a device shadow management method in an exemplary embodiment of the present application is shown;
[0047] Figure 4 A schematic diagram of the structure of a computer device provided by an exemplary embodiment of the present application is shown;
[0048] Figure 5 A schematic diagram of a storage medium provided by an exemplary embodiment of the present application is shown. DETAILED DESCRIPTION
[0049] Hereinafter, embodiments of the present application will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present application. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present application. It is obvious to those skilled in the art that the present application can be implemented without one or more of these details. In other examples, in order to avoid confusion with the present application, some technical features known in the art are not described.
[0050] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should also be understood that when the terms "comprise" and / or "include" are used in this specification, it indicates the presence of the features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0051] Now, exemplary embodiments according to the present application will be described in more detail with reference to the accompanying drawings. However, these exemplary embodiments may be implemented in a variety of different forms and should not be construed as being limited to the embodiments described herein. The accompanying drawings are not drawn to scale, and certain details may be magnified and certain details may be omitted for the purpose of clear expression. The shapes of the various regions and layers shown in the figures and the relative sizes and positional relationships therebetween are merely exemplary, and may deviate in practice due to manufacturing tolerances or technical limitations, and those skilled in the art may additionally design regions / layers with different shapes, sizes, and relative positions according to actual needs.
[0052] The following is attached to the instruction manual Figure 1-5 Several embodiments are given to describe exemplary implementations according to the present application. It should be noted that the following application scenarios are only shown to facilitate understanding of the spirit and principles of the present application, and the implementations of the present application are not limited in this regard. On the contrary, the implementations of the present application can be applied to any applicable scenario.
[0053] Device shadow is an important component in the IoT platform. It is a JSON document that stores the latest attribute status reported and issued by the device. It stores various attributes of the device. Given the importance of device shadow in the IoT platform, device shadow needs to be persisted so that the device shadow can maintain its original state after the system restarts or data migration. Device shadow is usually maintained in cache middleware or database. When maintained in cache middleware, the read and write efficiency is high, but the persistence reliability is low, and data loss is prone to occur. Once a failure occurs, data recovery is difficult. When maintained in the database, the reliability is high and the read and write performance is poor. However, device shadow is read and written very frequently in the IoT platform. The slow read and write speed will cause many functions to respond slowly, resulting in a poor user experience.
[0054] Therefore, in some exemplary embodiments of the present application, a method for managing device shadows is provided, such as Figure 1 As shown, including:
[0055] S1. Query the cache middleware and the device shadow in the database according to the device ID;
[0056] S2. If the query results fed back by the cache middleware and the database are both empty, a new device shadow is created for the queried device and saved to the cache middleware and the database at the same time;
[0057] S3. If one of the query results fed back by the cache middleware and the database is empty, the corresponding device shadow is saved in the cache middleware or database whose query result is empty;
[0058] S4. If the query results fed back by the cache middleware and the database are not empty, compare whether the version numbers of the device shadow in the cache middleware and the device shadow in the database are the same.
[0059] refer to Figure 2 , query the device shadow in the database according to the device ID, which can be referred to as DbShadow, and query the device shadow from the cache middleware according to the device ID, which can be referred to as CacheShadow. Figure 2 As shown, if both DbShadow and CacheShadow are empty, create a new device shadow and save it to the cache middleware and database at the same time; if DbShadow is empty and CacheShadow is not empty, save CacheShadow to the database; if DbShadow is not empty and CacheShadow is empty, save DbShadow to the cache middleware; if both DbShadow and CacheShadow are not empty, compare the version numbers of the two shadows.
[0060] If the version numbers are the same, it is necessary to determine whether the device status has changed. If there is a change, save it to the cache middleware. If there is no change, the cache middleware and the database will not be updated. If the DbShadow version number is greater than the CacheShadow version number, it is necessary to determine whether the status has changed. If there is a change, modify the DbShadow running status and save it to the cache middleware. If the CacheShadow version number is greater than the DbShadow, directly update the CacheShadow to the database. Here, the device shadow stores various attributes of the device, such as device ID, maximum idle time of the device, device running status, device shadow version number, etc. When determining whether the device status has changed, the corresponding device shadow is checked according to the device ID to see whether the stored device attribute values, including but not limited to the device offline or online status attributes, have changed. If changed, the changed content is synchronously stored in the database or cache middleware.
[0061] It can be seen that the device shadow management method described in the present application synchronizes the device shadow bidirectionally between the cache middleware and the database. On the one hand, it requires that the device shadow be read and written in the cache middleware to ensure high performance of reading and writing. On the other hand, it requires that the device shadow be synchronized to the database periodically according to the maximum idle time of the device, which not only ensures the high availability and reliability of the device shadow, but also ensures the high efficiency of bidirectional synchronization. At the same time, the device shadow version number reduces the frequency of synchronization and greatly reduces the database pressure caused by synchronization.
[0062] All device shadow reading and updating in the IoT platform are performed through the cache middleware, but it is necessary to set a scheduled task to synchronize from the cache to the database. The scheduled task time period is set according to the maximum idle time range of the device. The smaller the maximum idle time, the smaller the time period is set. For example, when the maximum idle time is 0 to 30 seconds, the time period is set to 30 seconds, when the maximum idle time is 30 to 60 seconds, the time period is set to 60 seconds, and so on. The execution time of the next task is set after the task is completed.
[0063] Therefore, in some exemplary embodiments of the present application, a method for applying the device shadow management method to perform device monitoring is also provided, such as Figure 3 As shown, it includes: when a device is created or activated, a device shadow of the device is created and stored in the cache middleware and the database at the same time, wherein the device shadow includes the device ID, the maximum idle time of the device, the device operating status and the device shadow version number, and the device shadows of all devices constitute a device shadow set; when the device reports data to the device gateway, the device shadow of the device is queried according to the device ID, if the device operating status changes, the device shadow version number is increased by one and the corresponding device shadow is saved to the cache middleware; the queried device operating status is broadcasted to each service node in the Internet of Things platform by using the message middleware; the last idle time of the device is calculated based on the current time and the maximum idle time of the device, and the last idle time of the device is used as the sorting weight of each device ID in the device shadow set.
[0064] It should be noted here that the Internet of Things is an important part of the new generation of information technology and an important development stage in the "informatization" era. Its English name is: "Internet of things (IoT)". As the name suggests, the Internet of Things is the Internet of things connected to each other. The Internet of Things is widely used in the integration of networks through communication perception technologies such as intelligent perception, recognition technology and ubiquitous computing. Therefore, it is called the third wave of the development of the world's information industry after computers and the Internet. The Internet of Things is an application extension of the Internet. Rather than saying that the Internet of Things is a network, it is better to say that the Internet of Things is business and application. Therefore, application innovation is the core of the development of the Internet of Things, and Innovation 2.0 with user experience as the core is the soul of the development of the Internet of Things. A complete IoT platform requires hardware, such as sensors, devices, time wheel timers, etc. Of course, a complete IoT platform also includes software, such as databases, cache middleware, message middleware, etc.
[0065] In a preferred embodiment, after using the last idle time of the device as the sorting weight of each device ID in the device shadow set, it also includes: using the last idle time of the device as the sorting weight of each device ID in the device shadow set to sort the set as an offline notification task set, wherein the offline notification task set is stored in the cache middleware; adding the offline notification task set to the time wheel timer, and setting the task delay time to the maximum idle time of the device; the time wheel timer triggers the offline notification task set, broadcasts it through the message middleware, and stores it through the cache middleware; wherein, before the time wheel timer triggers the offline notification task set and broadcasts it through the message middleware, if a device reports data, the task corresponding to the device is deleted from the offline notification task set. In another preferred embodiment, the time wheel timer triggers the offline notification task set and stores it through the cache middleware, including: when adding or deleting a task of a certain device ID in the offline notification task set, it is synchronously added or deleted in the offline notification task set of the cache middleware.
[0066] like Figure 3As shown, the device reports data to the device gateway, and the time wheel timer triggers the broadcast or storage of the device status information. The broadcast is through the message middleware in the IoT platform, and the storage is in the cache middleware. If the device reports data again before the device offline notification task is executed, the existing task is canceled and the task is rejoined according to the above steps. If the device does not report data before the task is executed, delete the device ID in the offline task set. If the deletion fails because the device ID does not exist, it is considered that the task has been executed by other service nodes. If the device ID is deleted successfully, the device offline notification task is executed. Query the device shadow according to the device ID. If the device is offline, increase the shadow version number by one, save the device shadow to the cache middleware, and broadcast the device offline event to each service node in the IoT platform.
[0067] The application scenario of the method for device monitoring using the device shadow management method in this application will be wider. On the one hand, a time wheel timer is used to execute offline notification tasks, with low server performance consumption and high real-time performance, and other service nodes can be notified as soon as the device is found to be offline; on the other hand, scheduled tasks at other service nodes obtain tasks from the offline task set for operation status monitoring, avoiding the loss of offline tasks caused by device gateway failure, and ensuring the high availability of operation status monitoring.
[0068] Please refer to the following Figure 4 , which shows a schematic diagram of a computer device provided by some embodiments of the present application. Figure 4 As shown, the computer device 2 includes: a processor 200, a memory 201, a bus 202 and a communication interface 203, and the processor 200, the communication interface 203 and the memory 201 are connected via the bus 202; the memory 201 stores a computer program that can be run on the processor 200, and when the processor 200 runs the computer program, it executes the device shadow management method provided in any of the aforementioned embodiments of the present application, and the computer device can be a computer device with a touch-sensitive display.
[0069] The memory 201 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 203 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.
[0070] The bus 202 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory 201 is used to store programs, and the processor 200 executes the programs after receiving the execution instruction. The device shadow management method disclosed in any implementation of the embodiment of the present application may be applied to the processor 200, or implemented by the processor 200.
[0071] The processor 200 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 200. The above processor 200 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a readily available programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor to be executed, or the hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 201, and the processor 200 reads the information in the memory 201 and completes the steps of the above method in combination with its hardware.
[0072] The computer device provided in the embodiment of the present application and the device shadow management method provided in the embodiment of the present application are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented therein.
[0073] The present application also provides a computer-readable storage medium corresponding to the device shadow management method provided in the above embodiment. Figure 5 , Figure 5 The computer-readable storage medium shown is an optical disc 30 on which a computer program (ie, a program product) is stored. When the computer program is executed by a processor, the device shadow management method provided by any of the aforementioned implementations is executed.
[0074] In addition, examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical or magnetic storage media, which are not listed here one by one.
[0075] The computer-readable storage medium provided in the above-mentioned embodiments of the present application and the method for allocating channels for quantum key distribution in a space-division multiplexed optical network provided in the embodiments of the present application are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by the application programs stored therein.
[0076] An embodiment of the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the device shadow management method provided in any of the aforementioned embodiments, the steps of the method including: querying the device shadow in the cache middleware and the database according to the device ID; if the query results fed back by the cache middleware and the database are both empty, creating a new device shadow for the queried device and saving it to the cache middleware and the database at the same time; if one of the query results fed back by the cache middleware and the database is empty, saving the corresponding device shadow in the cache middleware or the database whose query result is empty; if the query results fed back by the cache middleware and the database are not empty, comparing whether the version numbers of the device shadow in the cache middleware and the device shadow in the database are the same.
[0077] It should be noted that the algorithms and displays provided herein are not inherently related to any particular computer, virtual device or other device. Various general devices can also be used together with the teachings based thereon. According to the above description, it is obvious that the structure required for constructing such devices is constructed. In addition, the present application is not directed to any specific programming language. It should be understood that the content of the present application described herein can be implemented using various programming languages, and the above description of specific languages is to disclose the best implementation mode of the present application. In the specification provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this specification.
[0078] Similarly, it should be understood that in order to streamline the present application and aid in understanding one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present application, the various features of the present application are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the following intention: the claimed application requires more features than the features explicitly recited in each claim. More specifically, as reflected in the claims below, the inventive aspects lie in less than all the features of the single embodiment disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present application.
[0079] Those skilled in the art will appreciate that the modules in the devices in the embodiments can be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments can be combined into one module or unit or component, and in addition they can be divided into multiple submodules or subunits or subassemblies. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification and all processes or units of any method or device disclosed in this manner can be combined in any combination. Unless otherwise clearly stated, each feature disclosed in this specification can be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0080] The various component embodiments of the present application can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) can be used in practice to implement some or all functions of some or all components in the creation device of the virtual machine according to the embodiment of the present application. The present application can also be implemented as a device or device program for executing part or all of the methods described herein. The program implementing the present application can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0081] The above is only a preferred specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A device shadow management method, characterized in that: Applied to the Internet of Things platform, the method includes: Query the cache middleware and the device shadow in the database based on the device ID; If the query results fed back by the cache middleware and the database are both empty, a new device shadow is created for the queried device and saved to the cache middleware and the database at the same time; If one of the query results fed back by the cache middleware and the database is empty, the corresponding device shadow is saved in the cache middleware or database where the query result is empty; If the query results fed back by the cache middleware and the database are not empty, compare whether the version numbers of the device shadow in the cache middleware and the device shadow in the database are the same; If one of the query results fed back by the cache middleware and the database is empty, the corresponding device shadow is saved in the cache middleware or database whose query result is empty, including: If the query result of the cache middleware is empty and the query result of the database is not empty, the device shadow of the device in the database is saved to the cache middleware; If the query result of the database is empty and the query result of the cache middleware is not empty, the device shadow of the device in the cache middleware is saved in the database.
2. The device shadow management method according to claim 1, characterized in that: If the query results fed back by the cache middleware and the database are not empty, comparing whether the version numbers of the device shadow in the cache middleware and the device shadow in the database are the same, including: If the device shadow in the cache middleware has the same version number as the device shadow in the database, determine whether the device attributes have changed; If the device shadow version numbers in the cache middleware and the device shadow version numbers in the database are different, compare the device shadow version numbers.
3. The device shadow management method according to claim 2, characterized in that: The determining whether the device attribute has been changed includes: if the device attribute has been changed, saving the changed content to the cache middleware; if there has been no change, neither the cache middleware nor the database is updated.
4. The device shadow management method according to claim 2, characterized in that: If the device shadow in the cache middleware and the device shadow in the database have different version numbers, then comparing the device shadow version numbers, including: If the device shadow version number in the database is greater than the device shadow version number in the cache middleware, determine whether the device attributes have changed. If so, save the changed content to the cache middleware; If the device shadow version number in the database is smaller than the device shadow version number in the cache middleware, the device shadow version number in the cache middleware is updated to the database.
5. A method for monitoring equipment using any of the methods described in claims 1 to 4, characterized in that: The method comprises: When a device is created or activated, a device shadow of the device is created and stored in the cache middleware and the database at the same time, wherein the device shadow includes a device ID, a maximum idle time of the device, a device operating status, and a device shadow version number, and the device shadows of all devices constitute a device shadow set; When the device reports data to the device gateway, the device shadow of the device is queried based on the device ID. If the device running status changes, the device shadow version number is increased by one and the corresponding device shadow is saved to the cache middleware; Use the message middleware to broadcast the queried device operation status to each service node in the IoT platform; The last idle time of the device is calculated based on the current time and the maximum idle time of the device, and the last idle time of the device is used as the sorting weight of each device ID in the device shadow set.
6. The method for monitoring equipment according to claim 5, characterized in that: After taking the last idle time of the device as the sorting weight of each device ID in the device shadow set, the method further includes: The last idle time of the device is used as the sorting weight of each device ID in the device shadow set to sort the set as the offline notification task set, where the offline notification task set is stored in the cache middleware; Add the offline notification task set to the time wheel timer, and set the task delay time to the maximum idle time of the device; The time wheel timer triggers the offline notification task set, and broadcasts it through the message middleware and stores it through the cache middleware; Wherein, before the time wheel timer triggers the offline notification task set and broadcasts it through the message middleware, if a device reports data, the task corresponding to the device is deleted from the offline notification task set.
7. The method for monitoring equipment according to claim 6, characterized in that: The time wheel timer triggers the offline notification task set and stores it through the cache middleware, including: when adding or deleting a task with a certain device ID in the offline notification task set, adding or deleting it synchronously in the offline notification task set of the cache middleware.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Data access method and equipment
CN105095313A
System deployed in multiple computer rooms and cross-computer-room business data processing method
CN105205182A
Method and system for managing equipment operation state based on Internet of Things platform
CN111010429A