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 }
func brokerClientsHandler(client MQTT.Client, msg MQTT.Message) { brokerClients <- true fmt.Printf("BrokerClientsHandler ") fmt.Printf("[%s] ", msg.Topic()) fmt.Printf("%s\n", msg.Payload()) }
func onMessageReceived(client MQTT.Client, message MQTT.Message) { fmt.Printf("Received message on topic: %s\nMessage: %s\n", message.Topic(), message.Payload()) }