v1.0.3
Release of v1.0.3 includes a new proc: set_ssl_certificates*
, where you can specify the path to your cert and key for a SSL connection.
Thanks to @keslerm for the PR.
Proc
proc set_ssl_certificates*(ctx: MqttCtx, sslCert: string, sslKey: string) =
# Sets the SSL Certificate and Key to use when connecting to the remote broker
# for mutal TLS authentication
ctx.sslCert = sslCert
ctx.sslKey = sslKey
Example
import nmqtt, asyncdispatch
let ctx = newMqttCtx("nmqttClient")
ctx.set_host("test.mosquitto.org", 1883)
#ctx.set_auth("username", "password")
#ctx.set_ping_interval(30)
ctx.set_ssl_certificates("cert.crt", "private.key") # <==
proc mqttSub() {.async.} =
await ctx.start()
proc on_data(topic: string, message: string) =
echo "got ", topic, ": ", message
await ctx.subscribe("nmqtt", 2, on_data)
asyncCheck mqttSub
runForever()