1 """ Estimate coordinates from WIFI_POSITIONING and send back """
3 from datetime import datetime, timezone
4 from logging import getLogger
6 from struct import pack
10 from .gps303proto import parse_message, WIFI_POSITIONING
11 from .opencellid import qry_cell
12 from .zmsg import Bcast, Resp, topic
14 log = getLogger("gps303/lookaside")
19 zsub = zctx.socket(zmq.SUB)
20 zsub.connect(conf.get("collector", "publishurl"))
21 tosub = topic(WIFI_POSITIONING.PROTO)
22 zsub.setsockopt(zmq.SUBSCRIBE, tosub)
23 zpush = zctx.socket(zmq.PUSH)
24 zpush.connect(conf.get("collector", "listenurl"))
28 zmsg = Bcast(zsub.recv())
29 msg = parse_message(zmsg.packet)
31 "IMEI %s from %s at %s: %s",
34 datetime.fromtimestamp(zmsg.when).astimezone(tz=timezone.utc),
38 conf["opencellid"]["dbfn"], msg.mcc, msg.gsm_cells
42 packet=msg.Out(latitude=lat, longitude=lon).packed,
44 log.debug("Response for lat=%s, lon=%s: %s", lat, lon, resp)
45 zpush.send(resp.packed)
47 except KeyboardInterrupt:
51 if __name__.endswith("__main__"):
52 runserver(common.init(log))