We will be more or less do what's described in this document, but over the Internet.
From wherever you are on the web, you can drive the servo(s) connected to the Raspberry PI, just like if you were next to it.
We will be using
node.js as a server, and WebSocket as the protocol.
This document explains how to install all we need on the Raspberry PI.
node.jsserver can run on the Raspberry PI, but it is not mandatory. You can very well have the
node.jsserver installed on its own box, and the Raspberry PI connect to it, just like the other web clients that are going to connect to it too to drive the servo(s).
node.jsserver, using some WebSocket API. This connection from the Java program to the
node.jsserver can be made locally or remotely, the only difference would be the URL of the server.
node.jsserver running on a separate box would actually relieve the Raspberry PI of the load of the server.
nodeserver and driving the servo
adafruiti2c.AdafruitPCA9685class to drive the servo, and the tools provided by the
orasocket-client-12.1.3.jarlibrary to listen to the WebSocket server.
Prompt> node server.js
#!/bin/bash PI4J_HOME=/home/pi/pi4j/pi4j-distribution/target/distro-contents CP=./classes CP=$CP:$PI4J_HOME/lib/pi4j-core.jar CP=$CP:./libs/json.jar CP=$CP:./libs/orasocket-client-12.1.3.jar sudo java -cp $CP adafruiti2c.samples.ws.WebSocketListenerIf the
nodeserver does not run on the Raspberry PI (aka
localhost), use a system variable named
ws.urito provide its name in the script above:
sudo java -cp $CP -Dws.uri=ws://othermachine:9876/ adafruiti2c.samples.ws.WebSocketListener
The Android application interface. Before connection.
Runs on Android tablets and smarphones...