-
Notifications
You must be signed in to change notification settings - Fork 21
/
master_manager.py
89 lines (79 loc) · 2.93 KB
/
master_manager.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
#!/usr/bin/env python
import os
import multiprocessing
import serial
import signal
import argparse
def start_dosenet(mode):
if mode == 0:
os.system('sudo -E bash /home/pi/dosenet-raspberrypi/pocket.sh start')
if mode == 1:
os.system('sudo -E bash /home/pi/dosenet-raspberrypi/pocket.sh test')
def start_D3S(mode):
if mode == 0:
os.system('sudo -E bash /home/pi/dosenet-raspberrypi/D3S.sh start')
if mode == 1:
os.system('sudo -E bash /home/pi/dosenet-raspberrypi/D3S.sh test')
def start_AQ(mode):
if mode == 0:
os.system('sudo -E bash /home/pi/dosenet-raspberrypi/AQ.sh start')
if mode == 1:
os.system('sudo -E bash /home/pi/dosenet-raspberrypi/AQ.sh test')
def start_CO2(mode):
if mode == 0:
os.system('sudo -E bash /home/pi/dosenet-raspberrypi/CO2.sh start')
if mode == 1:
os.system('sudo -E bash /home/pi/dosenet-raspberrypi/CO2.sh test')
def start_Weather(mode):
if mode == 0:
os.system('sudo -E bash /home/pi/dosenet-raspberrypi/weather.sh start')
if mode == 1:
os.system('sudo -E bash /home/pi/dosenet-raspberrypi/weather.sh test')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--test_mode', action='store_true', default=False,
help="Choose whether the devices will start in test mode or not. (Default False)")
test_mode = parser.parse_args().test_mode
if not test_mode:
print('Waiting for NTP to be synced...')
os.system('sudo service ntp stop')
os.system('sudo timeout 60s ntpd -gq')
os.system('sudo service ntp start')
try:
ser = serial.Serial('/dev/ttyACM0')
ser.flushInput()
ser.close()
except:
pass
if test_mode:
p = multiprocessing.Process(target=start_D3S, args=(1,))
t = multiprocessing.Process(target=start_dosenet, args=(1,))
a = multiprocessing.Process(target=start_AQ, args=(1,))
c = multiprocessing.Process(target=start_CO2, args=(1,))
w = multiprocessing.Process(target=start_Weather, args=(1,))
else:
p = multiprocessing.Process(target=start_D3S, args=(0,))
t = multiprocessing.Process(target=start_dosenet, args=(0,))
a = multiprocessing.Process(target=start_AQ, args=(0,))
c = multiprocessing.Process(target=start_CO2, args=(0,))
w = multiprocessing.Process(target=start_Weather, args=(0,))
try:
print('Starting D3S script process')
p.start()
print('Starting Pocket Geiger script process')
t.start()
print('Starting Air Quality Sensor script process')
a.start()
print('Starting CO2 sensor script process')
c.start()
print('Starting Weather sensor script process')
w.start()
print('started')
p.join()
t.join()
a.join()
c.join()
w.join()
print('we can reboot here')
except:
pass