import requests
from signalrcore.hub_connection_builder import HubConnectionBuilder
 
TOKEN = "<YOUR_ACCESS_TOKEN>"  
API   = "https://<YOUR_DEPLOYMENT>.edge.zerokey.com/v3"
 
conn = requests.post(
    f"{API}/events/connections",
    headers={"Authorization": f"Bearer {TOKEN}"},
    json={"Mode": "read", "Filters": [{"FilterTemplate": "position_events"}]},
).json()
 
hub = HubConnectionBuilder().with_url(
    conn["EndpointURI"],
    options={"access_token_factory": lambda: conn["EndpointID"]},
).build()
 
hub.start()
import rclpy
from rclpy.node import Node
from geometry_msgs.msg import PointStamped
 
rclpy.init()
node = Node("zk_rtls")
pub  = node.create_publisher(PointStamped, "/zerokey/position", 10)
 
def handle_event(e: dict):
    if e.get("Category") != "POSITION":
        return
    pos = e.get("Content", {}).get("Position")
    if not pos:
        return
 
    msg = PointStamped()
    msg.header.stamp = node.get_clock().now().to_msg()
    msg.header.frame_id = "zk_map"
    msg.point.x, msg.point.y, msg.point.z = pos
    pub.publish(msg)
 
rclpy.spin(node)