Setting up the OpenTRV Java comms bridge on an Raspberry Pi =========================================================== BG20150827 1. Install the RXTX library on the RPi: sudo apt-get install librxtx-java 2. Compile the Java executable on your computer and copy it to the RPi: cd /path/to/opentrv/code ant this will create a out_D folder in which will contain a .jar file called OpenTRV-comms-.jar where version is likely to be 0.2.1 or 0.2.2. Copy that .jar file to the RPi. 3. Copy json-simple-1.1.1.jar and jssc.jar from the java/checkedInLibs folder to the RPi 4. Create a folder structure to put the .jar files and config file in (see below for the shell script and config file). Mine looks like this: ./bin: localOpenTRVMonitor.sh ./opentrv: v0_2 config.json lib OpenTRV-comms-0.2.2.jar thirdPartyLib json-simple-1.1.1.jar jssc.jar 5. Create a soft link to the latest JRE (note that the exact name on your RPi may vary, hence the link): cd /usr/lib/jvm sudo ln -s ./jdk-8-oracle-arm-vfp-hflt latest 6. Create a localOpenTRVMonitor.sh shell script to run the .jar executable. Mine looks like the below. Note the following lines: OPENTRVVER=0.2.2 => make sure this matches the version of the .jar file OPENTRVDIR=/home/pi/opentrv/v0_2/ => make sure this matches the top of the folder structure you created above #!/bin/sh # Starts long-running task to monitor local (~V0.2) OpenTRV node over serial. # Will exit if specified serial is not available. # Will exit if program is already running # (eg so periodic restart attempt from cron is safe). JAVA_HOME=/usr/lib/jvm/latest/ export JAVA_HOME # OpenTRV comms lib version OPENTRVVER=0.2.2 OPENTRVDIR=/home/pi/opentrv/v0_2/ OPENTRVJLDIR=$OPENTRVDIR/lib OPENTRVTPJLDIR=$OPENTRVDIR/thirdPartyLib # From librxtx-java package... OPENTRVSTPJLDIR=/usr/share/java OPENTRVTPNLDIR=/usr/lib/jni exec $JAVA_HOME/bin/java -Xms2m -Xmx4m \ -Djava.library.path=$OPENTRVTPNLDIR \ -classpath "$OPENTRVJLDIR/OpenTRV-comms-${OPENTRVVER}.jar:$OPENTRVTPJLDIR/*:$OPENTRVSTPJLDIR/*" \ uk.org.opentrv.comms.util.EventDrivenV0p2CLIFollower \ $OPENTRVDIR/config.json 7. Check the ID of your serial port: $ ls /dev/serial/by-id usb-FTDI_TTL232R_FTGCVTIF-if00-port0 8. Create a config.json file. A very simple one looks like this (note the serialPort entry): { "serialPort": "/dev/serial/by-id/usb-FTDI_TTL232R_FTGCVTIF-if00-port0", "handlers": [ { "name": "File log", "type": "uk.org.opentrv.comms.statshandlers.builtin.SimpleFileLoggingStatsHandler", "options": { "statsDirName": "/home/pi/opentrv/.private/stats/" } } ] } You will also find more complex examples in the javasrc/uk/org/opentrv/test/statsHandling/ folder in the code tree. In particular you have Emoncms examples there. 9. Test the script: ./bin/localOpenTRVMonitor.sh It should run without crashing and should start displaying stats lines. Stop it via CTRL-C 10. Schedule the script via cron: crontab -e My cron entry looks like this: 27 * * * * /bin/localOpenTRVMonitor.sh 2>&1 > /dev/null Meaning that it attempts to restart the script every hour at 27 minutes past the hour. If it's already running, it will let it run. 11. Once its expected start time is past, make sure it's running: ps -ef | grep java