[co7io] BACnet v2 binding for openHAB 2.x

The “Binding - BACnet” step now has the following error.

[ERROR] Failed to execute goal on project org.connectorio.addons.binding.bacnet: Could not resolve dependencies for project org.connectorio.addons:org.connectorio.addons.binding.bacnet:bundle:3.3.0-SNAPSHOT: The the following artifacts could not be resolved: org.code-house.bacnet4j:api:jar:1.3.0-SNAPSHOT, org.code-house.bacnet4j:ip:jar:1.3.0-SNAPSHOT, org.code-house.bacnet4j :mstp:jar:1.3.0-SNAPSHOT: org.code-house.bacnet4j:api:jar:1.3.0-SNAPSHOT was not found in JFrog during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of openhab-snapshot has elapsed or updates are forced → [Help 1]

Change this line:
connectorio-addons/pom.xml at 3.3.x · ConnectorIO/connectorio-addons · GitHub, and set bacnet4j.wrapper to 1.3.0-alpha1 and plc4x-extras to 0.8.0. I made some changes in there, but they should not be critical for build.

Without latest wrapper you will miss support to have all objects at device level, but that’s not relevant for testing with 3.3 for now.

Made changes, the assembly was complete. Nothing has changed, older version 3.0.2 does not work( Testing on v3.0.2, v3.0.4, v3.1.0, my personal v3.2.0.

Do you see any error during installation or while startup of binding?

In the binding manager, the bacnet binding is visible. When you click on install, the installation freezes.

Try installing it via shell - do features:install co7io-binding-bacnet.

Thank you Lukasz!
Works on version 3.2.0. If there are problems, I will write.

Hello, after one month of using bacnet binding, I found out the following… Not without problems. I connected about 50 things, after which the SNMP protocol stopped working, the protocols working through the ethernet tcp/ip also began to work unstable. If you reduce the number of things, other protocols start to work more stable.

This is the input voltage when no more than 15 things are connected to the bacnet. SNMP

This graph is when about 50 things are connected. SNMP voltage monitoring protocol.

I suspect the bacnet is overloading the network, high refresh rate. Although I set 1000ms and higher everywhere, changing the polling time, I did not notice the difference. The processor and memory are normal for loading. Tested on different hardware.

Its likely a case, because binding sends few readout requests for each poll cycle for each object. I been lately adjusting this part and also doing some aggregation of polling (reading up to 3 objects at each cycle to avoid segmentation), but its still not ported to 3.3.x.
You can set logging to DEBUG for org.connectorio.addons.binding.bacnet.internal.handler.object.task.ReadObjectTask and see in detail if your polling settings are accepted. I found out that UI did not present them properly so they were possible to specify only via text configuration (also awaiting port).

Tell me how to set up debug mode? And also is there an instruction for a text configuration or at least one example? The one at the beginning of the article does not fit. I’m testing on version 3.2.0.
I noticed that a thing can be created separately, each or in one thing, any number of channels, but only as a presentValue.

The debug mode can be enabled using openhab shell (ssh -p 8101 openhab@127.0.0.1 or openhab-cli console default password AFAIR is habopen). After logging in into shell you just type log:set DEBUG org.connectorio.addons.binding.bacnet.internal.handler.object.task.ReadObjectTask. It should have immediate effect and result in multiple entries appended to your openhab log file.

The text file config is indeed out of date, however you can take yaml output you see in “config” tab displayed in UI and transform it into xtext file. I do not have any working example of it.

Created the config file, didn’t use the user interface. Turned on debugging as you advised. For the testing I used 40 things and polling time was set to 1000 ms. During the tests I found out that when OH makes a poll of devices, the whole polling happens to all 40 devices at the same time.

One device is 4 channels: eventState, present value, outOfService, reliability.
40*4=160 requests per cycle.

I changed the source code and left only 1 channel - presentValue. After this, it turned into 40 requests per cycle which made it more stable performancewise.

So I have a question: is it possible to make some sort of a pause between channels and things?

I am not sure what you mean, something like Modbus binding min delay between polls for device to?
Scheduler used for polling will queue multiple tasks, thus you might improve stability by increasing thingHandler thread pool size [1]. Your network will definitely survive that.

I think later version of binding (will try to push it over weekend) which groups channels at device level will improve stability cause it polls 3 channels at the time. If you have device with 50 objects then you will have 17 network calls instead of 50.

[1] ThreadPoolManager (openHAB Core 3.4.0-SNAPSHOT API)

I am not sure what you mean, something like Modbus binding min delay between polls for device to?

Yes, the minimum delay between polls.

How to increase the size of the pool did not figure it out.
At the moment, I left only one channel “present Value”, everything became stable. When you update to the new version, I will test it. For now, I’ll leave it as it is, it’s difficult for a beginner to continue.

Hello, after the last update, there is a compile-time crash:

Could not resolve dependencies for project org.connectorio.addons:org.connectorio.addons.binding.bacnet:bundle:3.2.0-SNAPSHOT: The following artifacts could not be resolved: org.code-house.bacnet4j:api:jar:1.3.0-SNAPSHOT, org.code-house.bacnet4j:ip:jar:1.3.0-SNAPSHOT, org.code-house.bacnet4j:mstp:jar:1.3.0-SNAPSHOT: org.code-house.bacnet4j:api:jar:1.3.0-SNAPSHOT was not found in JFrog during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of openhab-snapshot has elapsed or updates are forced

Hello @heavemann,
Please build GitHub - Code-House/bacnet4j-wrapper: Simple facade for bacnet4j api., which is used by bacnet binding (same for plc4x-extras) if you run into troubles of “could not resolve dependencies” kind. These are only two snapshots used currently in connectorio addons project. Once you build them locally they will be used to build KAR which you deploy into your openHAB.

The bacnet4j wrapper received some updates related to “long discovery” allowing binding run in larger networks. I successfully tested discovery of more than 800 devices running in one of skyscrapers. ;))) Updated version also streamlined support for recognition of MSTP devices behind bacnet routers. Binding itself also introduced possibility to manually register network routers through ip bridge configuration (mark advanced options). This means that you can communicate with devices without running discovery.

I started working on subscriptions (COVs), but they again overgrow available time, thus they again have to wait.

Please build GitHub - Code-House/bacnet4j-wrapper: Simple facade for bacnet4j api. , which is used by bacnet binding (same for plc4x-extras) if you run into troubles of “could not resolve dependencies” kind. These are only two snapshots used currently in connectorio addons project. Once you build them locally they will be used to build KAR which you deploy into your openHAB.

Hello Łukasz. I’m sorry, but I didn’t understand what to do. Can you help please.

You need to clone (checkout) bacnet4j project on machine which you use to build bacnet binding. Once you have copy of it you do mvn clean install inside bacnet4j-wrapper directory.

Hi, @splatch. Thanks for sharing this BACnet binding. According to attached documentation this binding does not support COV, is this going to be implemented sometime ? I’m asking cause I want to use embedded bacnet stack from GitHub - bacnet-stack/bacnet-stack: BACnet Protocol Stack library provides a BACnet application layer, network layer and media access (MAC) layer communications services. to implement some devices controlled by the human person (like light switches and scene controller) that need to send updates to the OpenHAB.

Hello @mczerski,
The COV handling was deferred for several years already. Since I got handling of calendar and schedule objects, the next big thing I plan to work on are COVs. I can’t declare exact time for that, but it will be supported at some point of time. Most likely second half of 2023 (using exact year for further generations!).
I already made some proof of concept code to recognize how bacnet4j (underlying library in binding) handles that. Now I have to think how to handle all edge cases which COVs bring into the table. Despite of lightness of COVs for communication they complicate in significant way logic of caller.

Ok, so I just had some time to test bacnet binding but I have quite a problem. I’m trying to setup mstp network under openhab 2.5.12 but I’m failing to add mstp bridge to openhab. Whether using paper ui or textual cnfiguration I just get this error (with bacnet binding bacnet-2.5.1.20201006 and bacnet-2.5.2-SNAPSHOT):

2023-03-19 13:12:43.953 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.initialize()' on 'org.connectorio.binding.bacnet.internal.handler.network.BACnetMstpBridgeHandler@4c7c4edb': jssc/SerialPortException
java.lang.NoClassDefFoundError: jssc/SerialPortException
	at org.connectorio.binding.bacnet.internal.handler.network.BACnetMstpBridgeHandler.initialize(BACnetMstpBridgeHandler.java:66) ~[?:?]
	at sun.reflect.GeneratedMethodAccessor74.invoke(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_275]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_275]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:152) [bundleFile:?]
	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_275]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_275]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_275]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_275]
Caused by: java.lang.ClassNotFoundException: jssc.SerialPortException cannot be found by org.code-house.bacnet4j.mstp_1.2.0
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484) ~[org.eclipse.osgi-3.12.100.jar:?]
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395) ~[org.eclipse.osgi-3.12.100.jar:?]
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387) ~[org.eclipse.osgi-3.12.100.jar:?]
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150) ~[org.eclipse.osgi-3.12.100.jar:?]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352) ~[?:1.8.0_275]
	... 10 more
2023-03-19 13:12:43.956 [ERROR] [core.thing.internal.ThingManagerImpl] - Exception occurred while initializing handler of thing 'co7io-bacnet:mstp:70e0258f': jssc/SerialPortException
java.lang.NoClassDefFoundError: jssc/SerialPortException
	at org.connectorio.binding.bacnet.internal.handler.network.BACnetMstpBridgeHandler.initialize(BACnetMstpBridgeHandler.java:66) ~[?:?]
	at sun.reflect.GeneratedMethodAccessor74.invoke(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_275]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_275]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:152) [bundleFile:?]
	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_275]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_275]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_275]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_275]
Caused by: java.lang.ClassNotFoundException: jssc.SerialPortException cannot be found by org.code-house.bacnet4j.mstp_1.2.0
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484) ~[org.eclipse.osgi-3.12.100.jar:?]
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395) ~[org.eclipse.osgi-3.12.100.jar:?]
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387) ~[org.eclipse.osgi-3.12.100.jar:?]
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150) ~[org.eclipse.osgi-3.12.100.jar:?]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352) ~[?:1.8.0_275]
	... 10 more

Seems like something is missing in the installation (java.lang.NoClassDefFoundError: jssc/SerialPortException ?).