Sending a Processing array from one computer to other computers

Hello,

I’m creating a project that involves robots that are tracked with computer vision. The robots will each run on a Raspberry Pi Zero W. There will be about 20 of them. A camera mounted to the ceiling detects where the robots are in the space. That information is parsed by a Processing program on a computer connected to the camera. We’ll call that computer the master computer. What I would like to do is send an array of coordinates wirelessly from the master computer to the robots.

I think that there are a number of ways that I can go about doing this, but I’m wondering if there is a way that you think is best/most effective. Ideally the array would be sent about 4 times a second, and the robots would be updating where they move based on this information (also at a rate of 4 times per second).

I was wondering if there’s a way to do it “directly” (for example, you can send information from an Arduino to a Processing sketch via serial). Or (either due to the fact that I’m working wirelessly, or due to the fact that I need to send a series of messages to multiple robots) do I instead need to do something like create a webpage that holds the data? That website’s data would be updated by the master computer 4 times a second and read by the robots 4 times a second.

I’ve never passed Processing information wirelessly before, and any direction would be greatly appreciated :slight_smile:
Thanks everyone!

1 Like

Hi SheCurvesMobius, I resolved an similar situation with a Comau robot.
I tok a cue from a very useful example: SharedCanvasServer and SharedCanvasClient
They you can find in Examples/Library/Network

You can create one Server and many Clients do You want.
Instead the mouse coordinates You can send and receive any array data…
I have only added an simply control for right transmission ("§" + data + “#”)

I hope this simple way is useful for your case…
Keep us up to date
Regards

2 Likes

Thanks Dennis! I’m going to have a look at your example and work with it over the next few days and see what I can come up with :slight_smile:

I’m on my way but I’ve hit my first bump. I’ve changed the client file’s IP address to my own (which I discovered Googling “what’s my IP address”):

c = new Client(this, "198.2.93.167", 12345); // Replace with your server's IP and port

And then I hit play on the server sketch, and lastly hit play on the client sketch. When the client sketch runs I get this error:

java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.(Socket.java:434)
at java.net.Socket.(Socket.java:211)
at processing.net.Client.(Unknown Source)
at SharedCanvasClient_p2.setup(SharedCanvasClient_p2.java:43)
at processing.core.PApplet.handleDraw(PApplet.java:2432)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)

Where to from here? I’m not sure how to troubleshoot this one.

Thanks for any assistance!

1 Like

Hello,

I do not know what kind of network you are on.
The Google search gives you the IP it sees which can be your router and may not be your local IP and IP of server.

If you have client and server on same PC use the default 127.0.0.1 for the client to test.

  // Connect to the server's IP address and port
  c = new Client(this, "127.0.0.1", 12345); // Replace with your server's IP and port

Reference:
https://en.wikipedia.org/wiki/Localhost

Add this to your server setup() to get the actual IP of the server:

  s = new Server(this, 12345); // Start a simple server on a port
  println(Server.ip()); // Add this

And then replace 127.0.0.1 with that for testing.

Reference:
https://processing.org/reference/libraries/net/Server_ip_.html

I do not know what your network experience is but there are many ways to get your local IP address.
And this was a new way for me!

Next is client and server on different PCs on same network.

I added a second client on a PC on my network and got the same error you did until I entered the IP of the server.

:)

2 Likes

Amazing!! This totally worked, and it was such a quick fix. Thanks so much for your help glv! I’m going to give it a shot using a second computer now.

1 Like

Hello again!

I just got it working from my work PC (client) connecting to my home PC (server).
I remote desktop to work PC and on a VPN so that extra line (showing IP) helped me to connect the client quickly!

It is a little trickier if I have to punch through my router; I have to do port forwarding from my router IP to my network IP (behind the router) to the PC the server is on.
Also got that working!

That was a great distraction for me. I have numerous projects on the back burner and this is related.

This may be of interest as an example:


Arduino sends data to network server.
Network client connects to server and displays data received from Arduino.

:)

1 Like

Excellent–thanks so much :slight_smile: I got mine working on two computers as well–I have a good feeling that it will work well for my final application. Super stoked about it. I so appreciate your help!

3 Likes