Adding serial port in OpenHAB2

Hi, I’ve just acquired a z-wave stick, and all works great. However it starts off appearing on /dev/ttyACM0, and after unplugging (to bind to a z-wave device) and re-plugging it’ll appear as /dev/ttyACM1, and everything breaks. Now I"m aware of the instructions in here but unfortunately I’m running OpenHAB2 on a QNAP server, which resets the rules.d directory on every reboot, so that’s a no-go. On the upside the QNAP already provides some convenient dynamic symlinks sorted by device/manufacturer id, in my case /dev/serial/by-id/usb-0658_0200-if00. However the z-wave controller throws errors saying this serial port doesn’t exist when I try and configure my z-wave stick to use it.

The instructions for enabling a new non-standard serial port in OpenHAB1 are in the link above, but I can’t find anything anywhere for OH2. I tried adding this line to my conf/runtime.cfg file

…but it doesn’t have any effect. Does anyone know how to add a new port in OH2?

I’m on OH 1 but this should work with OH 2. Where possible I pair the device with the controller still plugged in by setting it to pair mode through Habmin. When I can’t do that because the range is just too far and I can’t move the device I shutdown OH before unplugging the controller and starting OH back up after replugging it in. I’ve just the one dongle so it always ends up on the same device.

I don’t know OH 2 very well but these parameters need to be added in whatever script that starts OH contains the call to java. The parameters need to be applied to that call, assuming it still works like that in OH 2.

Habmin2 doesn’t work for me sadly… the interface loads up fine, but barely anything is clickable, and occasionally a %%KEY_NOT_FOUND%% error appears in the top-right when I try and select something. e.g. when trying to Chart my Presence status:

2016-04-12 22:12:18.291 [DEBUG] [.jetty.server.handler.ContextHandler] - scope null||/rest/persistence/Presence @ HttpServiceContext{httpContext=DefaultHttpContext [bundle=org.openhab.ui.habmin_2.0.0.201603311030 [159], contextID=default]}

Shame really, I’d love to use it, but have searched high and low and can’t find what that error means so have given up for the time being.

On the upside at least I’ve solved my own problem here… all the config is in runtime/karaf/etc/openHAB-wrapper.conf … inside that is a long list of JVM parameters, so I just added one to the end saying and now the port is enabled!

Because of how the kernel allocates serial ports, what you could try is to unplug it again after /dev/ttyACM1 gets created. When you plug it back in a second time, you might be back to ACM0.

You’re right, it does indeed do that. However defining the port as above avoids this, so I’m happy at the moment!

On the upside at least I’ve solved my own problem here… all the config is in runtime/karaf/etc/openHAB-wrapper.conf … inside that is a long list of JVM parameters, so I just added one to the end saying and now the port is enabled!

i’me struggling with the same problem that i can’t connect via the serial binding. But in addition I can’t find the file you described… What’s different in my setup? Raspberry Pi2 with Openhab2 Beta2

i get this error message:
Dispatching event to subscriber ‘org.eclipse.smarthome.core.internal.items.ItemUpdater@9d111a’ takes more than 5000ms.

Can anyone help?

Actually I’ve moved towards running OH2 on a VirtualMachine on my server now (short story - my QNAP server only runs a limited version of Linux, so I’m running OH2 in an Ubuntu virtual machine for better compatibility), so have done a complete reinstall. I can’t find that file either now!

Solution is to edit runtime/karaf/bin/setenv, adding the line into JAVA_OPTS section that’s near the top (don’t forget to move the quotation mark from the end of the current set of lines, and put it at the end of the line you add in)

Might be that you need to update ownership of that serial port shortcut unless you’re running OH under a root-level user; if you don’t then you might still get the missing serial port error.

EDIT: Spoke too soon, it seemed to work once, and now doesn’t again :sob:

EDIT2: Actually it does work for me, but I have to run OH as sudo else it can’t access the port, even though I’ve chown’d it to my username

thank you for the quick response!

i added the port to the JAVA_OPTS but unfortunately it still doesn’t work:
export JAVA_OPTS="${JAVA_OPTS} -Dopenhab.home=${OPENHAB_HOME} -Dopenhab.conf=${OPENHAB_CONF} -Dopenhab.runtime=${OPENHAB_RUNTIME} -Dopenhab.userdata=${OPENHAB_USERDATA} -Dorg.osgi.service.http.port=${HTTP_PORT}${HTTPS_PORT}"

this seems to be correct to:
    pi@raspberrypi:~ $ ps -ef | grep tty
    root       540     1  0 18:43 tty1     00:00:00 /bin/login -f
    root       542     1  0 18:43 ?        00:00:00 /sbin/agetty --keep-baud 115200 38400 9600 ttyAMA0 vt102
    root       759   511  0 18:43 tty7     00:00:01 /usr/bin/X :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
    pi        1131   540  0 18:43 tty1     00:00:00 -bash
    root      1994  1987 63 18:49 pts/1    00:03:29 /usr/bin/java -`agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -Dopenhab.home=/opt/openhab -Dopenhab.conf=/opt/openhab/conf -Dopenhab.runtime=/opt/openhab/runtime -Dopenhab.userdata=/opt/openhab/userdata -Dorg.osgi.service.http.port=8080 -Xmx256m -Djava.awt.headless=true -Djava.endorsed.dirs=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/jre/lib/endorsed:/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/endorsed:/opt/openhab/runtime/karaf/lib/endorsed -Djava.ext.dirs=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/jre/lib/ext:/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/ext:/opt/openhab/runtime/karaf/lib/ext -Dkaraf.instances=/opt/openhab/runtime/karaf/instances -Dkaraf.home=/opt/openhab/runtime/karaf -Dkaraf.base=/opt/openhab/userdata -Dkaraf.etc=/opt/openhab/runtime/karaf/etc -Djava.util.logging.config.file=/opt/openhab/userdata/etc/ -Dkaraf.startLocalConsole=true -Dkaraf.startRemoteShell=true -classpath /opt/openhab/runtime/karaf/lib/boot/org.apache.karaf.diagnostic.boot-4.0.3.jar:/opt/openhab/runtime/karaf/lib/boot/org.apache.karaf.jaas.boot-4.0.3.jar:/opt/openhab/runtime/karaf/lib/boot/org.apache.karaf.main-4.0.3.jar:/opt/openhab/runtime/karaf/lib/boot/org.osgi.core-6.0.0.jar org.apache.karaf.main.Main`

The port gets blocked by openhab but nothing happens. Doesn’t matter if i use sudo or not.

I use following config. Do you see something wrong here?


String Arduino "Arduino" {serial="/dev/ttyUSB1@115200"}

rule "bedroomLight on off"
Item bedroomLight changed

    				Arduino.sendCommand("int a 1 1 1\r");
    				Arduino.sendCommand("int a 1 1 0\r");

the arduino isn’t blinking and no error output in the logs:

`2016-04-24 19:03:22.685 [INFO ] [marthome.event.ItemStateChangedEvent] - bedroomLight changed from OFF to ON
2016-04-24 19:03:22.706 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Arduino' received command int a 1 1 1
2016-04-24 19:03:22.736 [INFO ] [marthome.event.ItemStateChangedEvent] - Arduino changed from int a 1 1 0 to int a 1 1 1`