Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MqttClient ¶
type MqttClient struct { LocalMqttClient mqtt.Client Options *mqtt.ClientOptions Topics []string // contains filtered or unexported fields }
func MqttClientInit ¶
func MqttClientInit(mqttMessageHandler mqtt.MessageHandler, subTopics []string, broker string) MqttClient
MqttClientInit returns an MqttClient initialised with the MessageHandler function given in mqttMessageHandler, the list of subscribed topics given in subTopics, the broker address given in broker, and default options for the KeepAlive (5 s), PingTimeout (1 s), AutoReconnect (false) and ClientId (a 4 byte hex string). These options can be changed by accessing the mqtt.ClientOptions structure from MqttClient.Options.
func (*MqttClient) Publish ¶
func (mc *MqttClient) Publish(payload interface{}, topic string)
Publish asynchronously publishes the payload on a topic. Prints out an error if it fails.
func (*MqttClient) Start ¶
func (mc *MqttClient) Start() error
Start starts the MQTT client and subscribes to the list of topics given in MqttClientInit
func (*MqttClient) SubscribeToTopic ¶
func (mc *MqttClient) SubscribeToTopic(topic string) error
SubscribeToTopic Subscribe to an additional topic. Ideally, the user should pass all the topics that they want to subscribe to MqttClientInit.