Documentation ¶
Index ¶
- Constants
- type MqttClient
- func (mqttClient *MqttClient) Connect(clientCert *tls.Certificate, userName string, password string) error
- func (mqttClient *MqttClient) ConnectWithClientCert(pluginID string, clientCertFile string, clientKeyFile string) error
- func (mqttClient *MqttClient) ConnectWithPassword(userName string, password string) error
- func (mqttClient *MqttClient) Disconnect()
- func (mqttClient *MqttClient) Publish(topic string, message []byte) error
- func (MqttClient *MqttClient) SetTimeout(sec int)
- func (mqttClient *MqttClient) Subscribe(topic string, handler func(address string, message []byte))
- func (mqttClient *MqttClient) Unsubscribe(topic string)
- type MqttHubClient
- func (client *MqttHubClient) PublishAction(thingID string, name string, params map[string]interface{}) error
- func (client *MqttHubClient) PublishConfigRequest(thingID string, values map[string]interface{}) error
- func (client *MqttHubClient) PublishEvent(thingID string, event map[string]interface{}) error
- func (client *MqttHubClient) PublishPropertyValues(thingID string, values map[string]interface{}) error
- func (client *MqttHubClient) PublishTD(thingID string, td api.ThingTD) error
- func (client *MqttHubClient) Start() error
- func (client *MqttHubClient) Stop()
- func (client *MqttHubClient) Subscribe(thingID string, ...)
- func (client *MqttHubClient) SubscribeToActions(thingID string, ...)
- func (client *MqttHubClient) SubscribeToConfig(thingID string, ...)
- func (client *MqttHubClient) SubscribeToEvents(thingID string, ...)
- func (client *MqttHubClient) SubscribeToPropertyValues(thingID string, ...)
- func (client *MqttHubClient) SubscribeToTD(thingID string, ...)
- func (client *MqttHubClient) Unsubscribe(thingID string)
- type TopicSubscription
Constants ¶
const ConnectionTimeoutSec = 20
ConnectionTimeoutSec constant with connection and reconnection timeouts
const TLSPort = 8883
TLSPort is the default secure port to connect to mqtt
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MqttClient ¶
type MqttClient struct {
// contains filtered or unexported fields
}
MqttClient client wrapper around pahoClient This addresses problems with reconnect and auto resubscribe while using clean session
func NewMqttClient ¶
func NewMqttClient(hostPort string, caCertFile string) *MqttClient
NewMqttClient creates a new MQTT messenger instance The clientCertFile and clientKeyFile are optional. If provided then they must be signed by the CA used by the broker, so that the broker can authenticate the client. Leave empty when not using client certificates.
hostPort to connect to caCertFile must contain the server CA certificate filename
func (*MqttClient) Connect ¶
func (mqttClient *MqttClient) Connect(clientCert *tls.Certificate, userName string, password string) error
Connect to the MQTT broker If a previous connection exists then it is disconnected first. If no connection is possible this keeps retrying until the timeout is expired. With each retry a backoff period is increased until 120 seconds. The clientID is generated from the hostname and current timestamp.
clientCert to authenticate with client certificate. Use nil to authenticate with username/password userName to authenticate with. Use "" to ignore password to authenticate with. Use "" to ignore
func (*MqttClient) ConnectWithClientCert ¶
func (mqttClient *MqttClient) ConnectWithClientCert(pluginID string, clientCertFile string, clientKeyFile string) error
Connect to the MQTT broker using client certificate authentication
pluginID to connect as (no pass required) clientCertFile optional client certificate to authenticate the client with the broker clientKeyFile optional client key to authenticate the client with the broker
func (*MqttClient) ConnectWithPassword ¶
func (mqttClient *MqttClient) ConnectWithPassword(userName string, password string) error
Connect to the MQTT broker using password authentication If a previous connection exists then it is disconnected first. If no connection is possible this keeps retrying until the timeout is expired. With each retry a backoff period is increased until 120 seconds.
userName to identify as password credentials to identify with
func (*MqttClient) Disconnect ¶
func (mqttClient *MqttClient) Disconnect()
Disconnect from the MQTT broker and unsubscribe from all addresss and set device state to disconnected
func (*MqttClient) Publish ¶
func (mqttClient *MqttClient) Publish(topic string, message []byte) error
Publish a message to a topic address
func (*MqttClient) SetTimeout ¶
func (MqttClient *MqttClient) SetTimeout(sec int)
Set the connection timeout for the client. Must be invoked before the connect() call
func (*MqttClient) Subscribe ¶
func (mqttClient *MqttClient) Subscribe( topic string, handler func(address string, message []byte))
Subscribe to a address If a subscription already exists, it is replaced. topic: address to subscribe to. This supports mqtt wildcards such as + and # handler: callback handler.
func (*MqttClient) Unsubscribe ¶
func (mqttClient *MqttClient) Unsubscribe(topic string)
Unsubscribe a topic and handler if handler is nil then all subscribers to the topic are removed
type MqttHubClient ¶
type MqttHubClient struct {
// contains filtered or unexported fields
}
MqttHubClient is a wrapper around the generic MQTT client with convenience methods for use by plugins, Things and consumers to subscribe to Thing information and publish configuration, events and actions. This implements the IHubConnection API
func NewMqttHubClient ¶
func NewMqttHubClient(hostPort string, caCertFile string, userName string, password string) *MqttHubClient
NewMqttHubClient creates a new hub connection for Things and consumers Consumers use a login name and password to authenticate while Things can use their thingID and shared key obtained during provisioning.
hostPort address and port to connect to caCertFile containing the broker CA certificate for TLS connections userName of user that is connecting, or thingID of device password credentials with secret to verify the identity, eg password or Shared Key
func NewMqttHubPluginClient ¶
func NewMqttHubPluginClient(pluginID string, hostPort string, caCertFile string, clientCertFile string, clientKeyFile string) *MqttHubClient
NewMqttHubClient creates a new hub connection for Plugins Plugins use a client certificate to authenticate.
pluginID is the username (no pass needed) to identify as hostPort address and port to connect to caCertFile containing the broker CA certificate for TLS connections clientCertFile for client authentication clientKeyFile for client authentication
func (*MqttHubClient) PublishAction ¶
func (client *MqttHubClient) PublishAction(thingID string, name string, params map[string]interface{}) error
PublishAction publish a Thing action request to the Hub
func (*MqttHubClient) PublishConfigRequest ¶
func (client *MqttHubClient) PublishConfigRequest(thingID string, values map[string]interface{}) error
PublishConfig publish a Thing configuration request to the Hub
func (*MqttHubClient) PublishEvent ¶
func (client *MqttHubClient) PublishEvent(thingID string, event map[string]interface{}) error
PublishEvent publish a Thing event to the WoST hub Intended to by used by a Thing
func (*MqttHubClient) PublishPropertyValues ¶
func (client *MqttHubClient) PublishPropertyValues(thingID string, values map[string]interface{}) error
PublishPropertyValues publish a Thing property values to the WoST hub Intended to by used by a Thing to publish updates of property values
func (*MqttHubClient) PublishTD ¶
func (client *MqttHubClient) PublishTD(thingID string, td api.ThingTD) error
PublishTD publish a Thing description to the WoST hub Intended to by used by a Thing to publish an update to its TD
func (*MqttHubClient) Start ¶
func (client *MqttHubClient) Start() error
Start the client connection
func (*MqttHubClient) Subscribe ¶
func (client *MqttHubClient) Subscribe( thingID string, handler func(thingID string, msgType string, raw []byte, senderID string))
Subscribe subscribes to messages from Things
func (*MqttHubClient) SubscribeToActions ¶
func (client *MqttHubClient) SubscribeToActions( thingID string, handler func(thingID string, name string, params map[string]interface{}, senderID string))
SubscribeToAction subscribes a handler to requested actions.
func (*MqttHubClient) SubscribeToConfig ¶
func (client *MqttHubClient) SubscribeToConfig( thingID string, handler func(thingID string, config map[string]interface{}, senderID string))
SubscribeToConfig subscribes a handler to the request for configuration updates.
func (*MqttHubClient) SubscribeToEvents ¶
func (client *MqttHubClient) SubscribeToEvents( thingID string, handler func(thingID string, event map[string]interface{}, senderID string))
SubscribeEvents receives Thing events from the WoST hub.
func (*MqttHubClient) SubscribeToPropertyValues ¶
func (client *MqttHubClient) SubscribeToPropertyValues( thingID string, handler func(thingID string, values map[string]interface{}, senderID string))
SubscribePropertyValues receives updates to Thing property values from the WoST Hub
func (*MqttHubClient) SubscribeToTD ¶
func (client *MqttHubClient) SubscribeToTD( thingID string, handler func(thingID string, thingTD api.ThingTD, senderID string))
SubscribeTD subscribes to receive updates to TDs from the WoST Hub
thingID is the full ID of a thing, or "" to subscribe to all thingIDs
func (*MqttHubClient) Unsubscribe ¶
func (client *MqttHubClient) Unsubscribe(thingID string)
Unsubscribe removes thing subscription
type TopicSubscription ¶
type TopicSubscription struct {
// contains filtered or unexported fields
}
TopicSubscription holds subscriptions to restore after disconnect