Setting the EXTRA_JAVA_OPTS on OH2

i read a lot about the EXTRA_JAVA_OPTS environmental variable and some post say that it has to go in a file in /etc/defaults/openhab2.
There is also some talks about system.properties file…
and also the docs https://github.com/openhab/openhab-distro/blob/844f4cc20b50c802d2c343c515c4f9d0c1c03b6e/docs/sources/getting-started.md is not giving a hint where to put this.

for now i edited the runtime/bin/setenv but that not the correct place.

http://docs.openhab.org/installation/linux.html#privileges-for-common-peripherals

Additionally it’s needed to allow the java environment to access the serial port of the connected peripheral. Therefore the following setting has to be added/adapted on your system in file /etc/default/openhab2:

EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyS0:/dev/ttyS2:/dev/ttyACM0:/dev/ttyAMA0"

1 Like

Yes that can be a place but. It’s it strange to set a variable in the system while its needed in the program.
And i’m working on a Synology so i’m not sure /def/default/openhad2 will stay after any major update.
There should be a file somewhere in the userdata where this could be defined.

In the end i found that the Synology has also something like a dailout group called HTTP settings this made it work.

1 Like

Reviving an old thread as it looks like you may have solved a serial device access issue similar to what I am facing.

I’ve installed OpenHab2 (2.2.0.008-SNAPSHOT) on a Synology Diskstation (DS415play running DSM 6.1.4). I have OpenHab running with the Paper UI and have Bindings working that require only network access (Weather, etc). I’ve been trying without success to get the UPB (Universal Powerline Bus) Binding working but logs show “java.lang.RuntimeException: Port does not exist” and the Binding fails to start.

After reading this and other threads I have added the “openhab2” user to the “http” User Group using the “User” Control Panel widget. This did not seem to fix the issue.

I’ve also seen reference to modifying the “EXTRA_JAVA_OPTS environmental variable” as noted in this thread but my installation has no /etc/defaults/openhab2 file and I’m not familiar enough with this OS to know where to go looking.

If you have any pointers on how to get over this hurdle I would really appreciate it.

I put the
EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyEnocean"
in
/volume1/@appstore/openHAB/runtime/bin/setenv
somewhere above the line "export EXTRA_JAVA_OPTS … "

Also make sure the device has the right permissions set to be readable and writable by openhab.

I’m trying to edit the setenv file in Visual Studio Code but have no permissions.

How can I set the permissions to allow me to do this change?

I have similar problem. I run Openhab2 (2.3.0 snapshot) from command line in a custom folder ( /testfield/openhab/openhab-2.3.0-snapshot ) and want to use a virtual serial port that was set up with socat at /tmp/virtualcom0.

I tried to add EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyUSB1:/dev/ttyS0:/dev/ttyS1:/tmp/virtualcom0" to different files without success.

The documentation of openhab serial binding still says to edit start.sh.
Other posts recommend to edit /etc/default/openhab2, which I do not have. Creating such a file does not work.
I even tried to edit .../runtime/bin/setenv.

The output on openhab is always:

21:07:06.284 [ERROR] [del.item.internal.GenericItemProvider] - Binding configuration of type 'serial' of item 'E_Wo_Beam_RS232' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: Could not open serial port /tmp/virtualcom0: Serial port '/tmp/virtualcom0' could not be found. Available ports are:
/dev/ttyUSB0
/dev/ttyS0

I am lost. Where is the right location to set additional ports, if openhab is running from individual folder by command line?

Either of these will work. I have this at the top of start.sh (but not for serial ports)…

export EXTRA_JAVA_OPTS="-Xbootclasspath/a:/opt/openhab2/conf/jython/jython-standalone-2.7.0.jar -Dpython.home=/opt/openhab2/conf/jython -Dpython.path=/opt/openhab2/conf/lib"

Maybe you are missing the export? Hope this helps!

1 Like

I’m feeling stupid. It does not work. Modified the start.sh to

#!/bin/sh
echo Launching the openHAB runtime...
export EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyUSB1:/dev/ttyS0:/dev/ttyS1:/tmp/virtualcom0"
DIRNAME=`dirname "$0"`
exec "${DIRNAME}/runtime/bin/karaf" "${@}"

than start openhab from command line with:

sudo su -s /bin/bash -c '/testfield/openhab/openhab-2.3.0-snapshot/start.sh' openhab

but I still get the message that the port /tmp/virtualcom0 is not available. With putty I have access and all works fine with the port itself…

1 Like

Did you set the groups? if so, what happens if you put it in /dev/virtualcom0 (and reflecting that in EXTRA_JAVA_OPTS)?

Thank you Scott, I checked this again:

me@home:~$ groups openhab
openhab : openhab tty dialout

this is correct, or?

to put it in /dev/, I had to run socat as root. But the result is the same…

00:08:06.832 [ERROR] [del.item.internal.GenericItemProvider] - Binding configuration of type 'serial' of item 'E_Wo_Beam_RS232out' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: Could not open serial port /dev/virtualcom0: Serial port '/dev/virtualcom0' could not be found. Available ports are:
/dev/ttyUSB0
/dev/ttyS0

I tripple-checked every line for spelling errors, but cant find anything. Probably its a total stupid reason :weary:

Hi Rainer,
It looks like you are give the solution for my Serialport issue with OpenHAB 2.5 on my synology system. Thanks. I cab locate the file and find the location to add EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyEnocean" Problem is that I can save the file. The rights seem to be correct. See error message. Can you help to get this solved. scp: /volume1/@appstore/openHAB/runtime/bin/setenv: set times: Operation not permitted