-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFakeUR10_reader.py
More file actions
36 lines (28 loc) · 854 Bytes
/
Copy pathFakeUR10_reader.py
File metadata and controls
36 lines (28 loc) · 854 Bytes
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
# Code used to publish fake data to HiveMQ MQTT broker
from HiveMQConnect import HiveClient
import time
def fakeDataGen():
while True:
with open("UR10Output.txt", "r") as file:
while True:
text = file.readline()
if not text:
break
yield text
if __name__ == '__main__':
print("Starting up...")
iterator = fakeDataGen()
getter = (lambda : next(iterator))
time_out = 0.02
hqt_client = HiveClient()
hqt_client.connect_and_loop_start()
print("Running...")
try:
while True:
time.sleep(time_out)
message = getter()
print(message)
hqt_client.publish("DT/UR10", message)
except KeyboardInterrupt:
print("Stopping...")
hqt_client.loop_stop_and_disconnect()