diff --git a/examples/mqttpub.py b/examples/mqttpub.py index 42aa563..40b482f 100644 --- a/examples/mqttpub.py +++ b/examples/mqttpub.py @@ -5,9 +5,12 @@ This is the only reliable messaging pattern in the suite, as it automatically will retry if a request is not matched with a response. """ +import sys import pynng import curio +helper = "Usage:\n\tmqttpub.py " + address = "mqtt-quic://127.0.0.1:14567" async def main(): @@ -20,13 +23,16 @@ async def main(): print(f"Connection packet sent.") pubmsg = pynng.Mqttmsg() pubmsg.set_packet_type(3) # 0x03 Publish - pubmsg.set_publish_payload("Hello") - pubmsg.set_publish_topic("topic") - pubmsg.set_publish_qos(1) # qos is 1 + pubmsg.set_publish_payload(sys.argv[3]) + pubmsg.set_publish_topic(sys.argv[1]) + pubmsg.set_publish_qos(int(sys.argv[2])) await mqtt.asend_msg(pubmsg) print(f"Publish packet sent.") if __name__ == "__main__": + if len(sys.argv) != 4: + print(helper) + exit(0) try: curio.run(main) except KeyboardInterrupt: diff --git a/examples/mqttsub.py b/examples/mqttsub.py index 321c033..47ebe1b 100644 --- a/examples/mqttsub.py +++ b/examples/mqttsub.py @@ -5,9 +5,12 @@ This is the only reliable messaging pattern in the suite, as it automatically will retry if a request is not matched with a response. """ +import sys import pynng import curio +helper = "Usage:\n\tmqttsub.py " + address = "mqtt-quic://127.0.0.1:14567" async def main(): @@ -22,7 +25,7 @@ async def main(): print(f"Connection packet sent.") submsg = pynng.Mqttmsg() submsg.set_packet_type(8) # 0x08 Subscribe - submsg.set_subscribe_topic("topic", 1) # topic With Qos 1 + submsg.set_subscribe_topic(sys.argv[1], int(sys.argv[2])) # Topic and qos await mqtt.asend_msg(submsg) print(f"Subscribe packet sent.") while True: @@ -35,6 +38,9 @@ async def main(): print("payload:", rmsg.publish_payload()) if __name__ == "__main__": + if len(sys.argv) != 3: + print(helper) + exit(0) try: curio.run(main) except KeyboardInterrupt: