← Back to Improv
Improv
Instructable

Python CoT heartbeat (skeleton)

script ATAK
Difficulty: medium Time: ~30 min

Educational skeleton: build a tiny Python loop that emits a Cursor-on-Target (CoT) XML heartbeat. Pseudocode / outline only — wire it to a real TAK endpoint only in a lab you control.

Materials

Steps

  1. Sketch the event shape. A minimal CoT heartbeat is an XML event with point (lat/lon/hae), detail (contact callsign), type like a-f-G-U-C (example friendly ground unit — choose types deliberately), and a short stale time.
  2. Write a builder function. Something like build_heartbeat(callsign, lat, lon) -> str that fills timestamps (time, start, stale) in ISO-8601 UTC.
  3. Add a send stub. Start with print(xml) or write to a file. Only then add a socket send to a host/port your lab documents.
  4. Loop on an interval. Sleep 5–30s between heartbeats. Refresh stale so consumers drop you if the script stops.
  5. Validate offline. Diff two successive emissions; confirm UID is stable and timestamps advance.
  6. Lab only. Point at a local TAK / test harness before any shared network. Mis-typed CoT is spam.

Skeleton (pseudocode)

# Educational skeleton — not a drop-in TAK client
import time
from datetime import datetime, timedelta, timezone

def iso(dt):
    return dt.strftime("%Y-%m-%dT%H:%M:%S.000Z")

def build_heartbeat(uid, callsign, lat, lon, hae=0.0):
    now = datetime.now(timezone.utc)
    stale = now + timedelta(seconds=60)
    # Minimal CoT-shaped XML (illustrative; validate against your TAK docs)
    return f'''<event version="2.0" uid="{uid}" type="a-f-G-U-C"
  time="{iso(now)}" start="{iso(now)}" stale="{iso(stale)}" how="m-g">
  <point lat="{lat}" lon="{lon}" hae="{hae}" ce="9999999" le="9999999"/>
  <detail><contact callsign="{callsign}"/></detail>
</event>'''

def send(xml):
    # TODO: print, file, or socket to YOUR lab endpoint only
    print(xml)

UID = "Improv-Heartbeat-1"
while True:
    send(build_heartbeat(UID, "MF-HB", 35.0, -85.0))
    time.sleep(10)

Notes / gotchas

Video tips

Related watch — Marshall Pix4D/DTED2, TAK Syndicate, Meshtastic. Spelling lock: ATAK.

Pairs with Meshtastic → ATAK bridge as the “emit CoT” half of a local pipe.