Skip to content

Commit 5dee1eb

Browse files
committed
Added comments in code
1 parent d6fa65f commit 5dee1eb

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

src/nmqtt_pub.nim

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ proc nmqttPub(host="127.0.0.1", port: int=1883, ssl:bool=false, clientid="", use
99
let ctx = newMqttCtx(if clientid != "": clientid else: "nmqtt_pub_" & $getCurrentProcessId())
1010
ctx.set_host(host, port, ssl)
1111

12+
# Set the will message
1213
if willretain and (willtopic == "" or willmsg == ""):
1314
echo "Error: Will-retain giving, but no topic given"
1415
quit()
@@ -51,22 +52,22 @@ $options
5152
doc="Publish MQTT messages to a MQTT-broker.",
5253
cmdName="nmqtt_pub",
5354
help={
54-
"host": "IP-address of the broker.",
55-
"port": "network port to connect too.",
56-
"ssl": "enable ssl. Auto-enabled on port 8883.",
57-
"clientid": "your connection ID. Defaults to nmqtt_pub_ appended with processID.",
58-
"username": "provide a username",
59-
"password": "provide a password",
60-
"topic": "mqtt topic to publish to.",
61-
"msg": "message payload to send.",
62-
"qos": "quality of service level to use for all messages.",
63-
"retain": "retain messages on the broker.",
64-
"repeat": "repeat the publish N times.",
65-
"repeatdelay":"if using --repeat, wait N seconds between publish. Defaults to 0.",
66-
"willtopic":"set the will's topic",
67-
"willmsg": "set the will's message",
68-
"willqos": "set the will's quality of service",
69-
"willretain":"set to retain the will message"
55+
"host": "IP-address of the broker.",
56+
"port": "network port to connect too.",
57+
"ssl": "enable ssl. Auto-enabled on port 8883.",
58+
"clientid": "your connection ID. Defaults to nmqtt_pub_ appended with processID.",
59+
"username": "provide a username",
60+
"password": "provide a password",
61+
"topic": "mqtt topic to publish to.",
62+
"msg": "message payload to send.",
63+
"qos": "quality of service level to use for all messages.",
64+
"retain": "retain messages on the broker.",
65+
"repeat": "repeat the publish N times.",
66+
"repeatdelay": "if using --repeat, wait N seconds between publish. Defaults to 0.",
67+
"willtopic": "set the will's topic",
68+
"willmsg": "set the will's message",
69+
"willqos": "set the will's quality of service",
70+
"willretain": "set to retain the will message"
7071
},
7172
short={
7273
"password": 'P',

src/nmqtt_sub.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,31 @@ proc nmqttSub(host="127.0.0.1", port: int=1883, ssl:bool=false, clientid="", use
2323
else:
2424
ctx.set_host(host, port, ssl)
2525

26+
# Set the ping interval/keep alive
2627
ctx.set_ping_interval(keepalive)
2728

29+
# Set the will message
2830
if willretain and (willtopic == "" or willmsg == ""):
2931
echo "Error: Will-retain giving, but no topic given"
3032
quit(0)
3133
elif willtopic != "" and willmsg != "":
3234
ctx.set_will(willtopic, willmsg, willqos, willretain)
3335

36+
# Connec to broker
3437
await ctx.start()
3538

3639
# Remove retained messages
3740
if removeretained:
3841
waitFor ctx.publish(topic, "", 0, true)
3942

43+
# Callback for subscribe
4044
proc on_data(topic, msg: string) =
4145
echo topic, ": ", msg
4246

47+
# Subscribe to topic
4348
await ctx.subscribe(topic, qos, on_data)
4449

50+
# Control CTRL+c hook
4551
setControlCHook(handler)
4652

4753
runForever()

0 commit comments

Comments
 (0)