Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Add UPB binding to OH2, Fixes #4811 #4814

Merged
merged 1 commit into from
Nov 24, 2016
Merged

Conversation

watou
Copy link
Contributor

@watou watou commented Nov 23, 2016

@cvanorman This look OK to you?

Signed-off-by: John Cocula john@cocula.com

Signed-off-by: John Cocula <john@cocula.com>
@watou watou added this to the 1.9.0 milestone Nov 23, 2016
@watou watou merged commit ba60275 into openhab:master Nov 24, 2016
@watou watou deleted the upb-binding-oh2 branch November 24, 2016 08:29
@watou
Copy link
Contributor Author

watou commented Nov 24, 2016

If further changes are needed, a new PR can be opened.

@DaAwesomeP
Copy link

Thank you!

@DaAwesomeP
Copy link

@watou this doesn't seem to work. I configured it properly in services/upb.cfg and was sure to remove my JAR from the previous version. I'm using the latest snapshot on Debian 8. All I see in the log that's relevant:

[INFO ] [nhab.binding.upb.internal.UPBBinding] - UPB binding starting up...
[INFO ] [b.core.service.AbstractActiveService] - UPB Service has been started

Config:

# The refresh frequency, in milliseconds (optional, defaults to 3600000)
#refresh=

# The UPB modem port. Valid values are e.g. COM1 for Windows and /dev/ttyS0 or
# /dev/ttyUSB0 for Linux (required)
port=/dev/ttyS0

# UPB Netword ID (required, must be a value between 0 and 255, inclusive)
network=135

An example item:

Dimmer Light1 "Lights" (Lights) {upb="id=3 link=true"}

Do I need to reconfigure all of my items to some new syntax?

@watou
Copy link
Contributor Author

watou commented Nov 25, 2016

Can you configure the binding from the Paper UI?

@DaAwesomeP
Copy link

Where can I configure it in Paper UI? It's not in the Bindings config tab.

@DaAwesomeP
Copy link

So I switched to openhab2-online (from openhab2-offline), and now I'm getting a "port does not exist" error. I tried configuring it in both openhab.cfg and upb.cfg. I can find no config for it in Paper UI.

@DaAwesomeP
Copy link

@watou is there anything I can do? I've been using the old binding. The openhab user is in the dialout group, so I don't know what's causing this.

[INFO ] [nhab.binding.upb.internal.UPBBinding] - UPB binding starting up...
[ERROR] [org.openhab.binding.upb             ] - [org.openhab.binding.upb.binding(189)] The activate method has thrown an exception
java.lang.RuntimeException: Failed to open serial port.
        at org.openhab.binding.upb.internal.UPBBinding.activate(UPBBinding.java:81)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_111]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_111]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_111]
        at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_111]
        at org.apache.felix.scr.impl.helper.BaseMethod.invokeMethod(BaseMethod.java:222)
        at org.apache.felix.scr.impl.helper.BaseMethod.access$500(BaseMethod.java:37)
        at org.apache.felix.scr.impl.helper.BaseMethod$Resolved.invoke(BaseMethod.java:615)
        at org.apache.felix.scr.impl.helper.BaseMethod.invoke(BaseMethod.java:499)
        at org.apache.felix.scr.impl.helper.ActivateMethod.invoke(ActivateMethod.java:295)
        at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:302)[33:org.apache.felix.scr:2.0.2]
        at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:113)[33:org.apache.felix.scr:2.0.2]
        at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:866)[33:org.apache.felix.scr:2.0.2]
        at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:833)[33:org.apache.felix.scr:2.0.2]
        at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:774)[33:org.apache.felix.scr:2.0.2]
        at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse$1.run(ServiceFactoryUse.java:212)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at java.security.AccessController.doPrivileged(Native Method)[:1.8.0_111]
        at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.factoryGetService(ServiceFactoryUse.java:210)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.getService(ServiceFactoryUse.java:111)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.eclipse.osgi.internal.serviceregistry.ServiceConsumer$2.getService(ServiceConsumer.java:45)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:496)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.getService(ServiceRegistry.java:461)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.eclipse.osgi.internal.framework.BundleContextImpl.getService(BundleContextImpl.java:619)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.obtain(EventHandlerProxy.java:286)[3:org.apache.karaf.services.eventadmin:4.0.4]
        at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:407)[3:org.apache.karaf.services.eventadmin:4.0.4]
        at org.apache.felix.eventadmin.impl.tasks.HandlerTask.runWithoutBlacklistTiming(HandlerTask.java:102)[3:org.apache.karaf.services.eventadmin:4.0.4]
        at org.apache.felix.eventadmin.impl.tasks.SyncDeliverTasks.execute(SyncDeliverTasks.java:104)[3:org.apache.karaf.services.eventadmin:4.0.4]
        at org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks$TaskExecuter.run(AsyncDeliverTasks.java:163)[3:org.apache.karaf.services.eventadmin:4.0.4]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_111]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_111]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_111]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_111]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_111]
Caused by: java.lang.RuntimeException: Port does not exist
        at org.openhab.binding.upb.internal.UPBBinding.openSerialPort(UPBBinding.java:234)
        at org.openhab.binding.upb.internal.UPBBinding.activate(UPBBinding.java:77)
        ... 32 more
Caused by: gnu.io.NoSuchPortException
        at gnu.io.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:273)
        at org.openhab.binding.upb.internal.UPBBinding.openSerialPort(UPBBinding.java:232)
        ... 33 more
[ERROR] [org.openhab.binding.upb             ] - [org.openhab.binding.upb.binding(189)] Failed creating the component instance; see log for reason
[WARN ] [org.openhab.binding.upb             ] - FrameworkEvent WARNING - org.openhab.binding.upb
org.osgi.framework.ServiceException: org.apache.felix.scr.impl.manager.SingleComponentManager.getService() returned a null service object
        at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.factoryGetService(ServiceFactoryUse.java:232)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.getService(ServiceFactoryUse.java:111)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.eclipse.osgi.internal.serviceregistry.ServiceConsumer$2.getService(ServiceConsumer.java:45)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:496)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.getService(ServiceRegistry.java:461)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.eclipse.osgi.internal.framework.BundleContextImpl.getService(BundleContextImpl.java:619)[org.eclipse.osgi-3.10.2.v20150203-1939.jar:]
        at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.obtain(EventHandlerProxy.java:286)[3:org.apache.karaf.services.eventadmin:4.0.4]
        at org.apache.felix.eventadmin.impl.handler.EventHandlerProxy.sendEvent(EventHandlerProxy.java:407)[3:org.apache.karaf.services.eventadmin:4.0.4]
        at org.apache.felix.eventadmin.impl.tasks.HandlerTask.runWithoutBlacklistTiming(HandlerTask.java:102)[3:org.apache.karaf.services.eventadmin:4.0.4]
        at org.apache.felix.eventadmin.impl.tasks.SyncDeliverTasks.execute(SyncDeliverTasks.java:104)[3:org.apache.karaf.services.eventadmin:4.0.4]
        at org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks$TaskExecuter.run(AsyncDeliverTasks.java:163)[3:org.apache.karaf.services.eventadmin:4.0.4]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_111]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_111]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_111]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_111]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_111]

@watou
Copy link
Contributor Author

watou commented Dec 11, 2016

Caused by: gnu.io.NoSuchPortException

Can you adapt the instructions here:

https://github.com/openhab/openhab/wiki/symlinks

To open the port? Or is the config not being read properly by the binding code?

@DaAwesomeP
Copy link

This is a hardware serial port on the back of the computer. Its assignment never changes, so a udev rule is unnecessary. Adding the old binding into /usr/openhab2/addons and using services/openhab.cfg works perfectly, so I don't think that it's an issue with the serial port. The contents of /etc/openhab2/services/upb.cfg:

# The refresh frequency, in milliseconds (optional, defaults to 3600000)
refresh=3600000

# The UPB modem port. Valid values are e.g. COM1 for Windows and /dev/ttyS0 or
# /dev/ttyUSB0 for Linux (required)
port=/dev/ttyS0

# UPB Netword ID (required, must be a value between 0 and 255, inclusive)
network=135

It's very possible that the config is not being read properly by the binding since that's definitely something that changed from the older working version of the addon to the PaperUI-installed version.

@watou
Copy link
Contributor Author

watou commented Dec 11, 2016

This is a hardware serial port on the back of the computer. Its assignment never changes, so a udev rule is unnecessary.

Sorry, I wasn't clear. I was referring to this part:

You will also need to add the property to the Java command line by adding the following (device names delimited by : ) to the file /etc/init.d/openhab in the 'JAVA_ARGS' section with your device names substituted:

-Dgnu.io.rxtx.SerialPorts=/dev/USBrfxcom:/dev/USBzwave

I've made a small change so that the activate method will skip its steps if it's passed a null configuration. A test JAR is here. Please replace your binding bundle with this one and see if it succeeds in opening the port. Beforehand, please issue

openhab> log:set DEBUG org.openhab.binding.upb

@DaAwesomeP
Copy link

I added -Dgnu.io.rxtx.SerialPorts=/dev/ttyS0 to EXTRA_JAVA_OPTS in /etc/default/openhab2 to no avail.

I enabled the DEBUG logging and used the JAR you gave me and put it into /usr/share/openhab2/addons and restarted the service:

[DEBUG] [org.openhab.binding.upb             ] - ServiceEvent REGISTERED - {org.openhab.model.item.binding.BindingConfigReader, org.openhab.binding.upb.UPBBindingProvider}={component.name=org.openhab.binding.upb.genericbindingprovider, component.id=33, service.id=127, service.bundleid=207, service.scope=bundle} - org.openhab.binding.upb
[DEBUG] [org.openhab.binding.upb             ] - BundleEvent [unknown:512] - org.openhab.binding.upb
[DEBUG] [org.openhab.binding.upb             ] - BundleEvent STARTING - org.openhab.binding.upb
[DEBUG] [org.openhab.binding.upb             ] - BundleEvent STARTED - org.openhab.binding.upb
[INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'upb.items'
[DEBUG] [nhab.binding.upb.internal.UPBBinding] - Parsed UPB configuration:
[DEBUG] [nhab.binding.upb.internal.UPBBinding] - Serial port: /dev/ttyS0
[DEBUG] [nhab.binding.upb.internal.UPBBinding] - UPB Network: 135
[INFO ] [nhab.binding.upb.internal.UPBBinding] - UPB binding starting up...
[DEBUG] [org.openhab.binding.upb             ] - ServiceEvent REGISTERED - {org.osgi.service.event.EventHandler}={event.topics=openhab/command/*, service.pid=org.openhab.upb, port=/dev/ttyS0, refresh=3600000, network=135, component.name=org.openhab.binding.upb.binding, component.id=32, service.id=261, service.bundleid=207, service.scope=bundle} - org.openhab.binding.upb

There are no errors, but it doesn't work. There are also no debug messages logged about the command sent as there usually are when it sends a command. I don't know what magic sauce is in the bundle I've been using. It's from here.

@cvanorman
Copy link
Contributor

Sorry for my slow and infrequent responses, my time is not usually my own. I tried downloading a clean openhab2-online distribution and had no issues with getting the serial connection to work. It is receiving messages when I press a physical switch, but it does not seem to be receiving the list of supported items. When I activate an item in OpenHAB, the binding doesn't respond.

Regardless, I will have some time over the Christmas break here and will investigate converting it to the OpenHAB2 way of "things". Hopefully, that will address these issues.

@DaAwesomeP
Copy link

@cvanorman there's one slight annoyance in the binding that would be awesome if it could be improved. I'm currently using some empty links to trigger rules in OH. The slight problem is that in each one, I have to check for a double command, as all of my switches broadcast twice for reliability. This can definitely be patched, as each command contains a byte for "command 1 of 2" and "command 2 of 2." It should be as simple as storing the last received command and seeing if it's the same command other than the broadcast count. It should still work if it misses the first broadcast but only receives the second. Sadly, the PIM automatically sends the multi-broadcast commands, but it doesn't filter them out for the received commands.

mvolaart pushed a commit to mvolaart/openhab that referenced this pull request Dec 23, 2016
Signed-off-by: John Cocula <john@cocula.com>
@cvanorman
Copy link
Contributor

I have done an update to this binding (see openhab/openhab2-addons#1620).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants