Catch value errors

This commit is contained in:
Nico Schottelius 2016-11-12 18:14:37 +01:00
parent 435e1ace2c
commit 114c754900

View file

@ -21,27 +21,33 @@ import lorautil
# sodaq: lat=46.9699219 lon=9.0391764
# google: 46.969943, 9.038999
known_devices = [ "0018B20000000C58", "0018B20000000C37", "0018B20000000C59", "0018B20000000CD0" ]
log = logging.getLogger("adeunis")
log.setLevel(logging.DEBUG)
known_devices = [ "0018B20000000C58", "0018B20000000C37", "0018B20000000C59", "0018B20000000CD0" ]
def get_gps(deveui, payload):
res = []
if not int(payload[0:2], 16) & (2**7):
return res
lat_deg = float(payload[4:6])
lat_min = float(payload[6:8])
lat_sec = float(payload[8:10])
lat_frac_sec = float(payload[10:11])
lat = lat_deg + lat_min/60.0 + lat_sec/3600.0 + lat_frac_sec/36000.0
try:
lat_deg = float(payload[4:6])
lat_min = float(payload[6:8])
lat_sec = float(payload[8:10])
lat_frac_sec = float(payload[10:11])
lat = lat_deg + lat_min/60.0 + lat_sec/3600.0 + lat_frac_sec/36000.0
long_deg = float(payload[12:15])
long_min = float(payload[15:17])
long_sec = float(payload[17:19])
long_frac_sec = float(payload[19:20])
long = long_deg + long_min/60.0 + long_sec/3600 + long_frac_sec/36000.0
long_deg = float(payload[12:15])
long_min = float(payload[15:17])
long_sec = float(payload[17:19])
long_frac_sec = float(payload[19:20])
long = long_deg + long_min/60.0 + long_sec/3600 + long_frac_sec/36000.0
pos = ":lat={:.6f} long={:.6f}".format(lat, long)
pos = ":lat={:.6f} long={:.6f}".format(lat, long)
except ValueError as e:
log.info("GPS decode error: {}:{} {}".format(deveui, payload, e))
res = [ deveui + pos ]