Headless Operation
Note that the runtime properties are "sticky". You only need to specify them once during setup, when you launch the application the next time it will use those settings. It's easier to setup the server with the GUI first, then switch to headless. For example, on smaller systems like an rPI
this might work: http://lxde.org/.
So to configure use the GUI to set it up, discover your wemos, register your clients. If you can't run a GUI, use the "-cli" flag for an interactive command mode. Once you've got things configured and running the way you want them start the headless server using the "-run" flag for normal operation. The settings from the GUI or CLI are persisted and will be used by the server.
On a RaspberryPi (thanks Alex!):
login as pi
install java with sudo apt-get update && sudo \ apt-get install oracle-java7-jdk
install (copy) the jar file to the pi
start LXDE with startx and run the java app in a terminal window with your normal command
configure WemoServer (see below)
in particular ensure the host address and GPS location are correct
don't run it normally in the X - the logging window cripples the pi performance
exit/terminate the server
edit rc.local with the sudo -u pi command below. You may want to redirect for long running operation with:
> /dev/null 2>&1 &
For headless (no gui) operation, use (note the use of -cp vs -jar):
To start use:
java -cp WemoServer.jar mpp.wemo.server.Headless
At the prompt use "help" to see a list of the available configuration and runtime commands.
Use "quit" to exit.
or use
java -cp WemoServer.jar mpp.wemo.server.Headless -run
for unattended operation (with no stdin)
SaeedM has offered this script for managing server operation. Thanks Saeed!
SERVICE_NAME=WemoServer
PATH_TO_JAR="java -cp WemoServer.jar mpp.wemo.server.Headless -port 4033 -run -log"
PID_PATH_NAME=/home/pi/WemoServer-pid
case $1 in
start)
echo "Starting $SERVICE_NAME ..."
if [ ! -f $PID_PATH_NAME ]; then
nohup $PATH_TO_JAR 2>> /home/pi/wemo.log >> /home/pi/wemo.log &
echo $! > $PID_PATH_NAME
echo "$SERVICE_NAME started ..."
else
echo "$SERVICE_NAME is already running ..."
fi
;;
stop)
if [ -f $PID_PATH_NAME ]; then
PID=$(cat $PID_PATH_NAME);
echo "$SERVICE_NAME stoping ..."
kill $PID;
echo "$SERVICE_NAME stopped ..."
rm $PID_PATH_NAME
else
echo "$SERVICE_NAME is not running ..."
fi
;;
restart)
if [ -f $PID_PATH_NAME ]; then
PID=$(cat $PID_PATH_NAME);
echo "$SERVICE_NAME stopping ...";
kill $PID;
echo "$SERVICE_NAME stopped ...";
rm $PID_PATH_NAME
echo "$SERVICE_NAME starting ..."
nohup $PATH_TO_JAR 2>> /home/pi/wemo.log >> /home/pi/wemo.log &
echo $! > $PID_PATH_NAME
echo "$SERVICE_NAME started ..."
else
echo "$SERVICE_NAME is not running ..."
fi
;;
*)
echo "$0 [start,stop,restart]"
;;
esac