Releases: zevv/nmqtt
v1.0.6
v1.0.5
Release of v1.0.5 adds support for:
- fix multi levels wildcard support that must also match zero level (details).
- add support for single level wildcard '+' sign.
Thanks to @lpapier for the PR (#36)
Usage
See tests/subscribe.nim
for examples on use.
Details
http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html#appendix-a
Multi-level wildcard
The number sign (#) is a wildcard character that matches any number of levels within a topic. For example, if you subscribe to finance/stock/ibm/#, you receive messages on these topics:
- finance/stock/ibm
- finance/stock/ibm/closingprice
- finance/stock/ibm/currentprice
The multi-level wildcard can represent zero or more levels. Therefore, finance/# can also match the singular finance, where # represents zero levels. The topic level separator is meaningless in this context, because there are no levels to separate.The multi-level wildcard can be specified only on its own or next to the topic level separator character. Therefore, # and finance/# are both valid, but finance# is not valid. The multi-level wildcard must be the last character used within the topic tree. For example, finance/# is valid but finance/#/closingprice is not valid.
Single-level wildcard
The plus sign (+) is a wildcard character that matches only one topic level. For example, finance/stock/+ matches finance/stock/ibm and finance/stock/xyz, but not finance/stock/ibm/closingprice. Also, because the single-level wildcard matches only a single level, finance/+ does not match finance.The single-level wildcard can be used at any level in the topic tree, and in conjunction with the multilevel wildcard. It must be used next to the topic level separator, except when it is specified on its own. Therefore, + and finance/+ are both valid, but finance+ is not valid. The single-level wildcard can be used at the end of the topic tree or within the topic tree. > For example, finance/+ and finance/+/ibm are both valid.
v1.0.4
Release of v1.0.4 now allows for using wildcards when subscribing.
Thanks to @lmn for the PR.
nmqtt_sub
nmqtt_sub -t test/#
Library
import nmqtt, asyncdispatch
let ctx = newMqttCtx("nmqttClient")
ctx.set_host("test.mosquitto.org", 1883)
proc mqttSub() {.async.} =
await ctx.start()
proc on_data(topic: string, message: string) =
echo "got ", topic, ": ", message
await ctx.subscribe("test/#", 2, on_data)
asyncCheck mqttSub()
runForever()
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()
Release v1.0.2
Release of v1.0.2 has moved required user interaction out of nimble install
. This has been done, so installation of nmqtt
does not block installations of other packages, when it is a dependency.
It is still possible to generate the configuration file by:
- Copy and paste the file from
config/nmqtt.conf
- Clone the repo and
nimble setup
- Run
nimble setup nmqtt