-
Notifications
You must be signed in to change notification settings - Fork 1
/
start_gw.py
83 lines (67 loc) · 2.65 KB
/
start_gw.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
#-------------------------------------------------------------------------------
# Copyright 2016 Nicolas Bertuol, University of Pau, France.
#
#
# This file is part of the low-cost LoRa gateway developped at University of Pau
#
# Contact: [email protected]
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the program. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
# Oct/2016. re-designed by C. Pham to use self-sufficient script per cloud
import json
import os
conf_filename = "global_conf.json"
def start_config_from_json() :
#open json file to recover values
f = open(os.path.expanduser(conf_filename),"r")
lines = f.readlines()
f.close()
array = ""
#get all the lines in a string
for line in lines :
array += line
#change it into a python array
json_array = json.loads(array)
#recover each field different than 0 and call post_processing_gw.py with parameters
call_string_cpp = "sudo ./lora_gateway"
call_string_python = " | python post_processing_gw.py"
call_string_log_gw = ""
if json_array["ignorecomment"] :
call_string_python += " --ignorecomment"
if json_array["loggw"] :
call_string_python += " --loggw"
if json_array["wappkey"] :
call_string_python += " --wappkey"
if json_array["raw"] :
call_string_python += " --raw"
if json_array["aes"] :
call_string_python += " --aes"
if json_array["log_post_processing"] :
call_string_log_gw = " | python log_gw.py"
if json_array["mode"] != -1 :
call_string_cpp += " --mode %s" % str(json_array["mode"])
else :
call_string_cpp += " --bw %s --cr %s --sf %s" % (str(json_array["bw"]),str(json_array["cr"]),str(json_array["sf"]))
if json_array["ch"] != -1 :
call_string_cpp += " --ch %s" % str(json_array["ch"])
elif json_array["freq"] != -1:
call_string_cpp += " --freq %s" % str(json_array["freq"])
print call_string_cpp+call_string_python+call_string_log_gw
#launch the commands
os.system(call_string_cpp + call_string_python + call_string_log_gw)
if __name__ == "__main__":
start_config_from_json()