A socket server program listens to a port. When a client tries to connect the server either allows it in or denies it access to the port. If allowed access the client and server can now communicate using UDP/TCP communication protocols.
Below is a quick explanation and example of using Socket Severs/Clients on the Raspberry Pi for PWM control.
Sockets Running Pi-Blaster:
Sending strings back and forth between a client and server uses simple InputStream()/OutputStream() commands. We needed to be able to send strings and then have them echoed to /dev/pi-blaster (command line virtualization). We had some trouble echoing commands using 'bash' from a Java program. We eventually figured it out using a Java program and Shell Script on the Raspberry Pi.
We first sent PWM values to a file called motorcontrol.sh and then use Runtime() in Java to emulate a 'bash' command. The following is the Shell Script which 'echos' are the values we give it to /dev/pi-blaster.
The code for the Server and Client can be found on our Downloads page under Java - Socket Server.
Edit the IP address in the Client.java and Server.java files to match you specific IP requirements.
After exporting the server into a runnable .jar file copy it to the Raspberry Pi and then run it using this command:
Next run the Client on your laptop (we are just using Eclipse for now). It should look something like this:
and you have a Client/Server connection to the Raspberry Pi to run Pi-Blaster! Stay updated for instructions on how to use an XBox Controller to send values (instead of a JOptionPane).
great
ReplyDelete