Documentation ¶
Overview ¶
Package awsiotdev implements offline queueing and reconnecting features of MQTT protocol.
Example (DebugOut_print) ¶
DebugPrintBackend = func(a ...interface{}) { fmt.Print(a...) } s := &debugOut{true} s.print("Test1:", true) s = &debugOut{false} s.print("Test2:", false) DebugPrintBackend = log.Print
Output: Test1:true
Example (DebugOut_printf) ¶
DebugPrintfBackend = func(format string, a ...interface{}) { fmt.Printf(format, a...) } s := &debugOut{true} s.printf("Formatted value 1 (%d)", 10) s = &debugOut{false} s.printf("Formatted value 2 (%d)", 11) DebugPrintfBackend = log.Printf
Output: Formatted value 1 (10)
Example (DebugOut_println) ¶
DebugPrintlnBackend = func(a ...interface{}) { fmt.Println(a...) } s := &debugOut{true} s.println(errors.New("Error string 1")) s = &debugOut{false} s.println(errors.New("Error string 2")) DebugPrintlnBackend = log.Println
Output: Error string 1
Index ¶
- Variables
- type ConnectHandler
- type ConnectionLostHandler
- type DeviceClient
- func (s *DeviceClient) AddRoute(topic string, callback mqtt.MessageHandler)
- func (s *DeviceClient) Connect() mqtt.Token
- func (s *DeviceClient) Disconnect(quiesce uint)
- func (s *DeviceClient) IsConnected() bool
- func (s *DeviceClient) IsConnectionOpen() bool
- func (s *DeviceClient) OptionsReader() mqtt.ClientOptionsReader
- func (s *DeviceClient) Publish(topic string, qos byte, retained bool, payload interface{}) mqtt.Token
- func (s *DeviceClient) Subscribe(topic string, qos byte, cb mqtt.MessageHandler) mqtt.Token
- func (s *DeviceClient) SubscribeMultiple(filters map[string]byte, callback mqtt.MessageHandler) mqtt.Token
- func (s *DeviceClient) Unsubscribe(topics ...string) mqtt.Token
- type Options
- type TopicPayload
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DebugPrintBackend stores backend function of debug print output. // This can be replaced by custom logger. DebugPrintBackend = log.Print // DebugPrintfBackend stores backend function of debug printf output. // This can be replaced by custom logger. DebugPrintfBackend = log.Printf // DebugPrintlnBackend stores backend function of debug println output. // This can be replaced by custom logger. DebugPrintlnBackend = log.Println )
Functions ¶
This section is empty.
Types ¶
type ConnectHandler ¶
type ConnectHandler func(cli *DeviceClient)
ConnectHandler is the function type for connect callback.
type ConnectionLostHandler ¶
ConnectionLostHandler is the function type for connection lost callback.
type DeviceClient ¶
type DeviceClient struct {
// contains filtered or unexported fields
}
DeviceClient inplements mqtt.Client interface. Publishing messages and subscribing topics are queued in the DeviceClient if the network connection is lost. They are re-tried after the connection is resumed.
func New ¶
func New(opt *Options) *DeviceClient
New returns new MQTT client with offline queueing and reconnecting. Returned client is not connected to the broaker until calling Connect().
func (*DeviceClient) AddRoute ¶
func (s *DeviceClient) AddRoute(topic string, callback mqtt.MessageHandler)
AddRoute is not supported in this package at now.
func (*DeviceClient) Connect ¶
func (s *DeviceClient) Connect() mqtt.Token
Connect create a connection to the broker. Returned token indicates success immediately. Subscription requests and published messages are queued until actual connection establish.
func (*DeviceClient) Disconnect ¶
func (s *DeviceClient) Disconnect(quiesce uint)
Disconnect ends the connection to the broker. Currently, it disconnects immediately and quiesce argument is ignored.
func (*DeviceClient) IsConnected ¶
func (s *DeviceClient) IsConnected() bool
IsConnected returns a bool whether the client is connected to the broker or not.
func (*DeviceClient) IsConnectionOpen ¶
func (s *DeviceClient) IsConnectionOpen() bool
IsConnectionOpen returns a bool whether the client has an active connection to the broker. It is not supported in the latest paho.mqtt.golang release, but will be supported in the future release.
func (*DeviceClient) OptionsReader ¶
func (s *DeviceClient) OptionsReader() mqtt.ClientOptionsReader
OptionsReader returns a ClientOptionsReader of the internal MQTT client.
func (*DeviceClient) Publish ¶
func (s *DeviceClient) Publish(topic string, qos byte, retained bool, payload interface{}) mqtt.Token
Publish publishes a message. Currently, retained arguments are ignored and specified in the options are used.
func (*DeviceClient) Subscribe ¶
func (s *DeviceClient) Subscribe(topic string, qos byte, cb mqtt.MessageHandler) mqtt.Token
Subscribe requests a new subscription for the specified topic. Currently, qos argument is ignored and one specified in the options is used.
func (*DeviceClient) SubscribeMultiple ¶
func (s *DeviceClient) SubscribeMultiple(filters map[string]byte, callback mqtt.MessageHandler) mqtt.Token
SubscribeMultiple requests new subscription for multiple topics. Currently, retained argument is ignored and specified value in the options is used.
func (*DeviceClient) Unsubscribe ¶
func (s *DeviceClient) Unsubscribe(topics ...string) mqtt.Token
Unsubscribe ends the subscriptions for the specified topics.
type Options ¶
type Options struct { KeyPath string CertPath string CaPath string ClientID string Region string BaseReconnectTime time.Duration MaximumReconnectTime time.Duration MinimumConnectionTime time.Duration Keepalive time.Duration URL string Debug bool Qos byte Retain bool Will *TopicPayload OfflineQueueing bool OfflineQueueMaxSize int OfflineQueueDropBehavior string AutoResubscribe bool OnConnect ConnectHandler // OnConnectionLost is called if the MQTT connection is unexpectedly lost. // Pointer to the Options passed as the argument can be modified for the next reconnect. OnConnectionLost ConnectionLostHandler }
Options stores configuration of the MQTT connection.
type TopicPayload ¶
TopicPayload stores a pair of topic name and payload string.
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
internal
|
|
awsiotprotocol
Package awsiotprotocol is internal implementation of awsiotdev package.
|
Package awsiotprotocol is internal implementation of awsiotdev package. |
pubqueue
Package pubqueue is internal implementation of awsiotdev package.
|
Package pubqueue is internal implementation of awsiotdev package. |
subqueue
Package subqueue is internal implementation of awsiotdev package.
|
Package subqueue is internal implementation of awsiotdev package. |
Package presigner implements AWS v4 presigner wrapper for AWS IoT websocket connection.
|
Package presigner implements AWS v4 presigner wrapper for AWS IoT websocket connection. |