package main import ( "fmt" MQTT "github.com/eclipse/paho.mqtt.golang" mqtt "github.com/eclipse/paho.mqtt.golang" ) func publish(client MQTT.Client, bps float32) { topic := "WirelessBandwidth/state" //Payload := "{\"Mbps\":\"" + fmt.Sprintf("%f", bps) + "\"}" token := client.Publish(topic, 1, false, Payload) token.Wait() //fmt.Println(fmt.Sprintf("%f",bps)) } func subscribe(client MQTT.Client, bps float32) { topic := "home/rgbboard" //Payload := "{\"Mbps\":\"" + fmt.Sprintf("%f", bps) + "\"}" sub := client.Subscribe() token := client.Publish(topic, 1, false, Payload) token.Wait() //fmt.Println(fmt.Sprintf("%f",bps)) } var messagePubHandler MQTT.MessageHandler = func(client mqtt.Client, msg mqtt.Message) { fmt.Printf("Received message: %s from topic: %s\n", msg.Payload(), msg.Topic()) } var connectHandler MQTT.OnConnectHandler = func(client mqtt.Client) { fmt.Println("Connected") //topic := "homeassistant/sensor/WirelessBandwidth/config" //Payload := "{\"name\":\"WirelessBandwidth\",\"state_class\":\"measurement\",\"unit_of_measurement\":\"Mbps\", \"device_class\":\"monetary\", \"state_topic\":\"WirelessBandwidth/state\",\"unique_id\":\"WirelessBandwidth\",\"value_template\":\"{{ value_json.Mbps }}\"}" //token := client.Publish(topic, 1, false, Payload) //token.Wait() } var connectLostHandler MQTT.ConnectionLostHandler = func(client mqtt.Client, err error) { fmt.Printf("Connect lost: %v", err) }