Skip to content

Commit e6e7ce9

Browse files
committed
Added verbosity for nmqtt_pub
1 parent c6adb1f commit e6e7ce9

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/nmqtt_pub.nim

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ from os import getCurrentProcessId
44
include "nmqtt.nim"
55

66

7-
proc nmqttPub(host="127.0.0.1", port: int=1883, ssl:bool=false, clientid="", username="", password="", topic, msg: string, qos=0, retain=false, repeat=0, repeatdelay=0, willtopic="", willmsg="", willqos=0, willretain=false, verbose=false) =
7+
proc handler() {.noconv.} =
8+
## Catch ctrl+c from user
9+
echo ""
10+
quit(0)
11+
12+
13+
proc nmqttPub(host="127.0.0.1", port=1883, ssl=false, clientid="", username="", password="", topic, msg: string, qos=0, retain=false, repeat=0, repeatdelay=0, willtopic="", willmsg="", willqos=0, willretain=false, verbosity=0) =
814
## CLI tool for publish
15+
if verbosity >= 1:
16+
echo "Running nmqtt_pub v" & nmqttVersion
17+
918
let ctx = newMqttCtx(if clientid != "": clientid else: "nmqttpub-" & $getCurrentProcessId())
1019
ctx.set_host(host, port, ssl)
1120

@@ -19,6 +28,12 @@ proc nmqttPub(host="127.0.0.1", port: int=1883, ssl:bool=false, clientid="", use
1928
elif willtopic != "" and willmsg != "":
2029
ctx.set_will(willtopic, willmsg, willqos, willretain)
2130

31+
# Set the verbosity
32+
ctx.set_verbosity(verbosity)
33+
34+
# Control CTRL+c hook
35+
setControlCHook(handler)
36+
2237
# Connect to broker
2338
waitFor ctx.connect()
2439

0 commit comments

Comments
 (0)