示例#1
0
func OnMessageReceived(client MQTT.Client, message MQTT.Message) {
	buf := message.Payload()
	log.Infof("topic:%s / msg:%s", message.Topic(), buf)

	// analyze temperture data
	err, c, e := enocean.NewESPData(buf)
	if err != nil {
		log.Errorf("ERROR: %v, parse failed on $v, cosumed %v", err, buf, c)
	}
	temp := (255 - int(e.PayloadData[2])) * 40.0 / 255
	err, m := enocean.GetManufacturerName(e.ManufacturerId)
	if err != nil {
		log.Errorf("ERROR: %v, manufacturer ID is wrong", e.ManufacturerId)
	}
	msg := fmt.Sprintf("{\"RawData\": \"%v\", \"TeachIn\": %v, \"manufactuererId\": \"%v\", \"temperature\": %v}", e, e.TeachIn, m, temp)
	fmt.Println(msg)
	msgPipe <- msg
}
示例#2
0
func brokerClientsHandler(client MQTT.Client, msg MQTT.Message) {
	brokerClients <- true
	fmt.Printf("BrokerClientsHandler      ")
	fmt.Printf("[%s]  ", msg.Topic())
	fmt.Printf("%s\n", msg.Payload())
}
示例#3
0
func onMessageReceived(client MQTT.Client, message MQTT.Message) {
	fmt.Printf("Received message on topic: %s\nMessage: %s\n", message.Topic(), message.Payload())
}