本文整理汇总了Golang中git/eclipse/org/gitroot/paho/org/eclipse/paho/mqtt/golang/git.MqttClient.PublishMessage方法的典型用法代码示例。如果您正苦于以下问题:Golang MqttClient.PublishMessage方法的具体用法?Golang MqttClient.PublishMessage怎么用?Golang MqttClient.PublishMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git/eclipse/org/gitroot/paho/org/eclipse/paho/mqtt/golang/git.MqttClient
的用法示例。
在下文中一共展示了MqttClient.PublishMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Publish
func Publish(client *MQTT.MqttClient, topic string, payload []byte) {
message := MQTT.NewMessage(payload)
message.SetQoS(0)
receipt := client.PublishMessage(topic, message)
fmt.Println("publish:")
fmt.Printf("TOPIC: %s\n", topic)
fmt.Printf("MSG: %s\n", message.Payload())
<-receipt
}
示例2: PostCurrentData
// post WeatherData structure on JSON to MQTT topic
func PostCurrentData(dataChannel <-chan *weatherStation.WeatherData, mqttClient *MQTT.MqttClient, opts *MQTT.ClientOptions) {
//log.Println("start posting data")
for {
currentWeather := <-dataChannel
//fmt.Printf("#########################getting data =%+v\n", currentWeather)
jsonWeather, err := json.Marshal(currentWeather)
//fmt.Printf("#########################sended data =%s\n", jsonWeather)
check(err)
msg := MQTT.NewMessage(jsonWeather)
reconnectMqttBroker(mqttClient, opts)
if mqttConnected {
mqttClient.PublishMessage("/mackristof/weather-mtp/davis1", msg)
}
}
}