Device Definition - eucleed/wikkiot GitHub Wiki
Device definition.
The device definition is part of the Wikkiot protocol
The device definition defines a contract between the object builder and the interaction builder.
The device definition states the following info:
- The events it can emit
- The functions that it can execute
e.g The device definition of a simple switch would be
events: OnSwitchOn and OnSwitchOff.
The device definition if a simple lamp would be
Function: LightOn and LightOff
In object oriented term, the device definition is like an interface. The wikkiot server uses the device definition (interface) to interact with the device without knowing the details of the device. And the device needs to implement the device definition (interface) and need not to know what the wikkiot server will do with it.
The device definition is identified a bit like a maven dependency. The following fields are required
1. definitionId
2. groupId
3. versionId
A device builder can build a device definition and publish it on a device definition registry
Device definition for a simple lamp
import org.castafiore.iot.definitions.DefinitionBuilder
DeviceDefinition lamp = DefinitionBuilder.create("Lamp", "eucleed.iot", "1.0")
.addFunction("SwitchOn", "Switch on lamp")
.addFunction("SwitchOff", "Switch off lamp")
.build();
Device definition of a switch
DeviceDefinition remote = DefinitionBuilder.create("Remote", "eucleed.iot", "1.0")
.addEvent("OnSwitchOn", "When switch on is pressed on remote")
.addEvent("OnSwitchOff", "When Switch off is pressed on remote")
.build();
Publish a definition
DefinitionRegistryClient client = new DefinitionRegistryClient(ENDPOINT);
client.publishDefinition(remote);
Retrieve a definition
DefinitionRegistryClient client = new DefinitionRegistryClient(ENDPOINT);
DeviceDefinition definition = client.getDefinition("Lamp", "eucleed.iot", "1.0");