zctx = zmq.Context()
zsub = zctx.socket(zmq.SUB)
zsub.connect(conf.get("collector", "publishurl"))
- tosub = topic(WIFI_POSITIONING.PROTO)
- zsub.setsockopt(zmq.SUBSCRIBE, tosub)
+ zsub.setsockopt(zmq.SUBSCRIBE, topic(WIFI_POSITIONING.PROTO))
zpush = zctx.socket(zmq.PUSH)
zpush.connect(conf.get("collector", "listenurl"))
zctx = zmq.Context()
zsub = zctx.socket(zmq.SUB)
zsub.connect(conf.get("collector", "publishurl"))
- for protoname in (
- "STATUS",
- "SETUP",
- "POSITION_UPLOAD_INTERVAL",
+ for proto in (
+ STATUS.PROTO,
+ SETUP.PROTO,
+ POSITION_UPLOAD_INTERVAL.PROTO,
):
- tosub = topic(proto_by_name(protoname))
- zsub.setsockopt(zmq.SUBSCRIBE, tosub)
+ zsub.setsockopt(zmq.SUBSCRIBE, topic(proto))
zpush = zctx.socket(zmq.PUSH)
zpush.connect(conf.get("collector", "listenurl"))
while True:
neededsubs = clients.subs()
for imei in neededsubs - activesubs:
+ log.debug("topics: %s", [tpc.hex() for tpc in [topic(GPS_POSITIONING.PROTO, True, imei), topic(WIFI_POSITIONING.PROTO, False, imei)]])
zsub.setsockopt(
zmq.SUBSCRIBE,
- topic(GPS_POSITIONING.PROTO, True),
+ topic(GPS_POSITIONING.PROTO, True, imei),
)
zsub.setsockopt(
zmq.SUBSCRIBE,
- topic(WIFI_POSITIONING.PROTO, False),
+ topic(WIFI_POSITIONING.PROTO, False, imei),
)
for imei in activesubs - neededsubs:
zsub.setsockopt(
zmq.UNSUBSCRIBE,
- topic(GPS_POSITIONING.PROTO, True),
+ topic(GPS_POSITIONING.PROTO, True, imei),
)
zsub.setsockopt(
zmq.UNSUBSCRIBE,
- topic(WIFI_POSITIONING.PROTO, False),
+ topic(WIFI_POSITIONING.PROTO, False, imei),
)
activesubs = neededsubs
log.debug("Subscribed to: %s", activesubs)
if sk is zsub:
while True:
try:
- zmsg = Bcast(zsub.recv(zmq.NOBLOCK))
+ buf = zsub.recv(zmq.NOBLOCK)
+ zmsg = Bcast(buf)
+ log.debug("zmq packet: %s", buf.hex())
+ # zmsg = Bcast(zsub.recv(zmq.NOBLOCK))
msg = parse_message(zmsg.packet)
tosend.append(zmsg)
log.debug("Got %s", zmsg)
def topic(proto, is_incoming=True, imei=None):
- return (
- pack("BB", is_incoming, proto) + b"" if imei is None else imei.encode()
+ return pack("BB", is_incoming, proto) + (
+ b"" if imei is None else pack("16s", imei.encode())
)
@property
def packed(self):
return (
- pack("BB", int(self.is_incoming), self.proto)
- + ("0000000000000000" if self.imei is None else self.imei).encode()
+ pack(
+ "BB16s",
+ int(self.is_incoming),
+ self.proto,
+ "0000000000000000"
+ if self.imei is None
+ else self.imei.encode(),
+ )
+ (
b"\0\0\0\0\0\0\0\0"
if self.when is None
@property
def packed(self):
return (
- ("0000000000000000" if self.imei is None else self.imei.encode())
+ pack(
+ "16s",
+ "0000000000000000"
+ if self.imei is None
+ else self.imei.encode(),
+ )
+ (
b"\0\0\0\0\0\0\0\0"
if self.when is None