Documentation ¶
Overview ¶
Package exposedthing that implements the ExposedThing API Exposed Things are used by IoT device implementers to provide access to the device.
Package exposedthing that implements the ExposedThing MQTT protocol binding
Index ¶
- type ExposedThing
- func (eThing *ExposedThing) Destroy()
- func (eThing *ExposedThing) EmitEvent(name string, data interface{}) error
- func (eThing *ExposedThing) EmitPropertyChange(propName string, newRawValue interface{}, changesOnly bool) error
- func (eThing *ExposedThing) GetThingDescription() *thing.ThingDescription
- func (eThing *ExposedThing) GetValue(key string) (value *thing.InteractionOutput, found bool)
- func (eThing *ExposedThing) HandleActionRequest(actionName string, message []byte)
- func (eThing *ExposedThing) SetActionHandler(actionName string, ...)
- func (eThing *ExposedThing) SetPropertyWriteHandler(propName string, ...)
- type ExposedThingFactory
- func (etFactory *ExposedThingFactory) Connect(address string, mqttPort int) error
- func (etFactory *ExposedThingFactory) Destroy(eThing *ExposedThing)
- func (etFactory *ExposedThingFactory) Disconnect()
- func (etFactory *ExposedThingFactory) Expose(deviceID string, td *thing.ThingDescription) (eThing *ExposedThing, found bool)
- type ExposedThingMqttBinding
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExposedThing ¶
type ExposedThing struct { // deviceID for reverse looking of device by their internal ID DeviceID string // Protocol binding hook to emit an event EmitEventHook func(name string, data interface{}) error // Protocol binding hook to emit a single property change notification EmitPropertyChangeHook func(name string, data interface{}) error // Internal slot with Thing Description document this exposed thing exposes TD *thing.ThingDescription // contains filtered or unexported fields }
func CreateExposedThing ¶
func CreateExposedThing(deviceID string, td *thing.ThingDescription) *ExposedThing
CreateExposedThing constructs an exposed thing from a TD.
An exposed Thing is a local instance of a thing for the purpose of interaction with remote consumers. This is intended for use by the ExposedThingFactory only. Call 'Expose' to publish the TD of the thing and to start listening for actions and property write requests.
* td is a Thing Description document of the Thing to expose. * mqttClient client for binding to the MQTT protocol
func (*ExposedThing) Destroy ¶
func (eThing *ExposedThing) Destroy()
Destroy stops serving external requests this is an internal method for use by the factory
func (*ExposedThing) EmitEvent ¶
func (eThing *ExposedThing) EmitEvent(name string, data interface{}) error
EmitEvent publishes a single event to subscribers. This invokes the EmitEventHook from the protocol binding
name is the name of the event as described in the TD, or one of the general purpose events. data is the event value as defined in the TD events schema and used as the payload Returns an error if the event is not found or cannot be published
func (*ExposedThing) EmitPropertyChange ¶
func (eThing *ExposedThing) EmitPropertyChange( propName string, newRawValue interface{}, changesOnly bool) error
EmitPropertyChange emits a property value change event
This in turn will notify all observers (subscribers) of the change. The new value will be updated in the value store. TODO: validate property exists
propName is the name of the property in the TD newRawValue is the new raw value of the property which will also be stored in the valueStore. changesOnly emit the property change only if the property value has changed.
Returns an error if the property value cannot be published
func (*ExposedThing) GetThingDescription ¶
func (eThing *ExposedThing) GetThingDescription() *thing.ThingDescription
GetThingDescription returns the TD document of this exposed Thing This returns the cached version of the TD
func (*ExposedThing) GetValue ¶
func (eThing *ExposedThing) GetValue(key string) (value *thing.InteractionOutput, found bool)
GetValue reads the latest cached property value from the value store This is concurrent safe and should be the only way to access the values. Returns the InteractionOutput or nill if not found
func (*ExposedThing) HandleActionRequest ¶
func (eThing *ExposedThing) HandleActionRequest(actionName string, message []byte)
HandleActionRequest for this Thing to be invoked by the protocol binding. This passes the request to the registered action handler. If no specific handler is set then the default handler with name "" is invoked.
func (*ExposedThing) SetActionHandler ¶
func (eThing *ExposedThing) SetActionHandler(actionName string, actionHandler func(eThing *ExposedThing, actionName string, value *thing.InteractionOutput) error)
SetActionHandler sets the handler for handling an action for the IoT device.
Only a single handler is active. If a handler is set when a previous handler was already set then the latest handler will be used.
The device code should implement this handler to updated configuration of the device.
actionName is the action name this handler is for. If a single handler can take care of most actions
then use "" as the name to indicate it is the default handler.
The handler should return nil if the write is accepted or an error if not accepted. The property value in the TD will be updated after the property has changed through the change notification handler.
func (*ExposedThing) SetPropertyWriteHandler ¶
func (eThing *ExposedThing) SetPropertyWriteHandler(propName string, writeHandler func(eThing *ExposedThing, propName string, value *thing.InteractionOutput) error)
SetPropertyWriteHandler sets the handler for writing a property of the IoT device. This is intended to update device configuration. If the property is read-only the handler must return an error. Only a single handler is active. If a handler is set when a previous handler was already
set then the latest handler will be used.
The device code should implement this handler to updated configuration of the device.
propName is the property name this handler is for. Use "" for a default handler
The handler should return nil if the request is accepted or an error if not accepted. The property value in the TD will be updated after the property has changed through the change notification handler.
type ExposedThingFactory ¶
type ExposedThingFactory struct {
// contains filtered or unexported fields
}
ExposedThingFactory for managing connected instances of exposed things. Exposed Things are created using the 'expose' method. (the spec also mentions 'produce' and 'exposeInit'. Not clear how that is supposed to work so lets keep it simple.
This factory is intended for IoT devices to produce and expose 'Thing' instances to consumers. It will bind the instance to protocol bindings for publishing TDs, properties and events, and receive action and property change requests as sent by consumed things.
func CreateExposedThingFactory ¶
func CreateExposedThingFactory( appID string, clientCert *tls.Certificate, caCert *x509.Certificate) *ExposedThingFactory
CreateExposedThingFactory creates a factory instance for exposed things.
Intended for use by IoT devices and Hub services. IoT devices authenticate themselves with a client certificate obtained during the provisioning process using the idprov client. Hub services have access to the hub service TLS certificate configured in the Hub configuration file.
appID unique ID of the application instance clientCert with the certificate for authentication caCert previously obtained CA certificate used to validate the server
func (*ExposedThingFactory) Connect ¶
func (etFactory *ExposedThingFactory) Connect(address string, mqttPort int) error
Connect the factory to message bus. This uses the client certificate for authentication.
address of the hub server that runs the mqtt broker mqttPort with port of the mqtt broker for certificate auth
func (*ExposedThingFactory) Destroy ¶
func (etFactory *ExposedThingFactory) Destroy(eThing *ExposedThing)
Destroy stops and removes the exposed thing. This stops listening to external requests.
func (*ExposedThingFactory) Disconnect ¶
func (etFactory *ExposedThingFactory) Disconnect()
Disconnect the factory from the message bus
func (*ExposedThingFactory) Expose ¶
func (etFactory *ExposedThingFactory) Expose(deviceID string, td *thing.ThingDescription) (eThing *ExposedThing, found bool)
Expose creates an exposed thing instance and starts serving external requests for the Thing so that WoT Interactions using Properties and Actions will be possible. This also publishes the TD document of this Thing. Returns the exposed thing with a flag whether an existing thing was returned
type ExposedThingMqttBinding ¶
type ExposedThingMqttBinding struct {
// contains filtered or unexported fields
}
ExposedThingMqttBinding that connects the exposed thing to the message bus
func CreateExposedThingMqttBinding ¶
func CreateExposedThingMqttBinding(eThing *ExposedThing, mqttClient *mqttclient.MqttClient) *ExposedThingMqttBinding
CreateExposedThingMqttBinding constructs a mqtt protocol binding for exposed things.
eThing is the Exposed Thing to bind to mqttClient MQTT client for binding to the MQTT protocol
func (*ExposedThingMqttBinding) EmitEvent ¶
func (binding *ExposedThingMqttBinding) EmitEvent(name string, data interface{}) error
EmitEvent publishes a single event to subscribers. The topic will be things/{thingID}/event/{name} and payload will be the event data. If the event cannot be published, for example it is not defined, an error is returned.
name is the name of the event as described in the TD, or one of the general purpose events. data is the event value as defined in the TD events schema and used as the payload Returns an error if the event is not found or cannot be published
func (*ExposedThingMqttBinding) EmitPropertyChange ¶
func (binding *ExposedThingMqttBinding) EmitPropertyChange(name string, data interface{}) error
EmitPropertyChange sends a proerty change event to subscribers The topic will be things/{thingID}/event/{name} and payload will be the new property value. If the property cannot be published, for example it is not defined, an error is returned.
name is the name of the property as described in the property affordances section of the TD data is the property value as defined in the TD events schema and serialized to json
Returns an error if the event is not found or cannot be published
func (*ExposedThingMqttBinding) Start ¶
func (binding *ExposedThingMqttBinding) Start()
Start subscribes to Thing action requests Publish the Thing's own TD
func (*ExposedThingMqttBinding) Stop ¶
func (binding *ExposedThingMqttBinding) Stop()
Stop unsubscribes from all messages