@@ -4,23 +4,24 @@ from os import getCurrentProcessId
44include " nmqtt.nim"
55
66
7- let ctx = newMqttCtx (" nmqtt_sub_ " & $ getCurrentProcessId ())
7+ let ctx = newMqttCtx (" nmqttsub- " & $ getCurrentProcessId ())
88
99
1010proc handler () {.noconv .} =
1111 # # Catch ctrl+c from user
12+ echo " "
1213 waitFor ctx.disconnect ()
1314 quit (0 )
1415
15-
16- proc nmqttSub (host= " 127.0.0.1" , port: int = 1883 , ssl:bool = false , clientid= " " , username= " " , password= " " , topic: string , qos= 0 , keepalive= 60 , removeretained= false , willtopic= " " , willmsg= " " , willqos= 0 , willretain= false , verbose= false ) {.async .} =
16+ proc nmqttSub (host= " 127.0.0.1" , port= 1883 , ssl= false , clientid= " " , username= " " , password= " " , topic: string , qos= 0 , keepalive= 60 , removeretained= false , willtopic= " " , willmsg= " " , willqos= 0 , willretain= false , verbosity= 0 ) {.async .} =
1717 # # CLI tool for subscribe
18- let ctx = newMqttCtx (if clientid != " " : clientid else : " nmqttsub-" & $ getCurrentProcessId ())
18+ if verbosity >= 1 :
19+ echo " Running nmqtt_sub v" & nmqttVersion
20+
21+ if clientid != " " :
22+ ctx.clientid = clientid
1923
20- if port == 8883 :
21- ctx.set_host (host, port, true )
22- else :
23- ctx.set_host (host, port, ssl)
24+ ctx.set_host (host, port, ssl)
2425
2526 if username != " " or password != " " :
2627 ctx.set_auth (username, password)
@@ -35,6 +36,9 @@ proc nmqttSub(host="127.0.0.1", port: int=1883, ssl:bool=false, clientid="", use
3536 elif willtopic != " " and willmsg != " " :
3637 ctx.set_will (willtopic, willmsg, willqos, willretain)
3738
39+ # Set the verbosity
40+ ctx.set_verbosity (verbosity)
41+
3842 # Connec to broker
3943 await ctx.start ()
4044
0 commit comments