当前位置: 首页>>代码示例>>Golang>>正文


Golang MqttClient.PublishMessage方法代码示例

本文整理汇总了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
}
开发者ID:hakobera,项目名称:osx-cpu-temp,代码行数:11,代码来源:main.go

示例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)
		}
	}
}
开发者ID:mackristof,项目名称:golang-weather-station,代码行数:16,代码来源:main.go


注:本文中的git/eclipse/org/gitroot/paho/org/eclipse/paho/mqtt/golang/git.MqttClient.PublishMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。