Query method, device, computer equipment and storage medium for Internet of Things devices
By mapping the properties of IoT devices to fixed fields and building query indexes, the problem of inefficient query of IoT devices is solved, efficient query and data aggregation is achieved, and operation and maintenance costs are reduced.
Patent Information
- Application Number
- CN202210579956.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-25
- Publication Date
- 2025-09-02
- Estimated Expiration
- 2042-05-25
AI Technical Summary
In the field of the Internet of Things, it is difficult for the prior art to effectively manage and query a large number of attribute information of different IoT devices, resulting in low query efficiency and high operation and maintenance costs.
The properties of IoT devices are mapped into fixed fields through device model-based mode (SCHEMA), and a query index is built for fixed fields, and a general query index is established to assist in retrieving the set, where information corresponding to IoT devices of different device models is stored.
It realizes the establishment of a common query index for IoT devices of different device models in one set, improves query efficiency, reduces operation and maintenance costs, and supports rapid aggregation of device data.
Smart Images

Figure CN114896252B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of Internet of Things, and in particular to a method, apparatus, computer equipment, and storage medium for querying Internet of Things devices. Background Art
[0002] The Internet of Things (IoT) involves a wide variety of devices. Not only is the number of devices enormous, but the properties of these devices vary significantly. Even attributes with the same name may have different data types. Furthermore, the number of attributes they contain also varies significantly.
[0003] Therefore, there is an urgent need to provide a solution on how to store the information of IoT devices to facilitate subsequent query of IoT devices based on attributes. Summary of the Invention
[0004] The present application provides a method, apparatus, computer device, and storage medium for querying IoT devices. The technical solution is as follows:
[0005] According to one aspect of the present application, a method for querying an Internet of Things device is provided, the method comprising:
[0006] Mapping the attributes of the IoT device to fixed fields based on a schema of a device model of the IoT device, wherein the schema is a structure for describing the name and data type of the attributes of the IoT device, and the fixed field includes a plurality of subfields;
[0007] A query index is constructed for the fixed field, where the query index is used to assist in retrieving a collection storing information of IoT devices corresponding to different device models.
[0008] According to one aspect of the present application, a query device for an Internet of Things device is provided, the device comprising: an attribute mapping module and an index building module;
[0009] The attribute mapping module is configured to map the attributes of the IoT device to fixed fields based on a schema of a device model of the IoT device, wherein the schema is a structure for describing the name and data type of the attributes of the IoT device, and the fixed field includes a plurality of subfields;
[0010] The index building module is used to build a query index for the fixed field, and the query index is used to assist in retrieving a collection, in which information of IoT devices corresponding to different device models is stored.
[0011] According to another aspect of the present application, a computer device is provided, comprising: a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set, or an instruction set, and the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by the processor to implement the query method for an Internet of Things device as described above.
[0012] According to another aspect of the present application, a computer-readable storage medium is provided, wherein the storage medium stores at least one instruction, at least one program, a code set, or an instruction set, and the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement the query method for an Internet of Things device as described above.
[0013] According to another aspect of the present application, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method for querying an IoT device as described above.
[0014] The beneficial effects brought about by the technical solutions provided in the embodiments of the present application include at least the following beneficial effects:
[0015] By presetting a fixed field, the attributes of IoT devices of different device models are mapped to the same fixed field. The fixed field is used to build a query index, which is used to assist in retrieving a collection that stores information corresponding to IoT devices of different device models, thereby helping to establish a common query index for IoT devices of different device models within a collection. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0017] Figure 1 This is a schematic diagram of establishing a collection according to a device model provided by an exemplary embodiment of the present application;
[0018] Figure 2 is a schematic diagram of a collection including different device models provided by an exemplary embodiment of the present application;
[0019] Figure 3 is a schematic diagram of a computer system provided by an exemplary embodiment of the present application;
[0020] Figure 4 This is a flowchart of a method for querying an IoT device provided by an exemplary embodiment of the present application;
[0021] Figure 5 This is a flowchart of a method for querying an IoT device provided by an exemplary embodiment of the present application;
[0022] Figure 6 It is a schematic diagram of a query method for an Internet of Things device provided by an exemplary embodiment of the present application;
[0023] Figure 7 This is a block diagram of a query device for an Internet of Things device provided by an exemplary embodiment of the present application;
[0024] Figure 8 It is a structural diagram of a computer device provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0025] In order to make the objectives, technical solutions and advantages of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.
[0026] First, a brief introduction to the terms involved in this application:
[0027] SCHEMA: A structure that describes the names and data types of the properties of an IoT device.
[0028] It is understandable that SCHEMA involves the description form (name and data type) of the attributes of IoT devices, not the specific values of the attributes.
[0029] For example, create the following SCHEMA:
[0030]
[0031] In this SCHEMA, the attribute "color" is described, and its data type is "string"; the attribute "country" is described, and its data type is "string".
[0032] A collection is a physical collection that stores device information for IoT devices. A collection can be thought of as a data table.
[0033] The IoT landscape involves a wide variety of devices. Not only is the number of these devices enormous, but the attributes of these devices can vary significantly. Even attributes with the same name can have different data types. For example, for location, some devices use a time zone, while others use a composite structure combining longitude and latitude. Furthermore, the number of attributes varies significantly between different IoT devices. Therefore, traditional relational databases (such as MySQL) cannot store the attributes of different devices in the same table, separated by columns. Therefore, in practice, documents are often used to store the attributes of IoT devices, or even their complete information.
[0034] While using documents solves the problem of storing IoT device attributes, querying IoT devices based on their attributes requires a full table scan of all IoT devices, or a scan of all IoT devices of a specified type. Because it's impossible to predict the attribute names and types of newly stored IoT devices, it's impossible to accelerate attribute-based queries by creating indexes. When a large number of IoT devices are stored in a system, a full table scan of all IoT devices takes a long time and significantly impacts the system, resulting in significant disk input / output (I / O) and CPU usage.
[0035] In the IoT field, device models are typically created to describe information about IoT devices of the same type. One approach is to create a separate collection for each device model to store related IoT devices. This ensures that the attributes of IoT devices in the same collection have the same name and data type. Therefore, we can create a unique attribute index for each collection related to each device model to accelerate device queries. When the user specifies the device model and attributes, this approach can efficiently return IoT devices that meet the query criteria.
[0036] The practice of dividing collections by device model to store IoT devices has significant drawbacks. Because the number of device models often reaches into the thousands, this requires creating an equal number of collections, leading to significant operational costs. More importantly, this approach hinders aggregation of device data. For example, the IoT devices of the same user may be stored in multiple collections. By dividing collections by model, it's impossible to quickly determine the total number of devices belonging to a given user.
[0037] To efficiently query devices based on their attributes, indexing is necessary. To achieve good device data aggregation, the number of collections storing devices must be limited. However, given the diverse attributes of different IoT devices, there is currently no effective way to achieve both.
[0038] For example, Figure 1 The diagram shows how to create a collection based on device models. The diagram includes two collections, one corresponding to the device model of type model01 and the other corresponding to the device model of type model02.
[0039] Because devices under the same device model share the same attributes (including name and data type), they can be indexed within the same collection. For example, for a device collection of type model01, indexes are included for color, weight, and location; and for a device collection of type model01, indexes are included for color and country. This approach efficiently returns results for the following query: query:modelId='mode01'and color=4.
[0040] However, the large number of device models in the system requires the creation of numerous collections. IoT systems often have thousands of models. This hinders data maintenance (such as backup and migration). More importantly, it complicates data aggregation operations. For example, obtaining the total number of all devices belonging to a specific user requires merging the results of all collections.
[0041] For example, Figure 2 A diagram showing a collection including different device models is shown. The diagram includes a collection where IoT devices in the collection can have different device models.
[0042] Figure 2 The following example lists two device instances with different device models. Although both device models have a color attribute defined in their schemas, their data types are different (the color attribute in model01 is an int, while the color attribute in model02 is a string). Furthermore, the number and names of the attributes in the two model schemas differ.
[0043] In the IoT system, users can customize the SCHEMA of the device model. This makes it difficult to establish an effective index for the properties of IoT devices when the device information is stored in the same collection in the form of a document.
[0044] As analyzed above, the related technologies cannot provide a better way to query IoT devices.
[0045] The following describes the method for querying IoT devices provided by this application.
[0046] Please refer to Figure 3 , which shows a schematic diagram of a computer system involved in an embodiment of the present application. The computer system may include: a plurality of Internet of Things devices 110 and a server 120.
[0047] The IoT device 110 and the server 120 communicate with each other via a network, which may be a wireless network or a wired network.
[0048] The IoT device 110, also referred to as a smart device or smart hardware, can be a detection device with detection capabilities, such as an environmental monitoring device (e.g., a temperature sensor, a noise sensor, etc.), or a traffic monitoring device (e.g., a camera). It can also be a control device with control capabilities, such as a smart home device such as a smart switch, a smart socket, or a smart curtain, or various industrial control devices with control capabilities. The IoT device 110 in the embodiments of the present application is a general term for devices that can be connected to the IoT via a network or other means.
[0049] The IoT device 110 has corresponding device information, which includes device attributes. The device information can be uploaded to the server 120. The server 120 stores the device information of different IoT devices 110 and supports querying IoT devices.
[0050] Optionally, the server 120 may be a single server, a server cluster consisting of multiple servers, or a cloud server that provides basic cloud services such as cloud computing, cloud storage, big data, and artificial intelligence platforms.
[0051] Below, the query method of the Internet of Things device presented in the embodiment of the present application is further explained.
[0052] Figure 4 A flowchart of a query method for an IoT device provided by an exemplary embodiment of the present application is shown. Figure 3 Taking the server shown in FIG. 1 as an example, the method includes:
[0053] Step 410: Map the attributes of the IoT device to fixed fields based on the schema of the device model of the IoT device.
[0054] In the IoT field, device models are used to describe the information of IoT devices of the same type. For example, IoT devices a and b are both described using device model model01, while IoT devices c and d are both described using device model model02.
[0055] Each device model has a corresponding schema. A schema is a structure that describes the names and data types of the attributes of an IoT device. It is understood that since a schema can include multiple attributes, these attributes are arranged in a certain order within the schema.
[0056] An attribute is a measure that describes a specific dimension of an IoT device. Attributes have corresponding names and data types. The following describes the attributes supported by this application.
[0057] · Attributes are device information attributes.
[0058] Device information attributes are used to describe the IoT device itself. Exemplary device information attributes include size, weight, length, color, and location.
[0059] Attributes are functional attributes.
[0060] Functional attributes describe the functions supported by an IoT device. For example, if the IoT device is a smart air conditioner that supports temperature setting, the corresponding functional attribute is the temperature setting attribute. For example, if the IoT device is a smart fan that supports wind speed adjustment, the corresponding functional attribute is the wind speed adjustment attribute.
[0061] In an embodiment of the present application, for any IoT device in a computer system, a schema of a device model of the IoT device is obtained, and based on the schema, attributes of the IoT device are mapped to fixed fields.
[0062] Among them, fixed fields are fields created for attribute mapping.
[0063] Optionally, the fixed field includes multiple subfields, that is, the fixed field consists of several subfields.
[0064] Optionally, mapping the attributes of the IoT device to a fixed field based on the schema of the IoT device means: writing the value corresponding to the attribute into a subfield in the fixed field based on the order and data type of the attributes indicated by the schema.
[0065] Exemplarily, each subfield in the fixed field corresponds to two dimensions of information: sequence information and data type information, and at least one of the two dimensions of information is different between two different subfields.
[0066] Accordingly, based on the mode of the IoT device, the attributes of the IoT device are mapped to fixed fields, including: querying at least one subfield having corresponding sequence information based on the order of the attributes indicated by the mode of the IoT device, and then querying a unique subfield having corresponding data type information in the at least one subfield based on the data type of the attributes indicated by the mode of the IoT device, and writing the value corresponding to the attribute into the subfield. Alternatively, based on the mode of the IoT device, the attributes of the IoT device are mapped to fixed fields, including: querying at least one subfield having corresponding data type information based on the data type of the attributes indicated by the mode of the IoT device, and then querying a unique subfield having corresponding sequence information in the at least one subfield based on the order of the attributes indicated by the mode of the IoT device, and writing the value corresponding to the attribute into the subfield.
[0067] It is understandable that the names and data types of attributes under different device models are not fixed, so it is difficult to establish a query index for IoT devices under different device models. In the embodiment of the present application, by presetting a fixed field, the attributes of IoT devices of different device models can be mapped to the same fixed field.
[0068] Optionally, before step 410, the following step is also included: establishing a pattern of a device model of the Internet of Things device.
[0069] That is, before storing the information of the IoT device in the collection, a SCHEMA of the device model is established to describe the properties (including name and type) of the IoT device.
[0070] Step 420: Build a query index for the fixed field. The query index is used to assist in querying a collection.
[0071] The collection stores information about IoT devices corresponding to different device models.
[0072] In this embodiment of the present application, information about IoT devices corresponding to different device models is stored in the same collection. For example, the collection includes information about IoT devices 1 and 2 under device model model01, and information about IoT devices 3 and 4 under device model02.
[0073] It's understandable that storing IoT device information corresponding to different device models in the same collection can reduce operational costs and facilitate aggregation operations related to device data. For example, by querying this collection, you can quickly obtain the total number of IoT devices under a specific user.
[0074] Optionally, the information in a collection is stored as documents. Different IoT devices have varying numbers of attributes and varying data types, making it difficult to store information for different IoT devices in a single table using traditional relational databases (such as MySQL). Therefore, using documents in a collection allows for better storage of information for IoT devices corresponding to different device models.
[0075] In an embodiment of the present application, after completing the operation of mapping the attributes of all IoT devices to fixed fields, a query index is constructed for the fixed fields, and the query index is used to assist in querying the set.
[0076] Among them, the query index is a separate, physical storage structure that sorts the values in the collection. It is equivalent to the catalog of a book. According to the catalog of the book, the corresponding data can be quickly found. Similarly, according to the query index, the corresponding data in the collection can be quickly found to improve query efficiency.
[0077] Building a query index for a fixed field means using the fixed field as the index of a collection. After querying a value in the fixed field, you can extract the corresponding data from the collection based on the queried fixed field value.
[0078] To sum up, the query method for IoT devices provided in this embodiment maps the attributes of IoT devices of different device models to the same fixed field by presetting a fixed field. The fixed field is used to construct a query index, and the query index is used to assist in retrieving a collection, which stores information corresponding to IoT devices of different device models, thereby helping to establish a common query index for IoT devices of different device models within a collection.
[0079] In an exemplary embodiment, fixed fields are defined based on the following:
[0080] (1) Get the maximum number of attributes and the maximum number of attribute types supported by a single device model in the collection.
[0081] The maximum number of attributes supported by a single device model refers to the number of attributes with the largest values among all attributes corresponding to all device models; the maximum number of attribute types supported by a single device model refers to the number of data types with the largest values among all attribute data types corresponding to all device models.
[0082] That is, if a collection includes multiple device models, obtain the number of attributes and attribute data types supported by each device model, and then compare them to determine the maximum number of attributes and maximum number of attribute types supported by a single device model. For example, if device model model01 supports 3 attributes and 3 attribute data types, and device model02 supports 2 attributes and 2 attribute data types, then the maximum number of attributes and maximum number of attribute types supported by a single device model is 3.
[0083] For example, the device model model01 supports 4 attributes and 2 attribute data types; the device model model01 supports 3 attributes and 3 attribute data types; then the maximum number of attributes supported by a single device model is 4 and the maximum number of attribute types is 3.
[0084] (2) Determine that the fixed field includes X subfields, where X is equal to the maximum number of attributes multiplied by the maximum number of attribute types; wherein the X subfields are divided into subfield groups having the maximum number of attributes, each subfield group includes subfields having the maximum number of attribute types, and each subfield is used to identify an attribute corresponding to the target data type.
[0085] That is, the fixed field includes subfields equal to the maximum number of attributes multiplied by the maximum number of attribute types, and the fixed field includes subfield groups equal to the maximum number of attributes, each subfield group includes subfields equal to the maximum number of attribute types, and different subfields in a subfield group correspond to different data types.
[0086] Optionally, the data type set of each subfield group is the same, and the data type set refers to a set consisting of data types corresponding to multiple subfields in the subfield group.
[0087] Exemplarily, when the maximum number of attributes supported by a single device model is 3 and the maximum number of attribute types is 3, the fixed field includes 9 subfields. Exemplarily, the first 3 subfields correspond to subfield group 1, and the first subfield in subfield group 1 corresponds to data type 1, the second subfield in subfield group 1 corresponds to data type 2, and the third subfield in subfield group 1 corresponds to data type 3; the middle 3 subfields correspond to subfield group 2, and the first subfield in subfield group 2 corresponds to data type 1, the second subfield in subfield group 2 corresponds to data type 2, and the third subfield in subfield group 2 corresponds to data type 3; the last 3 subfields correspond to subfield group 3, and the first subfield in subfield group 3 corresponds to data type 1, the second subfield in subfield group 31 corresponds to data type 2, and the third subfield in subfield group 3 corresponds to data type 3.
[0088] It can be understood that, in the above example, only in different sub-field groups, each sub-field corresponds in the order of data type 1, data type 2, and data type 3. In specific implementation, the order of the data types corresponding to the sub-fields in the two sub-field groups may be different.
[0089] Based on the above fixed fields, the method of mapping attributes to fixed fields is explained.
[0090] The schema of the device model of an IoT device maps all properties of an IoT device to a set of fixed fields, including:
[0091] (1) According to the order of attributes defined in the schema, determine the target subfield groups to which the attributes are mapped in the corresponding order.
[0092] The target subfield group is a subfield group among the subfield groups with the maximum number of attributes included in the fixed field.
[0093] (2) According to the data type of the attribute defined in the schema, determine the mapping of the attribute to the target subfield.
[0094] The target subfield is a subfield in the subfields with the maximum number of attribute types included in the target subfield group.
[0095] For example, the schema defines attribute a, attribute b, and attribute c in the following order, and the fixed field defines subfield group 1, subfield group 2, and subfield group 3. Then, attribute a is mapped to subfield group 1, attribute b is mapped to subfield group 2, and attribute c is mapped to subfield group 3.
[0096] For example, the first subfield in subfield group 1 corresponds to data type 1, the second subfield in subfield group 1 corresponds to data type 2, the third subfield in subfield group 1 corresponds to data type 3, and attribute a corresponds to data type 1. Therefore, the value of attribute a is mapped to the first subfield in subfield group 1. The mapping method for attributes b and c can be deduced similarly and is not further described.
[0097] In an exemplary embodiment, after completing attribute mapping and establishing a query index for a fixed field, the query index can be retrieved using a device query condition to obtain target IoT devices in the collection that match the device query condition.
[0098] Figure 5 A flowchart of a query method for an IoT device provided by an exemplary embodiment of the present application is shown. Figure 3 Taking the server shown in FIG. 1 as an example, the method includes:
[0099] Step 510: Map the attributes of the IoT device to fixed fields based on the schema of the device model of the IoT device.
[0100] The implementation of this step can refer to the above-mentioned step 410 and will not be repeated here.
[0101] Step 520: Build a query index for the fixed field, and the query index is used to assist in querying the set.
[0102] The implementation of this step can refer to the above-mentioned step 420 and will not be repeated here.
[0103] Step 530: Obtain device query conditions.
[0104] Among them, the device query condition is used to query IoT devices based on target attributes.
[0105] For example, the device query condition carries a target attribute and a target device model identifier, wherein the target attribute is used to identify a specific attribute value, and the target device model identifier is used to identify a device model.
[0106] Step 540: Use the device query condition to retrieve the query index and obtain the target IoT devices in the set that match the device query condition.
[0107] The target IoT device is one or more IoT devices that collect and store information.
[0108] Exemplarily, the query index is first searched according to the device query condition, and then the corresponding target IoT device is extracted from the collection according to the search result.
[0109] Optionally, step 540 is replaced by the following steps:
[0110] (1) Based on the pattern, the target attributes carried in the device query condition are mapped to the target subfield in the fixed field.
[0111] Since a schema is a structure of names and data types used to describe the attributes of an IoT device, when the target attributes are carried in the device query conditions, the target attributes can be mapped to the target subfields in the fixed field based on the order and data types of the target attributes indicated by the schema.
[0112] Optionally, the device query condition carries a target attribute and a target device model identifier; based on the pattern, the target attribute carried in the device query condition is mapped to a target subfield in the fixed field, including:
[0113] The target mode corresponding to the device query condition is obtained, where the target mode is the mode of the device model corresponding to the target device model identifier; based on the target mode, the target attribute carried in the device query condition is mapped to the target subfield in the fixed field.
[0114] That is, the device model of the IoT device to be queried is determined through the target device model identifier, and then the target mode corresponding to the device model is confirmed. According to the order of the target attributes defined in the target mode, it is determined to map the target attributes to the target sub-field group of the corresponding order in the fixed field. Then, according to the data type of the target attribute defined in the target mode, it is determined to map the target attribute to the target sub-field in the target sub-field group.
[0115] (2) Retrieve the query index based on the target subfield to obtain the target IoT devices in the collection that match the device query conditions.
[0116] Exemplarily, the query index corresponding to the target subfield is searched, and then the corresponding target IoT device is extracted from the collection based on the search result.
[0117] Optionally, obtaining the target IoT device in the collection that matches the device query condition includes: returning the target IoT device in the collection that has the same value as the target attribute and whose device model corresponds to the target device model identifier.
[0118] To sum up, the technical solution provided in this embodiment maps the attributes of IoT devices of different device models to the same fixed field by presetting a fixed field. The fixed field is used to construct a query index, and the query index is used to assist in retrieving a collection, which stores information corresponding to IoT devices of different device models, thereby helping to establish a common query index for IoT devices of different device models within a collection.
[0119] After building the query index, you can obtain the device query conditions, retrieve the query index, and perform device query in the collection, thereby achieving fast query of the device.
[0120] Combined with reference Figure 6 , the device information of all IoT devices is stored in the same collection in the form of a document. In this embodiment, two IoT devices are used for illustration. The collection lists two instance device information, each with a different device model: model01 and model02.
[0121] The schema of the model corresponding to this collection is shown in the following table:
[0122]
[0123]
[0124] Step 601: Map attributes to fixed fields based on the model SCHEMA.
[0125] (1) Fixed fields are defined as follows:
[0126] Based on the maximum number of attributes and the maximum number of attribute types supported by a single model, define a set of fixed fields, the number of subfields of which is: maximum number of attributes * maximum number of attribute types.
[0127] For this embodiment, fixed fields may be defined as: 0_int, 0_double, 0_string, 1_int, 1_double, 1_string, 2_int, 2_double, 2_string.
[0128] (2) Map attributes to fixed fields according to the order and type defined in the model schema.
[0129] Device 1: color->0_int, weight->1_double, location->2_string.
[0130] Device 2: color->0_string, country->1_string.
[0131] The fixed fields after mapping are as follows Figure 6 shown.
[0132] Step 602: Create a query index for the fixed field.
[0133] Step 603: Query the device according to the attribute.
[0134] (1) Obtain device query conditions, which carry device model identifiers and attributes.
[0135] (2) Obtain the model SCHEMA corresponding to the device query condition.
[0136] (3) Map the device query conditions according to the model SCHEMA to obtain the mapped subfields.
[0137] (4) According to the mapped subfields, the previously constructed query index is retrieved to obtain the matching target IoT devices.
[0138] The following describes the query method using two examples.
[0139] Example 1:
[0140] (1) Given the following device query conditions: modeId='model01' and color=1.
[0141] (2) Obtain the model SCHEMA corresponding to the device query condition, such as [{"color":"int"},{"weight":"double"},{"location":"string"}].
[0142] (3) Map the device query condition according to the model SCHEMA to obtain the mapped subfield, i.e., color->0_int.
[0143] (4) Based on the mapped subfield 0_int, the query index constructed previously is retrieved, and the return value is 1 for all IoT devices whose modelId in the document is model01.
[0144] Example 2:
[0145] (1) Given the following device query conditions: modeId = 'model02' and color = 'blue'
[0146] (2) Obtain the model SCHEMA corresponding to the device query condition, such as [{"color":"string"},{"country":"string"}].
[0147] (3) Map the device query condition according to the model SCHEMA to obtain the mapped subfield, i.e., color->0_string.
[0148] (4) Based on the mapped subfield 0_string, the query index constructed previously is retrieved, and the returned value is blue and the modelId in the document is model02 for all IoT devices.
[0149] It is understandable that the above method embodiments can be implemented individually or in combination, and the embodiments of the present application are not limited in this regard.
[0150] The following is an embodiment of the device of the present application. For details not described in detail in the embodiment of the device, reference can be made to the corresponding records in the above method embodiment, and no further details will be given herein.
[0151] Figure 7 A schematic diagram of the structure of a query device for an IoT device provided by an exemplary embodiment of the present application is shown. The device can be implemented as all or part of a server through software, hardware, or a combination of both. The device includes: an attribute mapping module 702 and an index building module 704;
[0152] The attribute mapping module 702 is configured to map the attributes of the IoT device to fixed fields based on a schema of a device model of the IoT device, wherein the schema is a structure for describing the name and data type of the attributes of the IoT device, and the fixed field includes multiple subfields;
[0153] The index building module 704 is configured to build a query index for the fixed field, where the query index is used to assist in retrieving a collection storing information of IoT devices corresponding to different device models.
[0154] In an optional embodiment, the fixed fields are defined based on the following method:
[0155] Obtain the maximum number of attributes and the maximum number of attribute types supported by a single device model in the set;
[0156] Determining that the fixed field includes X subfields, where X is equal to the maximum number of attributes multiplied by the maximum number of attribute types;
[0157] The X subfields are divided into subfield groups having the maximum number of attributes, each subfield group includes subfields having the maximum number of attribute types, and each subfield is used to identify an attribute corresponding to a target data type.
[0158] In an optional embodiment, the attribute mapping module 702 is configured to:
[0159] According to the order of the attributes defined in the schema, determining to map the attributes to target subfield groups in a corresponding order, the target subfield group being one of the subfield groups with the maximum number of attributes included in the fixed field;
[0160] According to the data type of the attribute defined in the schema, it is determined to map the attribute to a target subfield, where the target subfield is one of the subfields with the maximum number of attribute types included in the target subfield group.
[0161] In an optional embodiment, the apparatus further comprises: a query condition acquisition module and a device query module;
[0162] The query condition acquisition module is used to obtain a device query condition, and the device query condition is used to query the IoT device based on a target attribute;
[0163] The device query module is configured to retrieve the query index using the device query condition to obtain target IoT devices in the set that match the device query condition.
[0164] In an optional embodiment, the device query module is configured to:
[0165] Based on the pattern, mapping the target attribute carried in the device query condition to a target subfield in the fixed field;
[0166] The query index is retrieved based on the target subfield to obtain the target IoT devices in the set that match the device query condition.
[0167] In an optional embodiment, the device query condition further carries a target device model identifier;
[0168] The device query module is used to:
[0169] Acquire a target mode corresponding to the device query condition, where the target mode is a mode of a device model corresponding to the target device model identifier;
[0170] Mapping the target attribute carried in the device query condition to a target subfield in the fixed field based on the target pattern;
[0171] Return the target IoT device in the set that has the same value as the target attribute and whose device model corresponds to the target device model identifier.
[0172] In an optional embodiment, the information in the collection is stored in the form of a document.
[0173] To sum up, the device provided in this embodiment maps the attributes of IoT devices of different device models to the same fixed field by presetting a fixed field. The fixed field is used to construct a query index, and the query index is used to assist in retrieving a collection, which stores information corresponding to IoT devices of different device models, thereby helping to establish a common query index for IoT devices of different device models within a collection.
[0174] Figure 8 Schematic diagram of the structure of a computer device provided by one embodiment of the present application. Specifically, the computer device 800 includes a central processing unit (CPU) 801, a system memory 804 including a random access memory (RAM) 802 and a read-only memory (ROM) 803, and a system bus 805 connecting the system memory 804 and the central processing unit 801. The computer device 800 also includes a basic input / output system (I / O system) 806 that helps transfer information between various components within the computer, and a mass storage device 807 for storing an operating system 813, application programs 814, and other program modules 815.
[0175] The basic input / output system 806 includes a display 808 for displaying information and an input device 809, such as a mouse and keyboard, for user account input. Both the display 808 and the input device 809 are connected to the central processing unit 801 via an input / output controller 810 connected to the system bus 805. The basic input / output system 806 may also include an input / output controller 810 for receiving and processing input from various other devices, such as a keyboard, mouse, or electronic stylus. Similarly, the input / output controller 810 also provides output to a display screen, printer, or other types of output devices.
[0176] The mass storage device 807 is connected to the central processing unit 801 via a mass storage controller (not shown) connected to the system bus 805. The mass storage device 807 and its associated computer-readable media provide non-volatile storage for the computer device 800. In other words, the mass storage device 807 may include a computer-readable medium (not shown) such as a hard disk or a CD-ROM drive.
[0177] Without loss of generality, computer-readable media may include computer storage media and communication media. Computer storage media include volatile and non-volatile, removable and non-removable media implemented by any method or technology for storing information such as computer-readable instructions, data structures, program modules or other data. Computer storage media include RAM, ROM, Erasable Programmable Read-Only Memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), flash memory or other solid-state storage technologies, CD-ROM, Digital Versatile Disc (DVD) or other optical storage, tape cassettes, magnetic tape, disk storage or other magnetic storage devices. Of course, those skilled in the art will appreciate that computer storage media are not limited to the above-mentioned ones. The above-mentioned system memory 804 and mass storage device 807 can be collectively referred to as memory.
[0178] According to various embodiments of the present application, the computer device 800 may also be connected to a remote computer on a network such as the Internet for operation. That is, the computer device 800 may be connected to a network 812 via a network interface unit 811 connected to the system bus 805, or the network interface unit 811 may be used to connect to other types of networks or remote computer systems (not shown).
[0179] The present application also provides a computer-readable storage medium, which stores at least one instruction, at least one program, code set or instruction set. The at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor to implement the query method of the Internet of Things device provided by the above-mentioned method embodiments.
[0180] The present application also provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the query method for an IoT device provided in each of the above method embodiments.
[0181] It should be understood that the term "plurality" used herein refers to two or more. "And / or" describes a relationship between associated objects, indicating that three possible relationships exist. For example, "A and / or B" can mean: A exists alone, A and B exist simultaneously, or B exists alone. The character " / " generally indicates an "or" relationship between the associated objects.
[0182] Those skilled in the art will understand that all or part of the steps of implementing the above embodiments may be accomplished by hardware, or by programs instructing related hardware to accomplish the steps. The programs may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk, or an optical disk, etc.
[0183] The above are only optional embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application.
Claims
1. A method for querying an Internet of Things device, characterized in that: The method comprises: Get the maximum number of attributes and the maximum number of attribute types supported by a single device model in the collection; Determine that a fixed field includes X subfields, where X is equal to the maximum number of attributes multiplied by the maximum number of attribute types; divide the X subfields into subfield groups equal to the maximum number of attributes, each subfield group includes subfields equal to the maximum number of attribute types, and each subfield is used to identify an attribute corresponding to the target data type; Obtaining a schema of the IoT device; the schema is a structure for describing the name and data type of an attribute of the IoT device; the schema includes a plurality of attributes, and the plurality of attributes are arranged in a certain order in the schema; Based on the schema of the device model of the IoT device, mapping the attributes of the IoT device to the fixed fields, the schema being a structure for describing the name and data type of the attributes of the IoT device, the fixed fields including a plurality of subfields; each subfield in the fixed fields corresponding to two dimensions of information: sequence information and data type information; Constructing a query index for the fixed field, the query index being used to assist in retrieving the collection, wherein the collection stores information of IoT devices corresponding to different device models; The mode based on the device model of the IoT device, mapping the attributes of the IoT device to fixed fields, includes: According to the order of the attributes indicated by the mode of the IoT device, at least one subfield having corresponding order information is queried, and then according to the data type of the attributes indicated by the mode of the IoT device, a unique subfield having corresponding data type information is queried in the at least one subfield, and the value corresponding to the attribute is written into the subfield.
2. The method according to claim 1, characterized in that The pattern based on the device model of the IoT device maps all attributes of the IoT device to fixed fields, including: According to the order of the attributes defined in the schema, determining to map the attributes to target subfield groups in a corresponding order, the target subfield group being one of the subfield groups with the maximum number of attributes included in the fixed field; According to the data type of the attribute defined in the schema, it is determined to map the attribute to a target subfield, where the target subfield is one of the subfields with the maximum number of attribute types included in the target subfield group.
3. The method according to claim 1 or 2, characterized in that The method further comprises: Obtaining a device query condition, where the device query condition is used to query the IoT device based on a target attribute; The query index is retrieved using the device query condition to obtain target IoT devices in the set that match the device query condition.
4. The method according to claim 3, characterized in that The step of using the device query condition to retrieve the query index to obtain a target IoT device in the set that matches the device query condition includes: Based on the pattern, mapping the target attribute carried in the device query condition to a target subfield in the fixed field; The query index is retrieved based on the target subfield to obtain the target IoT devices in the set that match the device query condition.
5. The method according to claim 4, characterized in that The device query condition also carries a target device model identifier; The mapping, based on the pattern, of the target attribute queried by the device query condition to the target subfield in the fixed field includes: Acquire a target mode corresponding to the device query condition, where the target mode is a mode of a device model corresponding to the target device model identifier; Mapping the target attribute carried in the device query condition to a target subfield in the fixed field based on the target pattern; The obtaining the target IoT device in the set that matches the device query condition includes: Return the target IoT device in the set that has the same value as the target attribute and whose device model corresponds to the target device model identifier.
6. The method according to claim 1 or 2, characterized in that The information in the collection is stored in the form of documents.
7. A query device for an Internet of Things device, characterized in that: The device includes: an attribute mapping module and an index building module; Get the module that specifies the maximum number of attributes and the maximum number of attribute types supported by a single device model in the collection; a module determining that a fixed field includes X subfields, where X is equal to the maximum number of attributes multiplied by the maximum number of attribute types; the X subfields are divided into subfield groups equal to the maximum number of attributes, each subfield group includes subfields equal to the maximum number of attribute types, and each subfield is used to identify an attribute corresponding to a target data type; A module for obtaining a schema of the IoT device; the schema is a structure for describing the name and data type of an attribute of the IoT device; the schema includes a plurality of attributes, and the plurality of attributes are arranged in a certain order in the schema; The attribute mapping module is configured to map the attributes of the IoT device to the fixed field based on the schema of the device model of the IoT device, wherein the schema is a structure for describing the name and data type of the attribute of the IoT device, and the fixed field includes a plurality of subfields; each subfield in the fixed field corresponds to two dimensions of information: sequence information and data type information; The index building module is used to build a query index for the fixed field, and the query index is used to assist in searching a collection, wherein the collection stores information of IoT devices corresponding to different device models; The mode based on the device model of the IoT device, mapping the attributes of the IoT device to fixed fields, includes: According to the order of the attributes indicated by the mode of the IoT device, at least one subfield having corresponding order information is queried, and then according to the data type of the attributes indicated by the mode of the IoT device, a unique subfield having corresponding data type information is queried in the at least one subfield, and the value corresponding to the attribute is written into the subfield.
8. A computer device, characterized in that: The computer device includes: a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set, or an instruction set, and the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by the processor to implement the query method for the Internet of Things device according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that The storage medium stores at least one instruction, at least one program, a code set, or an instruction set, and the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by the processor to implement the query method for the Internet of Things device according to any one of claims 1 to 6.
Citation Information
Patent Citations
Universal retrieval method and device, equipment and storage medium
CN113742535A
Data structured analysis method based on ElasticSearch
CN114064660A