Beispiel #1
0
func Disconnect(m MQTT.Client) error {
	if m.IsConnected() {
		m.Disconnect(20)
		log.Info("client disconnected")
	}
	return nil
}
Beispiel #2
0
func Publish(m MQTT.Client, topic string, payload []byte, qos int, retain bool, sync bool) error {
	token := m.Publish(topic, byte(qos), retain, payload)
	log.Info("published: %v, to topic: %v", string(payload), topic)
	token.Wait()

	return nil
}
Beispiel #3
0
func SubscribeOnConnect(client MQTT.Client) {
	log.Infof("client connected")

	if len(Subscribed) > 0 {
		token := client.SubscribeMultiple(Subscribed, OnMessageReceived)
		token.Wait()
		if token.Error() != nil {
			log.Error(token.Error())
		}
	}
}
Beispiel #4
0
func subscribeBackend(c MQTT.Client, topic string) {
	if token := c.Subscribe(topic, 0, nil); token.Wait() && token.Error() != nil {
		fmt.Println(token.Error())
		os.Exit(1)
	}
}