/*
SendTestResult sends the ping to MQTT broker
*/
SendTestResult sends the ping to MQTT broker
/ * SendTestResult sends the ping to MQTT broker * /
func SendTestResult(p interface{}, cfg config.MQTTConfig) {
	opts := MQTT.NewClientOptions()
	opts.AddBroker(fmt.Sprintf("tcp://%s:%s", cfg.Host, cfg.Port))
	opts.SetClientID(cfg.ClientName)
	if cfg.User != "" {
		log.Println("Using user:", cfg.User)
		opts.SetUsername(cfg.User)
	}
	if cfg.Pass != "" {
		log.Println("Using pass: ***")
		opts.SetPassword(cfg.Pass)
	}
	log.Println("Connecting to:", fmt.Sprintf("tcp://%s:%s", cfg.Host, cfg.Port))
	client := MQTT.NewClient(opts)
	if token := client.Connect(); token.Wait() && token.Error() != nil {
		log.Println("Failed to conect to broker")
		panic(token.Error())
	}
	log.Println("Sample Publisher Started")
	log.Println("---- doing publish ----")
	token := client.Publish(cfg.Topic, cfg.Qos, false, serialize(p))
	token.Wait()
	client.Disconnect(250)
	log.Println("Sample Publisher Disconnected")
}
func SendTestResult ( p interface { } , cfg config . MQTTConfig ) { opts := MQTT . NewClientOptions ( ) opts . AddBroker ( fmt . Sprintf ( " " , cfg . Host , cfg . Port ) ) opts . SetClientID ( cfg . ClientName ) if cfg . User != " " { log . Println ( " " , cfg . User ) opts . SetUsername ( cfg . User ) } if cfg . Pass != " " { log . Println ( " " ) opts . SetPassword ( cfg . Pass ) } log . Println ( " " , fmt . Sprintf ( " " , cfg . Host , cfg . Port ) ) client := MQTT . NewClient ( opts ) if token := client . Connect ( ) ; token . Wait ( ) && token . Error ( ) != nil { log . Println ( " " ) panic ( token . Error ( ) ) } log . Println ( " " ) log . Println ( " " ) token := client . Publish ( cfg . Topic , cfg . Qos , false , serialize ( p ) ) token . Wait ( ) client . Disconnect ( 250 ) log . Println ( " " ) }
SendTestResult sends the ping to MQTT broker
SendTestResult sends the ping to MQTT broker
//opts.SetCleanSession(*cleansess)