-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_mqtt.py
55 lines (42 loc) · 1.33 KB
/
test_mqtt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Test program for MQTT version of QDSpy
Copyright (c) 2024 Thomas Euler
All rights reserved.
2024-08-03 - Initial version
"""
# ---------------------------------------------------------------------
__author__ = "code@eulerlab.de"
import platform
import time
import sys
import Libraries.mqtt_client as mqtt
import Libraries.mqtt_globals as mgl
PLATFORM_WINDOWS = platform.system() == "Windows"
if not PLATFORM_WINDOWS:
WindowsError = FileNotFoundError
# ---------------------------------------------------------------------
def handleMsg(_msg) -> None:
pass
# ---------------------------------------------------------------------
if __name__ == "__main__":
if len(sys.argv) == 1:
# If no command line argument, exit
print("No arguments")
sys.exit()
iMsg = 0
mqtt.Client.handler = handleMsg
mqtt.Client.connect(ID=mgl.UUID, _isServ=False)
mqtt.Client.start()
# Convert command line arguments
arg = sys.argv[1].split(",")
msg = f"{arg[0]},{iMsg}"
if len(arg[1:]) > 0:
msg = msg +"," +",".join(arg[1:])
mqtt.Client.publish(msg, _doWait=True)
tDone = time.time() +1.0
while tDone > time.time():
time.sleep(0.02)
mqtt.Client.stop()
# ---------------------------------------------------------------------