-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocketioCli8.py
More file actions
111 lines (84 loc) · 2.56 KB
/
socketioCli8.py
File metadata and controls
111 lines (84 loc) · 2.56 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import socketio
import time
import os
import json
# Create a Socket.IO client
sio = socketio.Client()
# Define the event handler for the "connect" event
@sio.event
def connect():
print("I'm connected!")
sio.emit('chat message', 'Client8 connected')
# Define the event handler for the "chat message" event
@sio.on('chat message')
def message(data):
print(data)
@sio.on('sizak')
def message():
sizak = True
@sio.on('stop')
def message(data):
if "emergency" in data:
print("Emergency stopping!!")
print("Stopping machines...")
stop = True
# Define the event handler for the "disconnect" event
@sio.event
def disconnect():
print("I'm disconnected!")
sio.connect(dest, transports=['websocket'])
# Specify server address
dest = 'http://10.150.1.11:3000'
# Specify the directory where the JSON files are stored
#json_dir = "meltingM/Advs"
# Get a list of all JSON files in the directory
json_files = [f for f in os.listdir(json_dir) if f.endswith('.json')]
# Sort the list of files
json_files.sort()
# Connect to the server
sio.connect(dest, transports=['websocket'])
sizak = False
stop = False
timeCnt = 0
timeThresh = 60 # 60sec
while True:
if timeCnt == timeThresh:
print("Machine On")
sizak = True
if not sizak:
time.sleep(1)
timeCnt+=1
temp_json_path = os.path.join("cuttingLengthM/Temps", "0.json")
# Open the JSON file and load the data
with open(temp_json_path, 'r') as f:
data = json.load(f)
data = json.dumps(data)
# Now you can use the data from the JSON file
print(f"Loaded Temps data from " + str(data))
sio.emit('sensor Data', data)
else:
# Iterate over each JSON file
for json_file in json_files:
if stop:
break
time.sleep(1)
# Construct the full path to the JSON file
json_path = os.path.join("cuttingLengthM/Advs", json_file)
# Open the JSON file and load the data
with open(json_path, 'r') as f:
data = json.load(f)
data = json.dumps(data)
# Now you can use the data from the JSON file
print(f"Loaded Advs data from " + str(data))
sio.emit('sensor Data', data)
'''
for i in range(100):
time.sleep(0.1)
# Send a message to the server
sio.emit('chat message', 'Hello from Python Client!')
print(i)
'''
# Send a message to the server
sio.emit('chat message', 'Hello from Python Client!')
# Disconnect from the server
sio.disconnect()