ctucx.git: sdm2mqtt

Publish data from SDM120M meters via MQTT

commit d16ff597a3de39b682541d9f5a043acda1f3c50e
parent 62bedcaf15af23c85354428fa1edafa1c2a67c2e
Author: Leah (ctucx) <git@ctu.cx>
Date: Tue, 13 Dec 2022 14:47:16 +0100

implement mqtt-auth
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/sdm2mqtt.nim b/src/sdm2mqtt.nim
@@ -1,6 +1,6 @@
 import std/[asyncdispatch, asyncnet]
 import std/[os, posix]
-import std/[tables, json]
+import std/[tables, json, options]
 import std/math
 import nmqtt
 

@@ -79,6 +79,11 @@ proc main () {.async.} =
 
   mqttContext = newMqttCtx("sdm2mqtt")
   mqttContext.set_host(config.mqtt.host, config.mqtt.port)
+  mqttContext.set_verbosity(1)
+
+  if (config.mqtt.username.isSome and config.mqtt.password.isSome):
+    mqttContext.set_auth(config.mqtt.username.get, config.mqtt.password.get)
+
   await mqttContext.start()
 
   asyncCheck updatePowermeters(config)