-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_exp_nostats.py
executable file
·105 lines (95 loc) · 2.87 KB
/
init_exp_nostats.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
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
#!/usr/bin/python3
# initiate an experiment without waiting for node statistics
# Authors: Dimitrios Zorbas, Yerassyl Batirkhanov
import socket
import sys
import struct
import random
import subprocess
import shlex
import time
if len(sys.argv) < 3:
print("python3 init_exp_f.py -m <U/C>")
sys.exit()
PORT = 8002
BUFFER_SIZE = 512
assets = []
eds = 0
init = random.randint(1, 65535)
passwd = "97079088"
rx2sf = 12 # default value
succ_retries = 2 # do not change this (only for testing)
with open("assets.txt") as file:
next(file)
assets = [l.rstrip() for l in file]
items = assets[0].split(" ")
rx2sf = int(items[3])
for i in range(len(sys.argv)):
if sys.argv[i] == '-m':
sys.argv.pop(i)
mode = sys.argv.pop(i)
break
if mode == 'U':
for asset in assets:
items = asset.split(" ")
print(asset)
IP = items[1]
reboot_command = 'python3 webrepl/webrepl_client.py -p 97079088 '+str(IP)+' < <(echo -e "import machine" && echo -e "machine.reset()" && echo -e "exit")'
if (items[0] == 'GW'):
src_file = "../gateway/main.py"
remote_path = IP + ":/" + "main.py"
cmd = ['python3', 'webrepl/webrepl_cli.py', '-p', passwd, src_file, remote_path]
p = subprocess.Popen(cmd, stdout = subprocess.PIPE)
for line in p.stdout:
print(line.decode("utf-8"))
p.wait()
reboot_process = subprocess.Popen(reboot_command, shell = True, stdout = subprocess.PIPE, executable='/bin/bash')
time.sleep(2)
reboot_process.kill()
elif (items[0] == 'ED'):
src_file = "../end-device/main.py"
remote_path = IP + ":/" + "main.py"
cmd = ['python3', 'webrepl/webrepl_cli.py', '-p', passwd, src_file, remote_path]
p = subprocess.Popen(cmd, stdout = subprocess.PIPE)
for line in p.stdout:
print(line.decode("utf-8"))
p.wait()
reboot_process = subprocess.Popen(reboot_command, shell = True, stdout = subprocess.PIPE, executable='/bin/bash')
time.sleep(2)
reboot_process.kill()
else:
continue
time.sleep(10)
elif mode == 'C':
print("\nNew experiment with id:", init)
# contact first the NS to update rx2sf
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.0.230', 8001))
MESSAGE = struct.pack('HB', init, rx2sf)
s.send( MESSAGE )
s.close()
except Exception as e:
print("Socket error!", e)
# contact all GWs and EDs
for asset in assets:
MESSAGE = bytes(0)
print(asset)
items = asset.split(" ")
IP = items[1]
if (items[0] == 'GW'):
MESSAGE = struct.pack('HBB', init, int(items[2]), int(items[3]))
elif (items[0] == 'ED'):
eds += 1
MESSAGE = struct.pack('HiiiBBBB', init, int(items[2]), int(items[3]), int(items[4]), int(items[5]), int(items[6]), int(items[7]), succ_retries)
else:
continue
print("Sending to", items[0])
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((IP, PORT))
s.send( MESSAGE )
s.close()
except Exception as e:
print("Socket error!", e)
s.close()