Socket connection issues for vision

We are trying to connect a raspberry pi 3 with the roboRio. The raspberry pi processes the visual data and detects apriltags, then sends them through a socket to the roboRio where it will handle it accordingly.

The Raspberry Pi creates the socket server and the rio will connect to it.
Currently, we are having problems with connection. We keep on getting a ConnectionRefused error.

Here is how the socket is implemented rPi side:

server = socket.socket()
port = 5801
host = 'wpilibpi.local'
server.bind((host, port))
print("Awaiting socket connection...")
server.listen(2)
conn, address = server.accept()

And here is how we attempt to connect rio side:

Socket socket = new Socket("wpilibpi.local", 5801);

The robot for some reason cannot connect. We have an ethernet cable linking directly between the rio and the pi. When I connect using a laptop connected to the pi’s network, it does work.

What are we doing wrong?

I can’t answer why it’s not working, but I highly recommend looking into NetworkTables instead. It handles all of the low-level network connections for you.

Is there some example code / good documentation for both the Raspberry Pi and the rio (Java)? We tried looking at the documentation and it was very fragmented and all-over-the-place, so it was hard for us to use it.

Have you already looked at the WPILib NetworkTables documentation? There’s an example client in Python, as well as API documentation in both Java and Python. NetworkTables — FIRST Robotics Competition documentation

There’s also a Python vision example in the WPILibPi documentation that outputs to NetworkTables. Basic Vision Example — FIRST Robotics Competition documentation

I think you need a radio to connect your way by name instead of IP address.

Hello! Thanks for the response, I really appreciate it :slight_smile:

Question: is there any specific documentation needed for NetworkTables to work, or is an ethernet connection between the pi & rio enough?

Regarding networking, an Ethernet connection and of course them on the same subnet so they can connect to each other with TCP/IP.