Documentation
¶
Overview ¶
MQTT client bindings for the Go programming language which bind to https://mosquitto.org/api/files/mosquitto-h.html For more information please see https://github.com/mutablelogic/go-mosquitto/blob/master/README.md
Index ¶
- Constants
- func Cleanup() error
- func Init() error
- func Version() (int, int, int)
- type Client
- func (this *Client) Connect(host string, port int, keepalive int, async bool) error
- func (this *Client) ConnectBind(host, bindAddress string, port int, keepalive int, async bool) error
- func (this *Client) Destroy() error
- func (this *Client) Disconnect() error
- func (this *Client) Loop(timeout_ms int) error
- func (this *Client) LoopForever(timeout_ms int) error
- func (this *Client) LoopStart() error
- func (this *Client) LoopStop(force bool) error
- func (this *Client) Publish(topic string, data []byte, qos int, retain bool) (int, error)
- func (this *Client) Reconnect(async bool) error
- func (this *Client) Reinitialise(clientId string, clean bool, userInfo unsafe.Pointer) error
- func (this *Client) SetCredentials(user, password string) error
- func (this *Client) SetProtocol(protocol int) error
- func (this *Client) SetReconnectDelay(delay, max uint, exponential bool) error
- func (c *Client) SetTLS(capath, certpath, keypath string) error
- func (c *Client) SetTLSInsecure(v bool) error
- func (this *Client) SetUserInfo(userInfo unsafe.Pointer) error
- func (this *Client) Subscribe(topics string, qos int) (int, error)
- func (this *Client) Unsubscribe(topics string) (int, error)
- type ClientEx
- func (c *ClientEx) Destroy() error
- func (c *ClientEx) Reinitialise(clientId string, clean bool) error
- func (c *ClientEx) SetConnectCallback(cb ConnectCallback)
- func (c *ClientEx) SetDisconnectCallback(cb DisconnectCallback)
- func (c *ClientEx) SetLogCallback(cb LogCallback)
- func (c *ClientEx) SetMessageCallback(cb MessageCallback)
- func (c *ClientEx) SetPublishCallback(cb PublishCallback)
- func (c *ClientEx) SetSubscribeCallback(cb SubscribeCallback)
- func (c *ClientEx) SetUnsubscribeCallback(cb UnsubscribeCallback)
- type ConnectCallback
- type DisconnectCallback
- type Error
- type Level
- type LogCallback
- type Message
- func (this *Message) Copy() *Message
- func (this *Message) Data() []byte
- func (this *Message) Free()
- func (this *Message) FreeContents()
- func (this *Message) Id() int
- func (this *Message) Len() uint
- func (this *Message) Qos() int
- func (this *Message) Retain() bool
- func (this *Message) String() string
- func (this *Message) Topic() string
- type MessageCallback
- type Option
- type PublishCallback
- type SubscribeCallback
- type UnsubscribeCallback
Constants ¶
const ( MOSQ_ERR_CONN_PENDING = C.MOSQ_ERR_CONN_PENDING MOSQ_ERR_SUCCESS = C.MOSQ_ERR_SUCCESS MOSQ_ERR_NOMEM = C.MOSQ_ERR_NOMEM MOSQ_ERR_PROTOCOL = C.MOSQ_ERR_PROTOCOL MOSQ_ERR_INVAL = C.MOSQ_ERR_INVAL MOSQ_ERR_NO_CONN = C.MOSQ_ERR_NO_CONN MOSQ_ERR_CONN_REFUSED = C.MOSQ_ERR_CONN_REFUSED MOSQ_ERR_NOT_FOUND = C.MOSQ_ERR_NOT_FOUND MOSQ_ERR_CONN_LOST = C.MOSQ_ERR_CONN_LOST MOSQ_ERR_TLS = C.MOSQ_ERR_TLS MOSQ_ERR_PAYLOAD_SIZE = C.MOSQ_ERR_PAYLOAD_SIZE MOSQ_ERR_NOT_SUPPORTED = C.MOSQ_ERR_NOT_SUPPORTED MOSQ_ERR_AUTH = C.MOSQ_ERR_AUTH MOSQ_ERR_ACL_DENIED = C.MOSQ_ERR_ACL_DENIED MOSQ_ERR_UNKNOWN = C.MOSQ_ERR_UNKNOWN MOSQ_ERR_ERRNO = C.MOSQ_ERR_ERRNO MOSQ_ERR_EAI = C.MOSQ_ERR_EAI MOSQ_ERR_PROXY = C.MOSQ_ERR_PROXY MOSQ_ERR_PLUGIN_DEFER = C.MOSQ_ERR_PLUGIN_DEFER MOSQ_ERR_MALFORMED_UTF8 = C.MOSQ_ERR_MALFORMED_UTF8 MOSQ_ERR_KEEPALIVE = C.MOSQ_ERR_KEEPALIVE MOSQ_ERR_LOOKUP = C.MOSQ_ERR_LOOKUP )
const ( MOSQ_DEFAULT_PORT = 1883 MOSQ_DEFAULT_SECURE_PORT = 8883 )
const ( MQTT_PROTOCOL_V31 = int(C.MQTT_PROTOCOL_V31) MQTT_PROTOCOL_V311 = int(C.MQTT_PROTOCOL_V311) )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client C.struct_mosquitto
func (*Client) Connect ¶
Connect to a broker using host and port, setting the keepalive time in seconds and use 'true' for the async parameter to connect asyncronously
func (*Client) ConnectBind ¶
func (this *Client) ConnectBind(host, bindAddress string, port int, keepalive int, async bool) error
Connect to a broker using host and port, setting the keepalive time in seconds and use 'true' for the async parameter to connect asyncronously. Connects to a specific interface.
func (*Client) LoopForever ¶
Loop and perform actions on a regular basis.
func (*Client) Publish ¶
Publish a message to the broker in a topic and return the id of the request
func (*Client) Reinitialise ¶
Reinitalize a client object
func (*Client) SetCredentials ¶
Set username and password for connecting to a broker. Call this before Connect
func (*Client) SetProtocol ¶
Value must be set to either MQTT_PROTOCOL_V31, MQTT_PROTOCOL_V311, or MQTT_PROTOCOL_V5. Must be set before the client connects. Defaults to MQTT_PROTOCOL_V311.
func (*Client) SetReconnectDelay ¶
Control the behaviour of the client when it has unexpectedly disconnected The default behaviour if this function is not used is to repeatedly attempt to reconnect with a delay of 1 second until the connection succeeds.
func (*Client) SetTLS ¶
SetTLS sets certificate authority, cert and key for TLS connections. The certificate authority can either be a file or path to files. This version does not accept a callback for password, use ClientEx for that.
func (*Client) SetTLSInsecure ¶
SetTLSInsecure configures verification of the server hostname in the server certificate. If value is set to true, it is impossible to guarantee that the host you are connecting to is not impersonating your server.
type ClientEx ¶
type ClientEx struct {
*Client
ConnectCallback
DisconnectCallback
SubscribeCallback
UnsubscribeCallback
PublishCallback
MessageCallback
LogCallback
}
func NewEx ¶
NewEx returns a new client object, with callback support. If the clientId parameter is empty a random clientId will be generated. The clean flag instructs the broker to clean all messages and subscriptions on disconnect https://mosquitto.org/api/files/mosquitto-h.html#mosquitto_new
func (*ClientEx) Reinitialise ¶
Reinitalize a client object
func (*ClientEx) SetConnectCallback ¶
func (c *ClientEx) SetConnectCallback(cb ConnectCallback)
func (*ClientEx) SetDisconnectCallback ¶
func (c *ClientEx) SetDisconnectCallback(cb DisconnectCallback)
func (*ClientEx) SetLogCallback ¶
func (c *ClientEx) SetLogCallback(cb LogCallback)
func (*ClientEx) SetMessageCallback ¶
func (c *ClientEx) SetMessageCallback(cb MessageCallback)
func (*ClientEx) SetPublishCallback ¶
func (c *ClientEx) SetPublishCallback(cb PublishCallback)
func (*ClientEx) SetSubscribeCallback ¶
func (c *ClientEx) SetSubscribeCallback(cb SubscribeCallback)
func (*ClientEx) SetUnsubscribeCallback ¶
func (c *ClientEx) SetUnsubscribeCallback(cb UnsubscribeCallback)
type ConnectCallback ¶
type ConnectCallback func(Error) // Connect(return_code int)
type DisconnectCallback ¶
type DisconnectCallback func(Error) // Disconnect(return_code int)
type Level ¶
type Level int
const ( MOSQ_LOG_NONE Level = 0 MOSQ_LOG_INFO Level = (1 << 0) MOSQ_LOG_NOTICE Level = (1 << 1) MOSQ_LOG_WARNING Level = (1 << 2) MOSQ_LOG_ERR Level = (1 << 3) MOSQ_LOG_DEBUG Level = (1 << 4) MOSQ_LOG_SUBSCRIBE Level = (1 << 5) MOSQ_LOG_UNSUBSCRIBE Level = (1 << 6) MOSQ_LOG_WEBSOCKETS Level = (1 << 7) MOSQ_LOG_MIN = MOSQ_LOG_INFO MOSQ_LOG_MAX = MOSQ_LOG_WEBSOCKETS )
func (Level) StringFlag ¶
type LogCallback ¶
type Message ¶
type Message C.struct_mosquitto_message
func NewMessage ¶
func (*Message) FreeContents ¶
func (this *Message) FreeContents()
type MessageCallback ¶
type MessageCallback func(*Message) // Message(message *Message)
type Option ¶
type Option C.enum_mosq_opt_t
const ( MOSQ_OPT_PROTOCOL_VERSION Option = 1 MOSQ_OPT_SSL_CTX Option = 2 MOSQ_OPT_SSL_CTX_WITH_DEFAULTS Option = 3 MOSQ_OPT_RECEIVE_MAXIMUM Option = 4 MOSQ_OPT_SEND_MAXIMUM Option = 5 MOSQ_OPT_TLS_KEYFORM Option = 6 MOSQ_OPT_TLS_ENGINE Option = 7 MOSQ_OPT_TLS_ENGINE_KPASS_SHA1 Option = 8 MOSQ_OPT_TLS_OCSP_REQUIRED Option = 9 MOSQ_OPT_TLS_ALPN Option = 10 )
type PublishCallback ¶
type PublishCallback func(int) // Publish(message_id int)
type SubscribeCallback ¶
type UnsubscribeCallback ¶
type UnsubscribeCallback func(int) // Unsubscribe(message_id int)