A kind of internet of things equipment control method and system based on block chain
Technical field
The present invention relates to field of communication technology, in particular to a kind of internet of things equipment control method based on block chain and it is
System.
Background technique
Block chain is the novel of the computer technologies such as Distributed Storage, point-to-point transmission, common recognition mechanism, Encryption Algorithm
Application model.It is, in general, that block catenary system is made of data Layer, network layer, common recognition layer, excitation layer, contract layer and application layer.
Wherein, data Layer encapsulates bottom data block and the basic datas such as relevant data encryption and timestamp and rudimentary algorithm;
Network layer then includes distributed networking mechanism, data dissemination mechanism and data authentication mechanism etc.;Common recognition layer predominant package network section
All kinds of common recognition algorithms of point;Economic factor is integrated into block chain technical system by excitation layer, and main includes economic incentives
Issuing mechanism and distribution mechanism etc.;All kinds of scripts of contract layer predominant package, algorithm and intelligent contract, are block chain programmable features
Basis;Application layer then encapsulates the various application scenarios and case of block chain.In the model, the chain type block based on timestamp
Structure, the common recognition mechanism of distributed node, the intelligent contract based on the know together economic incentives and flexible programmable of calculating power are blocks
The most representative innovative point of chain technology.
From technical characterstic, block chain is generally acknowledged to include
Distributed fault-tolerance: network and its robust, the abnormality of fault-tolerant 1/3 or so node.
Can not tamper: it is consistent submit after data can always exist, can not destroyed or modification.
Privacy Safeguarding: cryptography ensure that can be accessed data without permission, but can not parse.
Bring business feature may include therewith:
Trustability: block chain technology can provide natural believable distributed account book platform, not need additional third party
Intermediary.
It reduces cost: being compared with traditional technology, block chain technology may be brought the shorter time, less manpower and maintenance
Cost.
Enhancing safety: block chain technology is beneficial to safe and reliable audit management and account clearance, and diminish crime possibility
Property and various risks.
Peer-to-peer network, i.e. peer-to-peer computer network are a kind of distributions that task and workload are distributed between fellow
A kind of networking or latticed form that formula application architecture, which is P2P computing model, to be formed in application layer.It can be with is defined as: network
Participant shares a part of hardware resource that they are possessed, these shared resources, can quilt by network offering services and content
Other peer nodes directly access without being subjected to intermediate entities.Participant in this network is both resource, service and content
Supplier, and be that resource, service and content obtain taker.
In peer to peer environment, all in the status of equity, each computer between the multiple stage computers that are connected to each other
There are identical function, no master-slave, a computer can not only be used for server, and setting shared resource is calculated for other in network
Machine is used, and can be used as work station, in general whole network does not depend on dedicated centralized servers, also not dedicated
Work station.Each computer in network can serve as the requestor of network service and the request of other computers is made
Response, provides resource, service and content.
With the fast development of technology of Internet of things, the wisdom life new era of all things on earth interconnection goes near gradually.Currently, Internet of Things
Equipment Market exponentially increases, and the impetus is swift and violent.People enjoy Internet of Things bring it is convenient while, internet-of-things terminal
Safety problem is gradually exposed.On the one hand, the safety of equipment access and control needs platform of internet of things to pass through a series of skills
Art scheme ensures that on the other hand, the interaction demand between equipment also increasingly increases.In this case, how to guarantee to setting
The control of standby control authority, prevent operation note be tampered and equipment between interconnection become a urgent problem needed to be solved.
Summary of the invention
In order to solve problems in the prior art, the embodiment of the invention provides a kind of internet of things equipment controls based on block chain
Method and system processed, to overcome in the prior art it cannot be guaranteed that the control of equipment control authority, operation note is prevented to be tampered,
And the problems such as interconnection between equipment.
In order to solve the above technical problems, the technical solution adopted by the present invention is that:
On the one hand, a kind of internet of things equipment control method based on block chain is provided, described method includes following steps:
S1: internet of things equipment is registered on platform of internet of things by device gateway;
S2: user passes through the platform of internet of things distribution apparatus control instruction;
S3: the platform of internet of things calls the service of block chain, is interacted, is called with intelligent contract by the block chain service
The intelligent corresponding interface of contract;
S4: the intelligence contract triggers contract event corresponding with the equipment control instruction;
S5: after the device gateway listens to contract event, processing is determined how according to the content in the contract event
The equipment control instruction.
Further, the step S1 is specifically included:
Internet of things equipment initiates registration request to platform of internet of things by device gateway, and platform of internet of things receives registration and asks
After asking, the unique identification of the internet of things equipment and the unique identification of the device gateway are recorded, and by the Internet of Things
The unique identification and user-association of the unique identification of equipment and the device gateway.
Further, the step S5 is specifically included:
After the device gateway listens to contract event, judge whether the device gateway in contract event is oneself, if so,
Then according to the unique identification of internet of things equipment to corresponding internet of things equipment sending device control instruction, if it is not, not appointing then
What is operated.
Further, the step S2 is specifically included:
User selects the equipment control instruction supported on the platform of internet of things, and clicks and issue.
Further, the method also includes:
S6: after the internet of things equipment has executed the equipment control instruction, by implementing result feed back to intelligent contract and
Platform of internet of things.
Further, the step S6 is specifically included:
After the internet of things equipment has executed the equipment control instruction, implementing result is fed back into the device gateway,
It is interacted by the device gateway with the intelligent contract, implementing result is sent to the intelligent contract record, the block
Chain service is sent to the platform of internet of things more new equipment implementing result after listening to instruction execution result event.
Further, after the internet of things equipment is registered on platform of internet of things by device gateway further include:
The state of internet of things equipment described in the platform of internet of things periodic detection.
Further, the state of internet of things equipment described in the platform of internet of things periodic detection specifically includes:
Platform of internet of things timing issues detection instruction, is interacted by the block chain service with intelligent contract, triggers equipment
State-detection event after device gateway listens to Condition Detection event, is monitored and recording equipment status data, and by equipment
Status data sends back platform of internet of things.
Further, the state of internet of things equipment described in the platform of internet of things periodic detection is specific further include:
If device gateway has listened to internet of things equipment and broken down, other internet of things equipment of the same user are by root
According to the rule being previously set, corresponding troubleshooting movement is made.
On the other hand, a kind of internet of things equipment control system based on block chain is provided, the system includes at least:
Platform of internet of things is used for internet of things equipment registration management and distribution apparatus control instruction;
Block chain service for the interaction between the platform of internet of things and intelligent contract and monitors instruction execution result
Event;
Intelligent contract, for providing the interface and contract event of external call, the intelligence contract is deployed in block chain
In;
Device gateway, for monitoring the event triggered in intelligent contract, such as according to the content judgement in the contract event
Where manages the equipment control instruction, and for managing internet of things equipment.
Further, the platform of internet of things includes at least:
Facility registration management module is used for registration management internet of things equipment;
Operational order release module, for being supplied to user's distribution apparatus control instruction.
Further, the block chain service includes at least:
Intelligent contract calling interface, for being interacted with intelligent contract;
Event monitoring module includes at least instruction execution result event for monitoring.
Further, the intelligent contract includes at least:
The interface of external call is used for and the block chain service interaction;
Contract event, for providing event corresponding with the equipment control instruction.
Further, the device gateway includes at least:
Equipment management service is sentenced for monitoring the event triggered in intelligent contract according to the content in the contract event
It is disconnected how to handle the equipment control instruction.
Further, the equipment management service includes at least:
Mqtt service, interacts with platform of internet of things for being supplied to equipment management service, by facility registration information and sets
Standby status data is sent to platform of internet of things;
Web3j is interacted for being supplied to equipment management service with intelligent contract, the intelligent contract run on loaded line, prison
Listen contract event;
Jna is interacted for being supplied to equipment management service with internet of things equipment, and control internet of things equipment executes the equipment
Control instruction and device status data is returned into equipment management service.
Technical solution provided in an embodiment of the present invention has the benefit that
1, the internet of things equipment control method and system provided by the invention based on block chain, using block chain intelligence contract
Equipment is issued as carrier to execute instruction.Due to only controlling in a short time based on the consistent distributed book keeping operation technology of data
51% or more node can just have an opportunity to change data, and change data it is necessary to change block, and each block chain will record
The hash value of previous block, so if to change the data on these blocks in the whole network needs very huge calculation power, and
And since block chain uses a large amount of cryptological technique, such as asymmetric arithmetic, elliptic curve, RSA etc., therefore, the present invention
The internet of things equipment control method and system based on block chain provided, can extraordinary retrospect record all execution and refer to
It enables, instruction execution result and equipment state, and related data is prevented to be tampered with, simplify the process of safety control;
2, the internet of things equipment control method and system provided by the invention based on block chain is based on block chain intelligence contract
It issues equipment as carrier to execute instruction, the mode that device directive issues realizes decentralization, and service is more stable, and availability is more
It is high;
3, the internet of things equipment control method and system provided by the invention based on block chain is based on peer-to-peer network, same
Interconnected communication, state aware may be implemented in all devices of a user;
4, the internet of things equipment control method and system provided by the invention based on block chain is based on event monitoring frame,
Device gateway can listen to any event of block chain network generation, realize that equipment state is synchronous, equipment room operation perception, phase
Than greatly reducing the load of device gateway in the mode of timing training in rotation.
Detailed description of the invention
To describe the technical solutions in the embodiments of the present invention more clearly, make required in being described below to embodiment
Attached drawing is briefly described, it should be apparent that, drawings in the following description are only some embodiments of the invention, for
For those of ordinary skill in the art, without creative efforts, it can also be obtained according to these attached drawings other
Attached drawing.
Fig. 1 is the flow chart of the internet of things equipment control method embodiment 1 provided by the invention based on block chain;
Fig. 2 is the flow chart of the internet of things equipment control method embodiment 2 provided by the invention based on block chain;
Fig. 3 is the structural schematic diagram of the internet of things equipment control system provided by the invention based on block chain;
Fig. 4 is that the structure of equipment management service in the internet of things equipment control system provided by the invention based on block chain is shown
It is intended to.
Specific embodiment
To make the object, technical solutions and advantages of the present invention clearer, below in conjunction with attached in the embodiment of the present invention
Figure, technical scheme in the embodiment of the invention is clearly and completely described, it is clear that described embodiment is only this
Invention a part of the embodiment, instead of all the embodiments.Based on the embodiments of the present invention, those of ordinary skill in the art exist
Every other embodiment obtained under the premise of creative work is not made, shall fall within the protection scope of the present invention.
Embodiment 1
As shown in Figure 1, Fig. 1 is the stream of the internet of things equipment control method embodiment 1 provided by the invention based on block chain
Cheng Tu, described method includes following steps:
S1: internet of things equipment is registered on platform of internet of things by device gateway.
Specifically, before new internet of things equipment access the equipment management service in device gateway need to be being passed through to Internet of Things
Platform is registered.
Further, the step S1 is specifically included:
After internet of things equipment networking, registration is initiated to platform of internet of things by the equipment management service in device gateway and is asked
It asks, after platform of internet of things receives registration request, letter needed for creating internet of things equipment and obtaining internet of things equipment authentication registration
Breath, records the unique identification of the internet of things equipment and the unique identification of the device gateway, and the Internet of Things is set
The unique identification and user-association of standby unique identification and the device gateway.What needs to be explained here is that authentication registration institute
The information needed further includes the information such as private key, equipment communication queue name other than unique identification.Wherein, in equipment management service
Information needed for servicing incoming authentication registration by mqtt, accesses platform of internet of things for internet of things equipment.
S2: user passes through the platform of internet of things distribution apparatus control instruction.
Specifically, can select to support on the platform of internet of things when user needs to operate some internet of things equipment
Equipment control instruction, and click issue.
S3: the platform of internet of things calls the service of block chain, is interacted, is called with intelligent contract by the block chain service
The intelligent corresponding interface of contract.
Specifically, platform of internet of things calls the service of block chain, interacted by the service of block chain with intelligent contract, block chain clothes
It is packaged with intelligent contract calling interface in business, corresponding interface in intelligent contract is called by intelligent contract calling interface, is realized
The interaction of the service of block chain and intelligent contract.
S4: the intelligence contract triggers contract event corresponding with the equipment control instruction.
Specifically, being provided with contract event corresponding with the equipment control instruction, intelligent contract root in intelligent contract
Corresponding contract event is triggered according to the equipment control instruction received.
S5: after the device gateway listens to contract event, processing is determined how according to the content in the contract event
The equipment control instruction.
Further, the step S5 is specifically included:
After equipment management service in the device gateway listens to contract event, the device gateway in contract event is judged
Whether unique identification is oneself, if so, explanation is intended for oneself instruction, then according to the unique identification of internet of things equipment to corresponding
Internet of things equipment sending device control instruction do not do any operation then if it is not, explanation is not intended for oneself instruction.
What needs to be explained here is that in the internet of things equipment control method provided in an embodiment of the present invention based on block chain,
One device gateway can manage multiple internet of things equipment, and equipment management service, equipment management service are deployed on device gateway
Contract event can be monitored, for the finger for belonging to itself listened to by the intelligent contract run on web3j loaded line when starting
It enables, equipment management service controls corresponding internet of things equipment by jna and executes corresponding movement.
Further, Internet of Things described in the internet of things equipment control method provided in an embodiment of the present invention based on block chain
After equipment is registered on platform of internet of things by device gateway further include:
The state of internet of things equipment described in the platform of internet of things periodic detection.
Specifically, platform of internet of things can periodically issue detection instruction for the internet of things equipment of access, pass through the block
Chain service is interacted with intelligent contract, triggers Condition Detection event, and the equipment management service in device gateway listens to equipment
After state-detection event, Condition Detection interface returning equipment status data, and recording equipment status number are called by Jna
According to being serviced by mqtt device status data sending back platform of internet of things.Wherein, if device gateway has listened to Internet of Things
Device fails, other internet of things equipment of the same user make corresponding failure for according to the rule being previously set
Processing movement.
In the specific implementation, platform of internet of things possesses the list of devices of registration, communication between devices to the rule being previously set
It is unified to use json format, platform of internet of things be capable of the data of failure or acquisition by page configuration based on 1-n equipment come
Given threshold, while the movement of other equipment execution after the condition of satisfaction can be set.Such as: under Intelligent household scene, intelligence
Cooking apparatus is if a failure occurs, gas management equipment detection trigger, and after gas is more than a certain concentration, intelligent door and window is according to event
Barrier and gas density automatically turn on window ventilation.So rule is expressed as follows with sequencing here:
If breakdown and gas > 100then window.open ().
What needs to be explained here is that will record respective equipment state number between the internet of things equipment of the only same user
According to.
Embodiment 2
As shown in Fig. 2, Fig. 2 is the stream of the internet of things equipment control method embodiment 2 provided by the invention based on block chain
Cheng Tu, this method is other than including above-mentioned steps S1 to S5, further includes:
S6: after the internet of things equipment has executed the equipment control instruction, by implementing result feed back to intelligent contract and
Platform of internet of things.
Further, the step S6 is specifically included:
After the internet of things equipment has executed the equipment control instruction, implementing result is fed back by jna callback interface
To the equipment management service in device gateway.Pass through the equipment management service and the intelligent contract friendship in the device gateway
Mutually, implementing result is sent to the intelligent contract, specifically, equipment management service is by calling in intelligent contract
RecordActionLog method recording instruction implementing result.The block chain service simultaneously listens to instruction execution result event
After be sent to the platform of internet of things more new equipment implementing result.
Embodiment 3
As shown in figure 3, Fig. 3 is the structural representation of the internet of things equipment control system provided by the invention based on block chain
Figure, the system include at least:
Platform of internet of things is used for internet of things equipment registration management and distribution apparatus control instruction.
Specifically, Physical Network platform is mainly used for internet of things equipment registration management, message management and distribution apparatus control
Instruction.
Further, the platform of internet of things includes at least:
Facility registration management module is used for registration management internet of things equipment;
Operational order release module, for being supplied to user's distribution apparatus control instruction.
Specifically, the unified platform that platform of internet of things is issued as facility registration management and equipment control instruction, passes through web
The page realizes operation, and then realizes that equipment management, equipment control instruction such as issue at the functions.
Block chain service for the interaction between the platform of internet of things and intelligent contract and monitors instruction execution result
Event.
Further, the block chain service includes at least:
Intelligent contract calling interface, for being interacted with intelligent contract;
Event monitoring module includes at least instruction execution result event for monitoring.
Specifically, encapsulating the intelligent contract calling interface and event prison of external call intelligence contract in block chain service
Module is listened, block chain service is mainly used for the interaction between platform of internet of things and intelligent contract.
Intelligent contract, for providing the interface and contract event of external call, the intelligence contract is deployed in block chain
In.
Specifically, intelligent contract is write using solidity language in the embodiment of the present invention, and dispose the area of intelligent contract
The calling of the operation of intelligent contract and web3j that the compatible solidity of block chain writes.
Further, the intelligent contract includes at least:
The interface of external call is used for and the block chain service interaction;
Contract event, for providing event corresponding with the equipment control instruction.
Specifically, further including the member of intelligent contract in addition to the interface comprising external call and contract event in intelligent contract
Data.
It is included at least in the interface of external call:
ExecAction: interface is executed instruction, triggers execActionEvent event in interface;
NotifyDeviceStatus: it notifies equipment state interface, triggers notifyDeviceStatusEvent in interface
Event;
RecordActionLog: recording instruction implementing result interface triggers recordActionLogEvent thing in interface
Part.
Contract event includes at least:
ExecActionEvent: event i.e. corresponding with the equipment control instruction;
NotifyDeviceStatusEvent: i.e. Condition Detection event;
RecordActionLogEvent: i.e. recording instruction implementing result event.
Metadata includes at least:
ContractAddress: the intelligent contract address of calling, different intelligent contracts are distinguished by contract address;
BaseAccount: the account of intelligent contract is created.
Device gateway, for monitoring the event triggered in intelligent contract, such as according to the content judgement in the contract event
Where manages the equipment control instruction, and for managing internet of things equipment.
Specifically, the operating system of the device gateway in the embodiment of the present invention selects Raspherry Pi operating system, and
Device gateway includes multiple.
Further, the device gateway includes at least:
Equipment management service is sentenced for monitoring the event triggered in intelligent contract according to the content in the contract event
It is disconnected how to handle the equipment control instruction.
Specifically, further including security module in device gateway, security module is controlled for equipment safety.Wherein, safe mould
Block mainly provides following two function: 1, key management;2 encryption and decryption operations.Each equipment can have one based on block chain
Account, each account possess the public and private key of one group of asymmetric encryption, and wherein private key is stored in security module.When receiving number
According to and confirm be destined to the data of oneself when, data content is decrypted by security module, therefore ensure that safety.Together
Should device gateway send data when, equally encrypted by security module after retransmit encrypted data.The present invention is real
The equipment management service applied in example uses java language.
Further, referring to shown in Fig. 4, Fig. 4 is the internet of things equipment control system provided by the invention based on block chain
The structural schematic diagram of middle equipment management service, the equipment management service include at least:
Mqtt service, interacts with platform of internet of things for being supplied to equipment management service, by facility registration information and sets
Standby status data is sent to platform of internet of things.
Specifically, on the one hand, new obtain need to create equipment in platform of internet of things before internet of things equipment accesses and obtain equipment note
Information needed for volume certification, including equipment unique identification, private key, equipment communication queue name etc..Pass through in equipment management service
Mqtt services incoming authentication information and equipment is accessed platform of internet of things.On the other hand, equipment meeting of the platform of internet of things for access
Timing issues detection instruction, after equipment management service receives detection instruction, calls Condition Detection interface to return by jna
Equipment state is serviced by mqtt equipment state sending back platform of internet of things.
Web3j is interacted for being supplied to equipment management service with intelligent contract, the intelligent contract run on loaded line, prison
Listen contract event.
Specifically, web3j is a lightweight, high modularization, passive-type, the safe library Java and Android,
For handling intelligent contract and being integrated with the client in block chain network.So that block chain can be used in user, and
Without writing oneself integrated code for platform.
Equipment management service can be passed through when starting by the intelligent contract run on web3j loaded line
EventObservable interface monitors contract event, for the instruction for belonging to itself listened to, controls equipment by jna and holds
The corresponding movement of row.
Equipment, which has executed, feeds back to equipment management service, equipment management for implementing result by jna callback interface after movement
The recordActionLog method recording instruction implementing result in intelligent contract is called in service by web3j, while block chain takes
Business will also listen to instruction execution result event and be sent to platform of internet of things more new equipment implementing result.
Equipment testing result equally passes through eventObservable interface and gets, and will record in device gateway
In being locally stored, it to be used for subsequent troubleshooting.
Jna is interacted for being supplied to equipment management service with internet of things equipment, and control internet of things equipment executes the equipment
Control instruction and device status data is returned into equipment management service.
Jna is writing a Chinese character in simplified form for Java Native Access, provides one group of Java tool-class dynamic access system during operation
Local library unite without writing any Native/jni code.As long as developer describes target in a java interface
The function and structure of native library, jna realize the mapping of Java interface to native function for automatic.
In conclusion technical solution provided in an embodiment of the present invention has the benefit that
1, the internet of things equipment control method and system provided by the invention based on block chain, using block chain intelligence contract
Equipment is issued as carrier to execute instruction.Due to only controlling in a short time based on the consistent distributed book keeping operation technology of data
51% or more node can just have an opportunity to change data, and change data it is necessary to change block, and each block chain will record
The hash value of previous block, so if to change the data on these blocks in the whole network needs very huge calculation power, and
And since block chain uses a large amount of cryptological technique, such as asymmetric arithmetic, elliptic curve, RSA etc., therefore, the present invention
The internet of things equipment control method and system based on block chain provided, can extraordinary retrospect record all execution and refer to
It enables, instruction execution result and equipment state, and related data is prevented to be tampered with, simplify the process of safety control;
2, the internet of things equipment control method and system provided by the invention based on block chain is based on block chain intelligence contract
It issues equipment as carrier to execute instruction, the mode that device directive issues realizes decentralization, and service is more stable, and availability is more
It is high;
3, the internet of things equipment control method and system provided by the invention based on block chain is based on peer-to-peer network, same
Interconnected communication, state aware may be implemented in all devices of a user;
4, the internet of things equipment control method and system provided by the invention based on block chain is based on event monitoring frame,
Device gateway can listen to any event of block chain network generation, realize that equipment state is synchronous, equipment room operation perception, phase
Than greatly reducing the load of device gateway in the mode of timing training in rotation.
It should be understood that provided by the above embodiment controlled based on the internet of things equipment control system of block chain in triggering
When business, only the example of the division of the above functional modules, in practical application, it can according to need and by above-mentioned function
It can distribute and be completed by different functional modules, i.e., the internal structure of system is divided into different functional modules, more than completing
The all or part of function of description.In addition, the internet of things equipment control system provided by the above embodiment based on block chain with
Internet of things equipment control method embodiment based on block chain belongs to same design, and specific implementation process is detailed in method implementation
Example, which is not described herein again.
Those of ordinary skill in the art will appreciate that realizing that all or part of the steps of above-described embodiment can pass through hardware
It completes, relevant hardware can also be instructed to complete by program, the program can store in a kind of computer-readable
In storage medium, storage medium mentioned above can be read-only memory, disk or CD etc..
All the above alternatives can form alternative embodiment of the invention using any combination, herein no longer
It repeats one by one.The foregoing is merely presently preferred embodiments of the present invention, is not intended to limit the invention, it is all in spirit of the invention and
Within principle, any modification, equivalent replacement, improvement and so on be should all be included in the protection scope of the present invention.