Skip to content

Commit 69ee315

Browse files
committed
Update README and inline code examples
1 parent 175c509 commit 69ee315

2 files changed

Lines changed: 38 additions & 94 deletions

File tree

README.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Native Nim MQTT client library
1+
# Native Nim MQTT client library and binaries
22

33
This is a hybrid package including a native Nim MQTT library and
44
binaries for a MQTT broker, publisher and subscriber.
@@ -39,6 +39,8 @@ The package provides 4 MQTT binaries:
3939
## nmqtt
4040
```
4141
$ nmqtt --help
42+
nmqtt version 1.0.0
43+
4244
nmqtt is a MQTT v3.1.1 broker
4345
4446
USAGE
@@ -68,14 +70,17 @@ OPTIONS
6870
--client-kickold kick old client, if new client has same clientid. Defaults to false.
6971
--clientid-pass pass clientid in payload {clientid:payload}. Defaults to false.
7072
--password-file= absolute path to the password file
73+
--ssl activate ssl for the broker - requires --ssl-cert and --ssl-key.
74+
--ssl-cert= absolute path to the ssl certificate.
75+
--ssl-key= absolute path to the ssl key.
7176
```
72-
_SSL is not supported_
7377

7478

7579
## nmqtt_password
7680
```
7781
$ nmqtt_password --help
78-
Add users and passwords to nmqtt's password file.
82+
nmqtt_password is a user and password manager for nmqtt
83+
nmqtt_password is based upon nmqtt version 1.0.0
7984
8085
USAGE
8186
nmqtt_password -a {password_file.conf} {username}
@@ -89,76 +94,71 @@ OPTIONS
8994
-?, --help print this cligen-erated help
9095
-a, --adduser add a new user to the password file.
9196
-b, --batch run in batch mode to allow passing passwords on the command line.
92-
-d, --deluser delete a user form the password file.
97+
-d, --deluser delete a user from the password file.
9398
```
9499

95100

96101
## nmqtt_pub
97102
```
98103
$ ./nmqtt_pub --help
99-
Publish MQTT messages to a MQTT-broker.
104+
nmqtt_pub is a MQTT client for publishing messages to a MQTT-broker.
105+
nmqtt_pub is based upon nmqtt version 1.0.0
100106
101107
Usage:
102108
nmqtt_pub [options] -t {topic} -m {message}
103109
nmqtt_pub [-h host -p port -u username -P password] -t {topic} -m {message}
104110
105111
OPTIONS
106-
-?, --help print this cligen-erated help
107-
--help-syntax advanced: prepend,plurals,..
108-
-h=, --host= IP-address of the broker.
109-
-p=, --port= network port to connect too.
110-
--ssl enable ssl. Auto-enabled on port 8883.
111-
-c=, --clientid= your connection ID. Defaults to nmqtt_pub_ appended with processID.
112-
-u=, --username= provide a username
113-
-P=, --password= provide a password
114-
-t=, --topic= mqtt topic to publish to.
115-
-m=, --msg= message payload to send.
116-
-q=, --qos= quality of service level to use for all messages.
117-
-r, --retain retain messages on the broker.
118-
--repeat= repeat the publish N times.
119-
--repeatdelay= if using --repeat, wait N seconds between publish. Defaults to 0.
120-
--removeretained clear any received retained messages
121-
--willtopic= set the will's topic
122-
--willmsg= set the will's message
123-
--willqos= set the will's quality of service
124-
--willretain set to retain the will message
125-
-v, --verbose set verbose
112+
-?, --help print this cligen-erated help
113+
-h=, --host= IP-address of the broker.
114+
-p=, --port= network port to connect too.
115+
--ssl use ssl.
116+
-c=, --clientid= your connection ID. Defaults to nmqttpub- appended with processID.
117+
-u=, --username= provide a username
118+
-P=, --password= provide a password
119+
-t=, --topic= mqtt topic to publish to.
120+
-m=, --msg= message payload to send.
121+
-q=, --qos= quality of service level to use for all messages.
122+
-r, --retain retain messages on the broker.
123+
--repeat= repeat the publish N times.
124+
--repeatdelay= if using --repeat, wait N seconds between publish. Defaults to 0.
125+
--willtopic= set the will's topic
126+
--willmsg= set the will's message
127+
--willqos= set the will's quality of service
128+
--willretain set to retain the will message
129+
-v=, --verbosity= set the verbosity level from 0-2. Defaults to 0.
126130
```
127131

128-
_`-verbose` not implemented yet_
129-
130132

131133
## nmqtt_sub
132134
```
133135
$ ./nmqtt_sub --help
134-
Subscribe to a topic on a MQTT-broker.
136+
nmqtt_sub is a MQTT client that will subscribe to a topic on a MQTT-broker.
137+
nmqtt_sub is based upon nmqtt version 1.0.0
135138
136139
Usage:
137140
nmqtt_sub [options] -t {topic}
138141
nmqtt_sub [-h host -p port -u username -P password] -t {topic}
139142
140143
OPTIONS
141144
-?, --help print this cligen-erated help
142-
--help-syntax advanced: prepend,plurals,..
143145
-h=, --host= IP-address of the broker. Defaults to 127.0.0.1
144146
-p=, --port= network port to connect too. Defaults to 1883.
145-
--ssl enable ssl. Auto-enabled on port 8883.
146-
-c=, --clientid= your connection ID. Defaults to nmqtt_pub_ appended with processID.
147+
--ssl use ssl.
148+
-c=, --clientid= your connection ID. Defaults to nmqttsub- appended with processID.
147149
-u=, --username= provide a username
148150
-P=, --password= provide a password
149-
-t=, --topic= MQTT topic to publish to.
151+
-t=, --topic= MQTT topic to subscribe too. For multipe topics, separate them by comma.
150152
-q=, --qos= quality of service level to use for all messages. Defaults to 0.
151153
-k=, --keepalive= keep alive in seconds for this client. Defaults to 60.
152154
--removeretained clear any retained messages on the topic
153155
--willtopic= set the will's topic
154156
--willmsg= set the will's message
155157
--willqos= set the will's quality of service
156158
--willretain set to retain the will message
157-
-v, --verbose set verbose
159+
-v=, --verbosity= set the verbosity level from 0-2. Defaults to 0.
158160
```
159161

160-
_`-verbose` not implemented yet_
161-
162162

163163
# Library
164164

@@ -250,7 +250,7 @@ ____
250250
### set_host*
251251

252252
```nim
253-
proc set_host*(ctx: MqttCtx, host: string, port: int=1883, doSsl=false) =
253+
proc set_host*(ctx: MqttCtx, host: string, port: int=1883, sslOn=false) =
254254
```
255255

256256
Set the MQTT host

src/nmqtt.nim

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,6 @@
1-
## Native Nim MQTT client library, work in progress
2-
## ---------------
1+
## Native Nim MQTT client library and binaries
32
##
4-
## Examples
5-
## --------
6-
##
7-
## ### Subscribe to topic
8-
## .. code-block::nim
9-
## import nmqtt, asyncdispatch
10-
##
11-
## let ctx = newMqttCtx("hallo")
12-
## ctx.set_host("test.mosquitto.org", 1883)
13-
## #ctx.set_auth("username", "password")
14-
## await ctx.start()
15-
##
16-
## proc mqttSub() {.async.} =
17-
## await ctx.start()
18-
## proc on_data(topic: string, message: string) =
19-
## echo "got ", topic, ": ", message
20-
##
21-
## await ctx.subscribe("nmqtt", 2, on_data)
22-
##
23-
## asyncCheck mqttSub
24-
## runForever()
25-
##
26-
##
27-
## ### Publish msg
28-
## .. code-block::nim
29-
## proc mqttPub() {.async.} =
30-
## await ctx.start()
31-
## await ctx.publish("nmqtt", "hallo", 2)
32-
## await ctx.disconnect()
33-
##
34-
## waitFor mqttPub()
35-
##
36-
## ### Subscribe and publish
37-
## .. code-block::nim
38-
## proc mqttSubPub() {.async.} =
39-
## await ctx.start()
40-
##
41-
## # Callback when receiving on the topic
42-
## proc on_data(topic: string, message: string) =
43-
## echo "got ", topic, ": ", message
44-
##
45-
## # Subscribe to topic the topic `nmqtt`
46-
## await ctx.subscribe("nmqtt", 2, on_data)
47-
## await sleepAsync 500
48-
##
49-
## # Publish a message to the topic `nmqtt`
50-
## await ctx.publish("nmqtt", "hallo", 2)
51-
## await sleepAsync 500
52-
##
53-
## # Disconnect
54-
## await ctx.disconnect()
55-
##
56-
## waitFor mqttSubPub()
57-
##
58-
59-
#{.experimental: "codeReordering".}
3+
## zevv (https://github.com/zevv) & ThomasTJdev (https://github.com/ThomasTJdev)
604

615
import
626
strutils,

0 commit comments

Comments
 (0)