Skip to content

Releases: zevv/nmqtt

v1.0.6

11 Feb 11:08
3e4157e
Compare
Choose a tag to compare
Bump version

v1.0.5

14 Jan 09:59
2bc6c76
Compare
Choose a tag to compare

Release of v1.0.5 adds support for:

  1. fix multi levels wildcard support that must also match zero level (details).
  2. 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:

  1. finance/stock/ibm
  2. finance/stock/ibm/closingprice
  3. 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

17 Oct 05:19
Compare
Choose a tag to compare

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

10 Jul 10:15
Compare
Choose a tag to compare

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

26 Apr 12:20
Compare
Choose a tag to compare

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:

  1. Copy and paste the file from config/nmqtt.conf
  2. Clone the repo and nimble setup
  3. Run nimble setup nmqtt