func Disconnect(m MQTT.Client) error { if m.IsConnected() { m.Disconnect(20) log.Info("client disconnected") } return nil }
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 }
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()) } } }
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) } }