-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.py
61 lines (52 loc) · 1.91 KB
/
controller.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
#A program to control coordinate gathering and transmission
#Arguments are as follows: python controller.py <ID> <Mode>
#Mode can be either transmitter or reciever.
import os
import sys
import subprocess
from gps_python import getGPS
def main():
if(len(sys.argv) != 3):
print("Incorrect number of arguments")
print("Arguments are as follows: python controller.py <ID> <Mode>")
return
node_id = sys.argv[1]
node_mode = sys.argv[2]
if(node_mode != "sender" and node_mode != "reciever"):
print("Mode must be either sender or reciever")
return
if(node_mode == "sender"):
while(1):
gps_info = getGPS()
gps_info = str(sys.argv[1]) + ": " + gps_info
print(gps_info)
subprocess.call(["sudo", "./dragino_lora_app", "sender", gps_info])
if(node_mode == "reciever"):
while(1):
output = subprocess.check_output(["sudo", "./dragino_lora_app", "rec"])
longitude = 0
latitude = 0
time = 0
node = 0
node_tracking = {}
output = output.split("\n")
for line in output:
if("longitude" in line):
line = line.split(" ")
node = line[1]
latitude = line[2]
longitude = line[3]
time = line[4]
print(line)
print(node)
print(latitude)
print(longitude)
print(time)
status = [latitude, longitude, time]
node_tracking[node] = status
print node_tracking
with open("locations.txt", 'w') as f:
for key in node_tracking:
f.write(str(key) + str(node_tracking[key]))
if __name__ == "__main__":
main()