Documentation
¶
Overview ¶
Package okiffsdk provides Go bindings for the Okiff MQTT SDK. It wraps a prebuilt static library (libokiff_sdk.a) via CGo.
Index ¶
- type ConnectionHandler
- type MessageHandler
- type SDK
- func (s *SDK) Connect() bool
- func (s *SDK) Destroy()
- func (s *SDK) Disconnect()
- func (s *SDK) Init(clientId, brokerHost, protocol, username, password string) error
- func (s *SDK) IsConnected() bool
- func (s *SDK) OnConnection(h ConnectionHandler)
- func (s *SDK) OnMessage(h MessageHandler)
- func (s *SDK) Publish(topic, payload string, qos int, retained bool)
- func (s *SDK) Stop()
- func (s *SDK) Subscribe(topic string, qos int) bool
- func (s *SDK) Unsubscribe(topic string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnectionHandler ¶
ConnectionHandler is called on every connection state change. connected: true = connected, false = disconnected or lost. rc: 0 = clean disconnect, -1 = unexpected loss.
type MessageHandler ¶
type MessageHandler func(topic, payload string)
MessageHandler is called when a message arrives on a subscribed topic.
type SDK ¶
type SDK struct {
// contains filtered or unexported fields
}
SDK is the main client handle. Create one with New().
func (*SDK) Connect ¶
Connect establishes the connection to the broker. Returns true on success, false on failure.
func (*SDK) Disconnect ¶
func (s *SDK) Disconnect()
Disconnect gracefully disconnects from the broker.
func (*SDK) IsConnected ¶
IsConnected returns the current connection state.
func (*SDK) OnConnection ¶
func (s *SDK) OnConnection(h ConnectionHandler)
OnConnection registers a callback invoked on every connection state change. Replaces any previously registered handler.
func (*SDK) OnMessage ¶
func (s *SDK) OnMessage(h MessageHandler)
OnMessage registers a callback invoked when a message arrives on any subscribed topic. Replaces any previously registered handler.
func (*SDK) Publish ¶
Publish sends a message to a topic. qos: 0 = at most once, 1 = at least once, 2 = exactly once. retained: broker stores the message for future new subscribers.
func (*SDK) Stop ¶
func (s *SDK) Stop()
Stop stops all activity and releases all resources. Must be called as the final cleanup step, after Disconnect.
func (*SDK) Subscribe ¶
Subscribe registers a subscription on the given topic. Returns true on success, false on failure.
func (*SDK) Unsubscribe ¶
Unsubscribe removes a topic subscription.