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
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
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
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, "22.214.171.124", 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 processing.net.Client.(Unknown Source)
Where to from here? I’m not sure how to troubleshoot this one.
Thanks for any assistance!
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
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.
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.
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.
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.
Excellent–thanks so much 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!