コード例 #1
0
ファイル: main.go プロジェクト: hakobera/osx-cpu-temp
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
0
// 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)
		}
	}
}