Synology and Java

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

For now it like to investigate the use of a Synology (DS-107+) NAS together with Java. This might be a good way to connect a JeeNode/Arduino to the internet. In the future I like to use a Raspberry Pi to connect to the internet, together with other functions of course.
Important is that I can run Java code in combination with the serial communication capabilities of the rxtxSerial library. I found a really nice post on how to install Java on a Synology, because I really don’t want to loose the steps described I’ll cite the text of the post below:

1. install ipkg

2. install jamvm

To start with you need to install the following packages with ipkg:

ipkg install classpath
ipkg install jamvm
ipkg install jikes
ipkg install zlib
ipkg install file

Once these have installed then you are almost ready to go.  Being a java developer, I was used to using javac and java to compile and execute programs, so jikes and jamvm didn’t sit well with me!  To get around this I created a symbolic link and a shell script in /opt/bin
These are as follows:

ln -s /opt/bin/jamvm /opt/bin/java

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.


/opt/bin/jikes -classpath /opt/share/jamvm/ $*

Remember to change the permissions on the shells scripts to add the execute flag!

I found out that there is also a  rxtxSerial ipk package which can be installed on the Synology. To do this just enter ipkg install  rxtx_2.1.7r2-1_arm.ipk on the command-line (you have to be logged in as root).

The cited post referred to this page.
Another page about Java and Synology is found here.

I’m wondering what is possible having all this installed (and what I need to install further). The code I tested uses URLConnection related classes and is not working yet … will be continued.

How to communicate using URLConnection in Java

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Reading data with serial communication between Arduino and PC is one step. After the PC has received the data I want it to send the data (raw or after some calculations) to a website. The website will store the data and show the data in some nice graphs and tables.
The other way around I want to send some commands from the website to the PC where the Java app has to send it to the Arduino which on its turn will perform some actions. I will write another post on this subject some other time.

I found a nice page at Oracle describing how to use the Java URLConnection class.

Depending on the functionality of your website script/app you could start very simple with the code below.


public class Reverse {
    public static void main(String[] args) throws Exception {

	URL url = new URL("");
	URLConnection connection = url.openConnection();

	OutputStreamWriter out = new OutputStreamWriter(

	BufferedReader in = new BufferedReader(
				new InputStreamReader(

All we do here is opening an URL to a PHP page and provide it with two variables. These variables can be extracted from the URL by the PHP script. The snippet below shows a piece of PHP code to extract the variables from the URL. After you got the variable values they can be stored in a database, written to a file, etc..


$type = $_GET['type'];
$value = $_GET['value'];

// store it in a database or write it to a file or ...

print "TYPE = ".$type." -- VALUE =".$value."</BR>"; 


I know it is very basic and not secure in the dangerous open network world (internet), but as a starting point for private network environments it might be helpful.



Serial communication between PC and Arduino

Using sensors together with the Arduino or JeeNode is cool. Using the serial monitor of the Arduino IDE lets you see the values. The data is sent from the Arduino over (in my case) a USB cable to my PC. With the serial monitor of the IDE I can receive and also send data.

To make a domotica solution I need something more than the serial monitor of the IDE. I want to be able to send and receive data from my own application and website.

I’m want to use Java to develop the application that’s going to send and receive data. Although I might also try C/C++ in a while, but for now I’ll focus on Java. The reason I want to use Java is that I’m using a Windows computer to develop, but I might want to use a Linux based device to let my application run and do its job. Hopefully it will be easier to switch between the two operating systems with an application written in Java.
(The platform I’m thinking of is the Raspberry Pi; hopefully soon to be ordered)

Searching for a good way to start writing code to communicate with an Arduino I found this page on the Arduino website and also another interesting website. (I did find this site about C and Arduino which might be useful in the future; and this one is I think about Processing and Arduino)

It turns out that by using the RXTX Java library it is possible to use serial communication to send and receive data between a PC and an Arduino. The page shows a code example of a Java app which is able to receive data from a serial port (COM port; in PC terms).

I chose Eclipse as my Java IDE (the SpringSource version to be exact). I had to download the 2.2pre version of the RXTX Library, because my Windows is a 65-bit version. In the 2.2pre package a 64-bit version of the rxtxSerial.dll is included. The 32-bit version will not work on a 64-bit OS, as I found out by trial-and-error. (I didn’t read through the entire page on otherwise I would have seen the instruction)  Beware that when you use the 2.2pre .dll file you also need to use the 2.2pre RXTXcomm.jar file in your classpath. If you don’t a version mismatch error will be shown.

The steps I took for my basic serial communication test application were:

  1. copy the rxtxSerial.dll to c:\windows\sysWOW64
  2. add the c:\windows\sysWOW64 to your path
  3. added the location of the RXTXcomm.jar file to the classpath in Eclipse
  4. created a new Java project;
  5. added a new file to the \src of the project
  6. named it
  7. copied the code snippet from the Arduino page (file is attached to this post)
  8. change the COM port to COM5
  9.  changed the bit-rate in the Java code (I needed 57600 for my JeeLink with RF12Demo)
  10. build en run

I saw the expected text from the RF12Demo in the console window of Eclipse.

The first step is done, data is transferred from JeeLink (Arduino) to a ‘self made’ application. The next step is, of course, to send data to an Arduino. I’ll let  you know whta my findings are.

The first of many steps to my own Java Domotica-bridge application.