diff --git a/python/adeunisrf.py b/python/adeunisrf.py index 605694c..94cce45 100644 --- a/python/adeunisrf.py +++ b/python/adeunisrf.py @@ -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 ]