Some more bugfixes

This commit is contained in:
jpmeijers 2017-02-26 19:41:43 +01:00
parent f8ea6b5186
commit 9834e8bc46

24
run.py
View File

@ -61,6 +61,7 @@ if os.environ.get("GW_KEY")==None:
sys.exit(0) sys.exit(0)
my_eui = GWID_PREFIX + format(uuid.getnode(), '012x') my_eui = GWID_PREFIX + format(uuid.getnode(), '012x')
my_eui = my_eui.upper()
print ("Gateway Type:\t"+os.environ.get("GW_TYPE")) print ("Gateway Type:\t"+os.environ.get("GW_TYPE"))
print ("Gateway ID:\t"+os.environ.get("GW_ID")) print ("Gateway ID:\t"+os.environ.get("GW_ID"))
@ -148,12 +149,14 @@ gateway_conf['contact_email'] = os.getenv('GW_CONTACT_EMAIL', "")
gateway_conf['description'] = description gateway_conf['description'] = description
# Use hardware GPS # Use hardware GPS
if(os.getenv('GW_GPS', True)): if(os.getenv('GW_GPS', False)==True):
print ("Using real GPS")
gateway_conf['gps'] = True gateway_conf['gps'] = True
gateway_conf['fake_gps'] = False gateway_conf['fake_gps'] = False
gateway_conf['gps_tty_path'] = os.getenv('GW_GPS_PORT', "/dev/ttyAMA0") gateway_conf['gps_tty_path'] = os.getenv('GW_GPS_PORT', "/dev/ttyAMA0")
# Use fake GPS with coordinates from TTN # Use fake GPS with coordinates from TTN
if(os.getenv('GW_GPS', False) and latitude!=0 and longitude!=0): elif(os.getenv('GW_GPS', False)==False and latitude!=0 and longitude!=0):
print ("Using fake GPS")
gateway_conf['gps'] = True gateway_conf['gps'] = True
gateway_conf['fake_gps'] = True gateway_conf['fake_gps'] = True
gateway_conf['ref_latitude'] = latitude gateway_conf['ref_latitude'] = latitude
@ -161,6 +164,7 @@ if(os.getenv('GW_GPS', False) and latitude!=0 and longitude!=0):
gateway_conf['ref_altitude'] = altitude gateway_conf['ref_altitude'] = altitude
# No GPS coordinates # No GPS coordinates
else: else:
print ("Not sending coordinates")
gateway_conf['gps'] = False gateway_conf['gps'] = False
gateway_conf['fake_gps'] = False gateway_conf['fake_gps'] = False
@ -179,40 +183,40 @@ if(os.getenv('SERVER_TTN', True)):
gateway_conf['servers'].append(server) gateway_conf['servers'].append(server)
# Add up to 3 additional servers # Add up to 3 additional servers
if(os.getenv('SERVER_1', True)): if(os.getenv('SERVER_1_ENABLED', False)):
server = {} server = {}
if(os.getenv('SERVER_1_TYPE', "semtech")=="ttn"): if(os.getenv('SERVER_1_TYPE', "semtech")=="ttn"):
server['serv_type'] = "ttn" server['serv_type'] = "ttn"
server['server_address'] = os.environ.get("SERVER_1_ADDRESS") server['server_address'] = os.environ.get("SERVER_1_ADDRESS")
server['serv_gw_id'] = os.environ.get("SERVER_1_GWID") server['serv_gw_id'] = os.environ.get("SERVER_1_GWID")
server['serv_gw_key'] = os.environ.get("SERVER_1_GWKEY") server['serv_gw_key'] = os.environ.get("SERVER_1_GWKEY")
if(os.getenv('SERVER_1_ENABLED', "true")=="true"): if(os.getenv('SERVER_1_ENABLED', "false")=="true"):
server['serv_enabled'] = True server['serv_enabled'] = True
else: else:
server['serv_enabled'] = False server['serv_enabled'] = False
gateway_conf['servers'].append(server) gateway_conf['servers'].append(server)
if(os.getenv('SERVER_2', True)): if(os.getenv('SERVER_2_ENABLED', False)):
server = {} server = {}
if(os.getenv('SERVER_1_TYPE', "semtech")=="ttn"): if(os.getenv('SERVER_1_TYPE', "semtech")=="ttn"):
server['serv_type'] = "ttn" server['serv_type'] = "ttn"
server['server_address'] = os.environ.get("SERVER_1_ADDRESS") server['server_address'] = os.environ.get("SERVER_1_ADDRESS")
server['serv_gw_id'] = os.environ.get("SERVER_1_GWID") server['serv_gw_id'] = os.environ.get("SERVER_1_GWID")
server['serv_gw_key'] = os.environ.get("SERVER_1_GWKEY") server['serv_gw_key'] = os.environ.get("SERVER_1_GWKEY")
if(os.getenv('SERVER_1_ENABLED', "true")=="true"): if(os.getenv('SERVER_1_ENABLED', "false")=="true"):
server['serv_enabled'] = True server['serv_enabled'] = True
else: else:
server['serv_enabled'] = False server['serv_enabled'] = False
gateway_conf['servers'].append(server) gateway_conf['servers'].append(server)
if(os.getenv('SERVER_3', True)): if(os.getenv('SERVER_3_ENABLED', False)):
server = {} server = {}
if(os.getenv('SERVER_1_TYPE', "semtech")=="ttn"): if(os.getenv('SERVER_1_TYPE', "semtech")=="ttn"):
server['serv_type'] = "ttn" server['serv_type'] = "ttn"
server['server_address'] = os.environ.get("SERVER_1_ADDRESS") server['server_address'] = os.environ.get("SERVER_1_ADDRESS")
server['serv_gw_id'] = os.environ.get("SERVER_1_GWID") server['serv_gw_id'] = os.environ.get("SERVER_1_GWID")
server['serv_gw_key'] = os.environ.get("SERVER_1_GWKEY") server['serv_gw_key'] = os.environ.get("SERVER_1_GWKEY")
if(os.getenv('SERVER_1_ENABLED', "true")=="true"): if(os.getenv('SERVER_1_ENABLED', "false")=="true"):
server['serv_enabled'] = True server['serv_enabled'] = True
else: else:
server['serv_enabled'] = False server['serv_enabled'] = False
@ -223,7 +227,7 @@ if(os.getenv('SERVER_3', True)):
# Write global_coonf # Write global_coonf
local_conf = {'gateway_conf': gateway_conf} local_conf = {'gateway_conf': gateway_conf}
with open('local_conf.json', 'w') as the_file: with open('local_conf.json', 'w') as the_file:
the_file.write(json.dumps(local_conf)) the_file.write(json.dumps(local_conf, indent=4))
# Endless loop to reset and restart packet forwarder # Endless loop to reset and restart packet forwarder
while True: while True:
@ -239,9 +243,11 @@ while True:
time.sleep(0.1) time.sleep(0.1)
GPIO.output(22, 0) GPIO.output(22, 0)
time.sleep(0.1) time.sleep(0.1)
GPIO.cleanup(22)
#TODO: reset other gateway boards #TODO: reset other gateway boards
# Start forwarder # Start forwarder
subprocess.call(["./mp_pkt_fwd"]) subprocess.call(["./mp_pkt_fwd"])
time.sleep(15) time.sleep(15)