mosquitto

package
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

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

View Source
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
)
View Source
const (
	MOSQ_DEFAULT_PORT        = 1883
	MOSQ_DEFAULT_SECURE_PORT = 8883
)
View Source
const (
	MQTT_PROTOCOL_V31  = int(C.MQTT_PROTOCOL_V31)
	MQTT_PROTOCOL_V311 = int(C.MQTT_PROTOCOL_V311)
)

Variables

This section is empty.

Functions

func Cleanup

func Cleanup() error

Cleanup should be called when use of library is finished

func Init

func Init() error

Init initiaizes the library

func Version

func Version() (int, int, int)

Version returns major, minor and revision of the mosquitto client library

Types

type Client

type Client C.struct_mosquitto

func New

func New(clientId string, clean bool, userInfo unsafe.Pointer) (*Client, error)

New is called to create a new empty client object

func (*Client) Connect

func (this *Client) Connect(host 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

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) Destroy

func (this *Client) Destroy() error

Destroy is called when you have finished using a client

func (*Client) Disconnect

func (this *Client) Disconnect() error

Disconnect from a broker

func (*Client) Loop

func (this *Client) Loop(timeout_ms int) error

Loop for a specific period of time

func (*Client) LoopForever

func (this *Client) LoopForever(timeout_ms int) error

Loop and perform actions on a regular basis.

func (*Client) LoopStart

func (this *Client) LoopStart() error

Start the event loop thread, to be called before Connect

func (*Client) LoopStop

func (this *Client) LoopStop(force bool) error

Stop the event loop thread, to be called after Disconnect has completed

func (*Client) Publish

func (this *Client) Publish(topic string, data []byte, qos int, retain bool) (int, error)

Publish a message to the broker in a topic and return the id of the request

func (*Client) Reconnect

func (this *Client) Reconnect(async bool) error

Reconnect to a broker when disconnect has occured.

func (*Client) Reinitialise

func (this *Client) Reinitialise(clientId string, clean bool, userInfo unsafe.Pointer) error

Reinitalize a client object

func (*Client) SetCredentials

func (this *Client) SetCredentials(user, password string) error

Set username and password for connecting to a broker. Call this before Connect

func (*Client) SetProtocol

func (this *Client) SetProtocol(protocol int) error

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

func (this *Client) SetReconnectDelay(delay, max uint, exponential bool) error

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

func (c *Client) SetTLS(capath, certpath, keypath string) error

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

func (c *Client) SetTLSInsecure(v bool) error

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.

func (*Client) SetUserInfo

func (this *Client) SetUserInfo(userInfo unsafe.Pointer) error

func (*Client) Subscribe

func (this *Client) Subscribe(topics string, qos int) (int, error)

Subscribe to one set of topics and return the id of the request

func (*Client) Unsubscribe

func (this *Client) Unsubscribe(topics string) (int, error)

Unsubscribe from one set of topics and return the id of the request

type ClientEx

func NewEx

func NewEx(clientId string, clean bool) (*ClientEx, error)

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) Destroy

func (c *ClientEx) Destroy() error

Destroy is called when you have finished using a client

func (*ClientEx) Reinitialise

func (c *ClientEx) Reinitialise(clientId string, clean bool) error

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 Error

type Error int

func (Error) Error

func (e Error) Error() string

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) String

func (f Level) String() string

func (Level) StringFlag

func (f Level) StringFlag() string

type LogCallback

type LogCallback func(Level, string) // Log(level Level, message string)

type Message

func NewMessage

func NewMessage(id int) *Message

func (*Message) Copy

func (this *Message) Copy() *Message

func (*Message) Data

func (this *Message) Data() []byte

func (*Message) Free

func (this *Message) Free()

func (*Message) FreeContents

func (this *Message) FreeContents()

func (*Message) Id

func (this *Message) Id() int

func (*Message) Len

func (this *Message) Len() uint

func (*Message) Qos

func (this *Message) Qos() int

func (*Message) Retain

func (this *Message) Retain() bool

func (*Message) String

func (this *Message) String() string

func (*Message) Topic

func (this *Message) Topic() string

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
)

func (Option) String

func (v Option) String() string

type PublishCallback

type PublishCallback func(int) // Publish(message_id int)

type SubscribeCallback

type SubscribeCallback func(int, []int) // Subscribe(message_id int, granted_qos []int)

type UnsubscribeCallback

type UnsubscribeCallback func(int) // Unsubscribe(message_id int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL