snstac / pytak

PyTAK is a Python package for rapid TAK integration.
https://pytak.readthedocs.io/en/stable/
Apache License 2.0
153 stars 42 forks source link

CoT messages not showing in WinTAK #57

Open iandresolares opened 8 months ago

iandresolares commented 8 months ago

Hello! First of all thank you for the the library!

So I am having troubles understanding how to connect to WinTAK. Basically for now I just want to test sending GPS data to WinTAK so it shows as a marker of some type. Later I plan to integrate the device with UAS plugin in order to manage waypoint navigation (I hope this is possible). The thing is, I have slightly modified the example send.py script, to send fake data to my WinTAK (both the script and WinTAK are running on the same PC). However I do not receive anything at all in WinTAK (I guess there is network configuration problem in WinTAK) and I can not figure out why.

Here is the code:


import asyncio
import xml.etree.ElementTree as ET

from configparser import ConfigParser

import pytak
import takproto

import time
import datetime

class MySerializer(pytak.QueueWorker):
    """
    Defines how you process or generate your Cursor on Target Events.
    From there it adds the CoT Events to a queue for TX to a COT_URL.
    """

    async def handle_data(self, data):
        """Handle pre-CoT data, serialize to CoT Event, then puts on queue."""
        event = data
        resp = await self.put_queue(event)
        print(resp)

    async def run(self, number_of_iterations=-1):
        """Run the loop for processing or generating pre-CoT data."""
        while 1:
            # data = tak_pong()
            # await self.handle_data(data)
            # print("pong data has been sent")
            # await asyncio.sleep(20)
            now = datetime.datetime.utcnow()
            stale = now
            stale += datetime.timedelta(hours=1)
            now_iso = now.isoformat()[:-4] + "Z"
            stale_iso = stale.isoformat()[:-4] + "Z"
            # 2023-12-05T08:46:22.96Z
            # 2023-12-07T12:01:37.681452Z
            print(now_iso)
            print(stale_iso)
            cot = f"""<?xml version='1.0' encoding='utf-16' standalone='yes'?>
<event version='2.0' uid='S-1-5-21-3327203913-228467099-2355216783-1001' type='a-f-G' time='{now_iso}' start='{now_iso}' stale='{stale_iso}' how='h-e'>
    <point lat='43.545231' lon='-5.661920' hae='9999999' ce='9999999' le='9999999' />
    <detail>
        <takv version='4.1.0.231' platform='WinTAK-CIV' os='Microsoft Windows 11 Home' device='HP HP Laptop 15-da0xxx' />
        <contact callsign='FONG' endpoint='' />
        <uid Droid='FONG' />
        <__group name='Cyan' role='Team Member' />
        <status battery='50' />
        <track course='0.00000000' speed='0.00000000' />
    </detail>
</event>
"""

            buf = takproto.xml2proto(cot,  takproto.TAKProtoVer.STREAM)
            print(buf)
            await self.handle_data(buf)
            # await asyncio.sleep(20)
            time.sleep(2)

def tak_pong():
    """Generate a simple takPong CoT Event."""
    root = ET.Element("event")
    root.set("version", "2.0")
    root.set("type", "t-x-d-d")
    root.set("uid", "takPong")
    root.set("how", "m-g")
    root.set("time", pytak.cot_time())
    root.set("start", pytak.cot_time())
    root.set("stale", pytak.cot_time(3600))
    return ET.tostring(root)

async def main():
    """Main definition of your program, sets config params and
    adds your serializer to the asyncio task list.
    """
    config = ConfigParser()
    config["mycottool"] = {"COT_URL": "tcp://192.168.99.108:4242"}
    config = config["mycottool"]

    # Initializes worker queues and tasks.
    clitool = pytak.CLITool(config)
    await clitool.setup()

    # Add your serializer to the asyncio task list.
    clitool.add_tasks(set([MySerializer(clitool.tx_queue, config)]))

    # Start all tasks.
    await clitool.run()

if __name__ == "__main__":
    asyncio.run(main())

Also I attach some WinTAK screenshots which may be useful: imagen imagen imagen

Some help is greatly appreciate it. Thanks!!

BR

jackwilliams2480 commented 3 months ago

Did you ever figure out the solution?

omkarjoshi-07 commented 2 months ago

Hey guys! I am also trying to send some sample COT drone detection event from python in the way mentioned above. It seems data is being sent to winTAK, but I am not able to see anything on winTAK. Can anyone please help me to understand?

surabhiwireless commented 3 weeks ago

Hi all, I am facing the same issue as well. I am trying to send COT messages to the server, the server port shows bytes received; but I can see nothing on webtak (the one which is available on the TAK server installation, and when the TAK server is launched on the web).