snstac / pytak

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

Network is unreachable #36

Closed dbussert closed 1 year ago

dbussert commented 1 year ago

I'm using adsbcot with adsbexchange pi image. I was previously using DHCP to get an IP but recently moved to a static IP by editing dhcpcd.conf. At that point my Pi stopped outputting COT entirely. I traced the error back to adsbcot exiting out with this error.

After troubleshooting, I believe this is because there is no default route set on this Pi (LAN only). I'm using a very simple config, just output COT to default multicast SA address. Pytak may be thinkin there is no route to the multicast address, although one shouldn't be needed.

[adsbcot]
DUMP1090_URL = http://127.0.0.1/tar1090/data/aircraft.json
POLL_INTERVAL = 10

I resolved this by adding an (unnecessary) default gateway to eth0

pi@adsbexchange:~ $  DEBUG=1 /home/pi/.local/bin/adsbcot -c /etc/adsbcot.ini
Showing Config: %s /etc/adsbcot.ini
==========
<Section: adsbcot>
==========
DEBUG:asyncio:Using selector: EpollSelector
DEBUG:asyncio:Close <_UnixSelectorEventLoop running=False closed=False debug=True>
Traceback (most recent call last):
  File "/home/pi/.local/bin/adsbcot", line 8, in <module>
    sys.exit(main())
  File "/home/pi/.local/lib/python3.9/site-packages/adsbcot/commands.py", line 31, in main
    pytak.cli(__name__.split(".")[0])
  File "/home/pi/.local/lib/python3.9/site-packages/pytak/client_functions.py", line 317, in cli
    asyncio.run(main(app_name, config), debug=debug)
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/pi/.local/lib/python3.9/site-packages/pytak/client_functions.py", line 262, in main
    await clitool.setup()
  File "/home/pi/.local/lib/python3.9/site-packages/pytak/classes.py", line 237, in setup
    reader, writer = await pytak.protocol_factory(self.config)
  File "/home/pi/.local/lib/python3.9/site-packages/pytak/client_functions.py", line 202, in protocol_factory
    writer = await pytak.create_udp_client(cot_url)
  File "/home/pi/.local/lib/python3.9/site-packages/pytak/client_functions.py", line 69, in create_udp_client
    stream: DatagramClient = await dgconnect((host, port))
  File "/home/pi/.local/lib/python3.9/site-packages/pytak/asyncio_dgram/aio.py", line 269, in connect
    transport, protocol = await loop.create_datagram_endpoint(
  File "/usr/lib/python3.9/asyncio/base_events.py", line 1363, in create_datagram_endpoint
    raise exceptions[0]
  File "/usr/lib/python3.9/asyncio/base_events.py", line 1350, in create_datagram_endpoint
    await self.sock_connect(sock, remote_address)
  File "/usr/lib/python3.9/asyncio/selector_events.py", line 502, in sock_connect
    return await fut
  File "/usr/lib/python3.9/asyncio/selector_events.py", line 507, in _sock_connect
    sock.connect(address)
OSError: [Errno 101] Network is unreachable
ampledata commented 1 year ago

@dbussert I've added a feature to PyTAK 3.7.0 that allows setting the LOCAL_ADDR of the open_connection call within asyncio. You'll want to set LOCAL_ADDR to your static IP, this can be done via the normal adsbcot config mechanisms (env vars, config file, etc).

I've not yet found a comfortable way of solving for the problem of consistently joining a multcast group from Python on Linux. My currently solution is to rely on systemd to restart adsbcot every time the network interfaces change (e.g. change ip, come up, go down, gain a route, etc).

ampledata commented 1 year ago

@dbussert correction, the param is PYTAK_MULTICAST_LOCAL_ADDR