Skip to content
Snippets Groups Projects
Commit 5b53098d authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Fix Subscribe API / Cleaned jsonDump API

parent f57b637f
No related branches found
No related tags found
No related merge requests found
......@@ -31,13 +31,13 @@ func MQTTSetup(cfg *Config, publishHandler mqtt.MessageHandler) mqtt.Client {
return client
}
func MQTTSubscribe(client mqtt.Client, cfg *Config) error {
token := client.Subscribe(cfg.topic+"/#", 0, nil)
if err := token.Wait(); token.Error() != nil {
return fmt.Errorf("failed to subscribe to topic '%s/#': %v", cfg.topic, err)
func MQTTSubscribe(client mqtt.Client, cfg *Config) {
topic := cfg.topic + "/#"
token := client.Subscribe(topic, 0, nil)
if token.Wait(); token.Error() != nil {
slog.Warn("MQTTSubscribe failed", "topic", topic, "err", token.Error())
}
slog.Debug("Subscribed to", "Topic", cfg.topic+"/#")
return nil
slog.Debug("Subscribed to", "Topic", topic)
}
func MQTTLostCnx(client mqtt.Client, err error) {
......@@ -51,5 +51,5 @@ func MQTTDumpMsg(msg mqtt.Message) {
if err != nil {
slog.Error("Error decoding JSON %v", "topic", msg.Topic(), "err", err)
}
jsonDump(data)
jsonDump("MQTT update", data)
}
......@@ -24,7 +24,7 @@ func hexStringToInteger(hexString string) (uint64, error) {
return integerValue, nil
}
func jsonDump(data map[string]interface{}) {
func jsonDump(title string, data map[string]interface{}) {
// sort keys
keys := make([]string, 0)
for key := range data {
......@@ -33,7 +33,7 @@ func jsonDump(data map[string]interface{}) {
sort.Strings(keys)
// dump keys
tab := table.NewWriter()
tab.SetTitle("MQTT update")
tab.SetTitle(title)
tab.SetStyle(table.StyleRounded)
for _, key := range keys {
if key != "update" {
......
......@@ -526,5 +526,5 @@ func NewDebugDevice(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInte
func (dev *DebugDevice) update(payload map[string]interface{}) {
slog.Info("Debug Device update", "payload", payload)
jsonDump(payload)
jsonDump("Debug Device update", payload)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment