Disclosure of Invention
An object of the embodiments of the present application is to provide a terminal linkage method and apparatus based on a block chain, and an electronic device, so as to improve the problems that the current user rule execution architecture is deployed in a centralized manner, and is unreliable, unsafe, and has no fair and fair execution log record, and it is difficult to trace responsibility.
The invention is realized by the following steps:
in a first aspect, an embodiment of the present application provides a terminal linkage method based on a block chain, which is applied to a gateway device, and the method includes: receiving a first control message sent by a trigger terminal; the first control message comprises an identifier of the trigger terminal and control state information; sending the first control message to a first node in a block chain system, so that the first node determines a rule contract matched with the identifier of the trigger terminal and the control state information from a distributed book based on the first control message, and executes a contract event corresponding to the rule contract; receiving a second control message sent by the first node; the second control message comprises an identifier of a response terminal corresponding to the contract event and control execution information corresponding to the response terminal; and sending the control execution information to the response terminal.
In the embodiment of the application, a distributed rule execution method is constructed by using a block chain technology, so that the problems of high safety risk and low efficiency of the conventional centralized rule implementation mode are solved. And the trusted storage and the trusted execution are realized through the rule contract in the block chain. The triggering condition, the executing process and the executing result of the rule execution are stored on the chain, so that the safety, the reliability and the traceability of the linkage process among the terminal devices are ensured.
In a second aspect, an embodiment of the present application provides a terminal linkage method based on a blockchain, which is applied to a first node in a blockchain system, and the method includes: receiving a first control message sent by gateway equipment; the first control message comprises an identifier of a trigger terminal and control state information; determining a rule contract matched with the identification of the trigger terminal and the control state information from a distributed account book based on the first control message, and executing a contract event corresponding to the rule contract; sending a second control message to the gateway equipment; the second control message includes an identifier of a response terminal corresponding to the contract event and control execution information corresponding to the response terminal.
With reference to the technical solution provided by the second aspect, in some possible implementation manners, before the receiving the first control packet sent by the gateway device, the method further includes: receiving a scene control rule sent by an Internet of things platform; the scene control rule comprises an identifier of the trigger terminal, control state information corresponding to the trigger terminal, an identifier of the response terminal and control execution information corresponding to the response terminal; and storing the scene control rule into a rule contract in the distributed account book.
In a third aspect, an embodiment of the present application provides a rule configuration method based on a block chain, which is applied to an internet of things platform, and the method includes: receiving a scene control rule sent by a user terminal; the scene control rule comprises an identifier of a trigger terminal, control state information of the trigger terminal, an identifier of a response terminal and control execution information of the response terminal; and sending the scene control rule to a first node in a blockchain system, so that the first node stores the scene control rule in a rule contract in a distributed account book.
With reference to the technical solution provided by the third aspect, in some possible implementation manners, the sending the scene control rule to the first node in the blockchain system includes: signing the scene control rule based on a pre-stored private key of the user terminal; sending the signed scene control rule to a first node in the block chain system so that the first node verifies the signature based on a pre-stored public key; and after the signature verification is passed, the first node stores the scene control rule into a rule contract in a distributed account book.
In the embodiment of the application, the Internet of things platform signs the scene control rule based on a pre-stored private key of the user terminal; and sending the signed scene control rule to a first node in the block chain system so that the first node verifies the signature based on a pre-stored public key. By the method, the safety of the data transmission process is improved.
In a fourth aspect, an embodiment of the present application provides a terminal linkage device based on a block chain, which is applied to a gateway device, and the device includes: the first receiving module is used for receiving a first control message sent by the trigger terminal; the first control message comprises an identifier of the trigger terminal and control state information; a first sending module, configured to send the first control packet to a first node in a blockchain system, so that the first node determines, based on the first control packet, a rule contract that is matched with an identifier of the trigger terminal and the control state information from a distributed book, and executes a contract event corresponding to the rule contract; a second receiving module, configured to receive a second control packet sent by the first node; the second control message comprises an identifier of a response terminal corresponding to the contract event and control execution information corresponding to the response terminal; and the second sending module is used for sending the control execution information to the response terminal.
In a fifth aspect, an embodiment of the present application provides a blockchain-based terminal linkage device applied to a first node in a blockchain system, where the device includes: the receiving module is used for receiving a first control message sent by the gateway equipment; the first control message comprises an identifier of a trigger terminal and control state information; the determining module is used for determining a rule contract matched with the identifier of the trigger terminal and the control state information from a distributed account book based on the first control message and executing a contract event corresponding to the rule contract; a sending module, configured to send a second control packet to the gateway device; the second control message includes an identifier of a response terminal corresponding to the contract event and control execution information corresponding to the response terminal.
In a sixth aspect, an embodiment of the present application provides a rule configuration device based on a block chain, which is applied to an internet of things platform, and the device includes: the receiving module is used for receiving the scene control rule sent by the user terminal; the scene control rule comprises an identifier of a trigger terminal, control state information of the trigger terminal, an identifier of a response terminal and control execution information of the response terminal; and the sending module is used for sending the scene control rule to a first node in a blockchain system so that the first node stores the scene control rule in a rule contract in a distributed account book.
In a seventh aspect, an embodiment of the present application provides an electronic device, including: a processor and a memory, the processor and the memory connected; the memory is used for storing programs; the processor is configured to call a program stored in the memory, and execute the method provided in the first aspect, the second aspect, or the third aspect.
In an eighth aspect, embodiments of the present application provide a storage medium having a computer program stored thereon, where the computer program, when executed by a processor, performs the methods as provided in the first, second, or third aspects.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
In view of the fact that the related user rule execution architecture is deployed in a centralized manner for the interaction of the internet of things intelligent device at present, and the problems of unreliability, insecurity, no fair and impartial execution log record and difficulty in responsibility tracing exist, the inventor of the present application has conducted research and exploration and provides the following embodiments to solve the problems.
Referring to fig. 1, an embodiment of the present application provides a terminal linkage system based on a block chain, including: gateway equipment, block chain system and thing networking platform.
It should be noted that the block chain system is a distributed shared account book and database, has the characteristics of decentralization, non-falsification, trace remaining in the whole process, traceability, collective maintenance, public transparency and the like, and is composed of a plurality of nodes. For convenience of explaining the scheme, in the embodiment of the present application, the interaction between the first node in the blockchain system and the gateway device and the internet of things platform is described. That is, the first node in the blockchain system is communicatively connected to the gateway device and the internet of things platform. The first node may be the same node or different nodes, and the present application is not limited thereto.
The internet of things platform is mainly used for performing credible uplink on the scene control rule sent by the user terminal, namely, sending the scene control rule to a first node in the block chain system, so that the first node writes the scene control rule into a rule contract in the distributed account book.
It should be explained that a rule contract is a computer protocol in a blockchain system that aims to propagate, verify or execute contracts in an informational manner, i.e., a Smart contract (Smart contract).
After the rule contract is stored in the distributed account book, the first node is mainly used for matching the rule contract corresponding to the message from the distributed account book according to the message sent by the receiving gateway device, executing the contract event corresponding to the contract, further obtaining the execution result of the contract event, and then sending the execution result to the gateway device.
Among them, Gateway (Gateway) devices, also called internetwork connectors and protocol converters, are computer systems or devices that provide data conversion services among multiple networks. The gateway device is mainly used for receiving a message sent by the trigger terminal and sending the message to a first node in the block chain system, so that the first node determines a rule contract matched with the message from the distributed account book and executes a contract event corresponding to the rule contract; and then receiving an execution result sent by the first node, and sending the execution result to a corresponding response terminal.
The gateway device realizes interaction with the first node through an API (Application Programming Interface) Interface.
Referring to fig. 2, the present embodiment provides a terminal linkage method based on a block chain, which is applied to the terminal linkage system based on the block chain shown in fig. 1, and it should be noted that the terminal linkage method based on the block chain provided in the present embodiment is not limited by the sequence shown in fig. 2 and the following. The method comprises the following steps: step S101-step S108.
Step S101: the method comprises the steps that an Internet of things platform receives a scene control rule sent by a user terminal; the scene control rule comprises an identifier of a trigger terminal, control state information of the trigger terminal, an identifier of a response terminal and control execution information of the response terminal.
The scene control rule is a rule which can be customized by a user. The scene control rule needs to include an identifier of the trigger terminal, control state information of the trigger terminal, an identifier of the response terminal, and control execution information of the response terminal. The trigger terminal and the response terminal may be the same device or different devices, and the following description is given by way of example.
As a scenario, the scenario control rule may be a rule that the smart watch controls the smart door lock to open or close. Namely, the triggering terminal is an intelligent watch A, and the response terminal is an intelligent door lock B. The control state information of the intelligent watch A can be that the intelligent watch A triggers a door opening button; the control execution information of the corresponding intelligent door lock B is the opening of the door. The control state information of the intelligent watch A can also be that the intelligent watch A triggers a door closing button, and the corresponding control execution information of the intelligent door lock B is door closing.
As another scenario, the scenario control rule may be an alarm rule reported by the detection device, for example, the detection device may be a traffic monitoring device, and the corresponding response terminal may be a mobile phone of the user. The control state information of the flow monitoring device may be that the flow information is monitored to be greater than a preset threshold, and correspondingly, the control execution information of the mobile phone is the generated alarm information.
As another scenario, the scenario control rule may also be a mail sending rule, for example, the trigger terminal is a mobile phone of the user, and the corresponding response terminal is also a mobile phone of the user. The control state information of the mobile phone is information triggering the sending of the mail to the target user, and the control execution information of the corresponding mobile phone is the sending of the mail (the sending object is the target user).
It is understood that in other embodiments, the above-described scenario control rules may also be rules defined by a user for a wide variety of smart homes. For example, the present application is not limited to the rules for controlling an intelligent desk lamp and the rules for controlling an intelligent television.
Step S102: and the Internet of things platform sends the scene control rule to a first node in the block chain system.
After receiving the scene control rule sent by the user terminal, the Internet of things platform sends the scene control rule to a first node in the block chain system.
As an optional implementation manner, when the scene control rule is sent to the first node, the scene control rule is signed according to a pre-stored private key of the user terminal, and then the signed scene control rule is sent to the first node.
When the method is adopted, the user terminal registers in the Internet of things platform and the block chain system in advance, namely, during registration, the user terminal sends the private key to the Internet of things platform and sends the public key to the first node in the block chain system. That is, the internet of things platform stores the private key sent by the user terminal after receiving the private key, and when the user terminal sends the scene control rule, the private key corresponding to the user terminal is inquired from the stored private key, and the scene control rule is signed by the private key. The Internet of things platform can store the private key corresponding to each user terminal through the identification code of the user terminal. And finally, sending the signed scene control rule to the first node so that the first node verifies the signature through a public key. By the method, the safety of the data transmission process is improved.
Step S103: the first node stores the scenario control rule into a rule contract in a distributed ledger.
After receiving the scene control rule sent by the internet of things platform, the first node stores the scene control rule in a rule contract in the distributed account book.
When the first node sends the signed scene control rule, the first node firstly verifies the signature. That is, the verification is performed through a public key sent by the user terminal in advance, if the verification is passed, the scene control rule is stored into a rule contract in the distributed account book, and if the verification fails, the rule uplink request is discarded, and the process is ended.
The credible uplink of the scene control rule can be completed through the steps S101 to S103, so that the scene rule configured by the user is stored in the block chain system, and the terminal linkage method can be executed through the scene rule stored in the block chain system subsequently.
Step S104: the gateway equipment receives a first control message sent by a trigger terminal; the first control message comprises an identifier of the trigger terminal and control state information.
After the credible uplink of the scene control rule is finished, terminal linkage control can be performed below, and the gateway equipment receives a first control message sent by the trigger terminal at first. The first control packet includes the identifier of the trigger terminal and the control state information. The identifier of the trigger terminal may be an ID (Identity document) of the trigger terminal, or may also be an IP (Internet Protocol) address of the trigger terminal, which is not limited in the present application.
Illustratively, the trigger terminal is a smart watch, the ID of the trigger terminal is 001, and the control state information of the trigger terminal is a trigger door opening button.
Step S105: the gateway device sends the first control message to a first node in the blockchain system.
And then, the gateway equipment sends the identifier of the trigger terminal and the control state information to the first node. The gateway equipment sends the identifier of the trigger terminal and the control state information to the first node through the API.
Step S106: and the first node determines a rule contract matched with the identification of the trigger terminal and the control state information from the distributed account book based on the first control message, and executes a contract event corresponding to the rule contract.
Then, after receiving the identifier of the trigger terminal and the control state information sent by the gateway device, the first node matches a corresponding rule contract from the distributed account book, and executes a contract event corresponding to the rule contract. It can be understood that the pre-stored rule contract has a corresponding relationship between the control state information of the trigger terminal and the control execution information of the response terminal, and the contract event corresponding to the execution rule contract can be understood as determining the control execution information of the corresponding response terminal through the control state information of the trigger terminal. That is, the contract event corresponding to the execution rule contract obtains the execution result of the contract event, that is, the corresponding identifier of the response terminal and the control execution information of the response terminal are obtained.
Illustratively, when the trigger terminal is a smart watch, the ID of the trigger terminal is 001, the control state information of the trigger terminal is a trigger door opening button, and the first node executes a contract event corresponding to the rule contract to obtain the control execution information of the smart door lock B and the control execution information of the smart door lock B as door opening.
It should be noted that, when the rule contract is not matched with the rule contract, a message representing a control error is sent to the gateway device.
Step S107: the first node sends a second control message to the gateway equipment; the second control message includes an identifier of a response terminal corresponding to the contract event and control execution information corresponding to the response terminal.
And then, the first node sends the identification of the response terminal and the control execution information party corresponding to the response terminal to the gateway equipment.
Step S108: the gateway device transmits the control execution information to the response terminal.
And finally, the gateway equipment transmits the control execution information to the corresponding response terminal, thereby completing the control of the response terminal.
Next, the terminal linkage method is described with reference to a specific example, and referring to fig. 3, it is assumed that a scene control rule for controlling the smart watch a to open or close the smart door lock B is prestored in the distributed book in the blockchain system. The user clicks the door opening button on the intelligent watch A, at the moment, the gateway device receives a first control message (including the intelligent watch A and information triggering the door opening button) sent by the intelligent watch A, and then sends the intelligent watch A and the information triggering the door opening button to a first node in the block chain system. The first node determines a rule contract matched with the intelligent watch A and information triggering a door opening button from the distributed account book based on the first control message, executes a contract event corresponding to the rule contract, then sends an execution result corresponding to the contract time to the gateway device (wherein the execution result is that the intelligent door lock B opens the door), and finally the gateway device sends a door opening instruction to the intelligent door lock B, so that linkage of the intelligent watch and the intelligent door lock based on the block chain is completed.
In summary, in the embodiment of the present application, a distributed rule execution method is constructed by using a blockchain technique, so that the problems of high security risk and low efficiency of the current centralized rule implementation method are solved. And the trusted storage and the trusted execution are realized through the rule contract in the block chain. The triggering condition, the executing process and the executing result of the rule execution are stored on the chain, so that the safety, the reliability and the traceability of the linkage process among the terminal devices are ensured.
It should be noted that the above embodiments are a complete description of the terminal linkage method of the blockchain in the terminal linkage system based on the blockchain. However, the internet of things platform, the first node in the blockchain system, and the gateway device may each execute a corresponding method.
For example, the embodiment of the application further provides a rule configuration method based on the block chain, which is applied to the platform of the internet of things. The method comprises the following steps: receiving a scene control rule sent by a user terminal; the scene control rule comprises an identifier of a trigger terminal, control state information of the trigger terminal, an identifier of a response terminal and control execution information of the response terminal; and sending the scene control rule to a first node in a blockchain system, so that the first node stores the scene control rule in a rule contract in a distributed account book.
For another example, the embodiment of the present application further provides a terminal linkage method based on a block chain, which is applied to the first node. The method comprises the following steps: receiving a first control message sent by gateway equipment; the first control message comprises an identifier of a trigger terminal and control state information; determining a rule contract matched with the identification of the trigger terminal and the control state information from a distributed account book based on the first control message, and executing a contract event corresponding to the rule contract; sending a second control message to the gateway equipment; the second control message includes an identifier of a response terminal corresponding to the contract event and control execution information corresponding to the response terminal.
For another example, the embodiment of the present application further provides a terminal linkage method based on a block chain, which is applied to a gateway device. The method comprises the following steps: receiving a first control message sent by a trigger terminal; the first control message comprises an identifier of the trigger terminal and control state information; sending the first control message to a first node in a block chain system, so that the first node determines a rule contract matched with the identifier of the trigger terminal and the control state information from a distributed book based on the first control message, and executes a contract event corresponding to the rule contract; receiving a second control message sent by the first node; the second control message comprises an identifier of a response terminal corresponding to the contract event and control execution information corresponding to the response terminal; and sending the control execution information to the response terminal.
Referring to fig. 4, based on the same inventive concept, anelectronic device 100 according to an embodiment of the present application is further provided, which includes acontroller 101 and amemory 102, where thememory 102 stores computer-readable instructions, and the computer-readable instructions, when executed by thecontroller 101, cause thecontroller 101 to execute the method.
The controller may also be a general-purpose Processor, for example, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a discrete gate or transistor logic device, or a discrete hardware component, and may implement or execute the methods, steps, and logic blocks disclosed in the embodiments of the present Application. Further, a general purpose processor may be a microprocessor or any conventional processor or the like.
The Memory may be, but is not limited to, Random Access Memory (RAM), Read Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (EPROM), and electrically Erasable Programmable Read-Only Memory (EEPROM). The memory is used for storing a program, and the controller executes the program after receiving the execution instruction.
It should be noted that theelectronic device 100 may be a gateway device, a first node in a blockchain system, or an internet of things platform in the foregoing embodiments. That is, the structures of the gateway device, the first node, and the internet of things platform provided in the embodiment of the present application all refer to the structure shown in fig. 4.
Referring to fig. 5, based on the same inventive concept, an embodiment of the present application further provides a terminal linkage device 200 based on a block chain, which is applied to a gateway device, and the device includes:
a first receiving module 201, configured to receive a first control packet sent by a trigger terminal; the first control message includes an identifier of the trigger terminal and control state information.
A first sending module 202, configured to send the first control packet to a first node in a blockchain system, so that the first node determines, based on the first control packet, a rule contract that is matched with the identifier of the trigger terminal and the control state information from a distributed ledger, and executes a contract event corresponding to the rule contract.
A second receiving module 203, configured to receive a second control packet sent by the first node; the second control message includes an identifier of a response terminal corresponding to the contract event and control execution information corresponding to the response terminal.
A second sending module 204, configured to send the control execution information to the response terminal.
Referring to fig. 6, based on the same inventive concept, an embodiment of the present invention further provides a terminal linkage apparatus 300 based on a block chain, applied to a first node in a block chain system, the apparatus including:
a receiving module 301, configured to receive a first control packet sent by a gateway device; the first control message comprises an identifier of a trigger terminal and control state information.
A determining module 302, configured to determine, based on the first control packet, a rule contract that is matched with the identifier of the trigger terminal and the control state information from the distributed ledger, and execute a contract event corresponding to the rule contract.
A sending module 303, configured to send a second control packet to the gateway device; the second control message includes an identifier of a response terminal corresponding to the contract event and control execution information corresponding to the response terminal.
Optionally, the apparatus further comprises: a configuration module 304. The configuration module is used for receiving a scene control rule sent by the Internet of things platform before receiving a first control message sent by the gateway equipment; the scene control rule comprises an identifier of the trigger terminal, control state information corresponding to the trigger terminal, an identifier of the response terminal and control execution information corresponding to the response terminal; and storing the scene control rule into a rule contract in the distributed account book.
Referring to fig. 7, based on the same inventive concept, an embodiment of the present application further provides a rule configuration apparatus 400 based on a block chain, which is applied to an internet of things platform, and the apparatus includes:
a receiving module 401, configured to receive a scene control rule sent by a user terminal; the scene control rule comprises an identifier of a trigger terminal, control state information of the trigger terminal, an identifier of a response terminal and control execution information of the response terminal.
A sending module 402, configured to send the scenario control rule to a first node in a blockchain system, so that the first node stores the scenario control rule in a rule contract in a distributed ledger.
Optionally, the sending module 402 is specifically configured to sign the scene control rule based on a pre-stored private key of the user terminal; sending the signed scene control rule to a first node in the block chain system so that the first node verifies the signature based on a pre-stored public key; and after the signature verification is passed, the first node stores the scene control rule into a rule contract in a distributed account book.
It should be noted that, as those skilled in the art can clearly understand, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
Based on the same inventive concept, the present application further provides a storage medium, on which a computer program is stored, and when the computer program is executed, the computer program performs the method provided in the foregoing embodiments.
The storage medium may be any available medium that can be accessed by a computer or a data storage device including one or more integrated servers, data centers, and the like. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
In addition, units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
Furthermore, the functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
In this document, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions.
The above description is only an example of the present application and is not intended to limit the scope of the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application.