mqtt: add Subscribe method; server subscribes and logs incoming messages
This commit is contained in:
@@ -43,6 +43,15 @@ func main() {
|
||||
} else {
|
||||
mq = mqc
|
||||
mqttclient.SetDefault(mqc)
|
||||
|
||||
// subscribe to the configured topic and log incoming messages
|
||||
if cfg.MQTT.Topic != "" {
|
||||
if err := mq.Subscribe(cfg.MQTT.Topic, func(t string, p []byte) {
|
||||
log.Printf("mqtt recv on %s: %s", t, string(p))
|
||||
}); err != nil {
|
||||
log.Printf("warning: mqtt subscribe failed: %v", err)
|
||||
}
|
||||
}
|
||||
// publish a startup message (non-blocking)
|
||||
go func() {
|
||||
msg := fmt.Sprintf("lambdaiot-core started on %s", addr)
|
||||
|
||||
Reference in New Issue
Block a user