Skip to content

Instantly share code, notes, and snippets.

@mikelgg93
Created November 28, 2023 16:38
Show Gist options
  • Save mikelgg93/6253694c60412fcc41168cb8fa4c0592 to your computer and use it in GitHub Desktop.
Save mikelgg93/6253694c60412fcc41168cb8fa4c0592 to your computer and use it in GitHub Desktop.
Core subscribe to gaze.3d.1
import msgpack
import zmq
ctx = zmq.Context()
pupil_remote = ctx.socket(zmq.REQ)
ip = "localhost"
port = 50020
pupil_remote.connect(f"tcp://{ip}:{port}")
pupil_remote.send_string("SUB_PORT")
sub_port = pupil_remote.recv_string()
subscriber = ctx.socket(zmq.SUB)
subscriber.connect(f"tcp://{ip}:{sub_port}")
subscriber.subscribe("gaze.3d.")
try:
print("Listening for 'gaze.3d.1.' messages...")
while True:
topic, payload = subscriber.recv_multipart()
message = msgpack.loads(payload, raw=False)
eye = "right" if "gaze.3d.0." in str(topic) else "left"
print(
f"Eye {eye}:\n"
f" gaze_normal_3d: {message['gaze_normal_3d']}\n"
f" phi: {message['base_data'][0]['phi']}\n"
f" theta: {message['base_data'][0]['theta']}\n"
)
except KeyboardInterrupt:
print("Stopped listening for 'gaze.3d.1.' messages.")
finally:
subscriber.close()
ctx.term()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment