Openhab2 udp binding

Having difficulty getting a simple UDP output binding to work on openHAB2.
Had this working on openHAB1, but want to switch to the latest code base (Downloaded the 2.0.0 snapshot yesterday. May 14, 2016).

My items file has this:

Switch MySwitch1 “My Switch” (gUnit1) { udp=">[ON:‘MAP(’], >[OFF:‘MAP(’]" }

Have a sitemap file with my group in and am able to see this item in the basic web UI.
However, when I click on the switch icon, I don’t see any UDP messages sent out (checking via wireshark, and also on my remote device). But I do see this error in the logfile:

2016-05-14 21:37:42.841 [ERROR] [g.tcp.AbstractDatagramChannelBinding] - there is no channel that services [itemName=MySwitch1, command=ON]

Note1: I see a similar error for the OFF command.

Note2: I’ve added a tcp.cfg file to my /conf/services directory with:


Note3: I see the following log, so I assume the udp binding is active.

2016-05-14 21:37:08.103 [INFO ] [g.tcp.AbstractDatagramChannelBinding] - Listening for incoming data on /0:0:0:0:0:0:0:0:13000

Note4: I’ve also tried to drop (and remove) the 1.8.2 tcp binding jar into the addons directory - doesn’t seem to change the behavour. I still get the above error & info logs.

Note5: Also looked at the newer openHAB2 syntax for items, things & channels but cannot figure out how to configure the channel string in the item file. Not even sure this makes sense, because how would the generic tcp/udp binding define or know what channels are available on my device?

Appreciate any advice/help with the “no channel” error and how to this up properly on openHAB2.

Continuing the discussion from TCP binding under OH2:


I have just adjusted some things and can confirm, xbmc and tcp/udp won’t load ( stats then stops) and won’t create items until you rename/save/modify either a openhab.cfg file or a specific “tcp.cfg” file in the service folder. Change the file name to tcp1.cfg after I have started OH2 and all the items/channels load and work. !!???

What is going on???

PS actually xbmc is still causing me some troubles as it won’t handle the “POST” Updates. Any thoughts on this.

i have the same issue with tcp right now, maybe we can get this fixed for both of us. i too have noticed it working after a change is made to the config file only after the system starts…my thread is at

Thanks for the reply @sihui

So I tried the same test, ie: rename my tcp.cfg to udp.cfg.
There is no difference in behaviour - still get the ERROR

2016-05-17 22:11:11.404 [ERROR] [g.tcp.AbstractDatagramChannelBinding] - there is no channel that services [itemName=MySwitch1, command=ON]

Thank you @Branden_Smale for the trail that you left here.
I was able to follow your post and install the tcp 1.9.0 binding.

This seems to work much better on 2 fronts:

  1. I was also getting those NPEs from the “deactivate method” - they’re gone now.
  2. Now my UDP packets are being sent out when I toggle the switch on the basic ui. This is great!

However, still one puzzle to solve. I now see the following warnings as my mapping is not working:

2016-05-17 22:49:30.368 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type MAP
2016-05-17 22:49:30.368 [WARN ] [ing.tcp.protocol.internal.UDPBinding] - couldn’t transform response because transformationService of type ‘MAP’ is unavailable

I get these warnings for both ON & OFF switch transitions.
Any ideas on this?

Individual transformation services have to be installed separately in OH2. Install the transformation from the Paper UI, or at the openhab> prompt:

openhab> feature:install openhab-tranformation-map

and see if the errors go away?

Thanks for the instructions @watou
UDP output from OH2 is working very well now.

1 Like

Now for UDP input…
Using this test item definition

String TestSensor “TestState [%s]” (gUnit1) { udp="<[]" }

I can see that my UDP input packet is received and displayed properly in the basic web UI, however I noticed the following in the log file:

2016-05-19 20:48:34.063 [INFO ] [marthome.event.ItemStateChangedEvent] - TestSensor changed from NULL to SwitchState=ON < followed by many Null characters >

Looks like the code that prints this log is printing the entire UDP packet buffer (1024 bytes) and not just the length of the actual data rec’d in the packet. (ie: 14 bytes in my example).
It seems like a small bug, yes?

This seems to be related to this old issue I reopened a few days ago:

@saerdnaer, any thoughts?

Thank you @watou. That sure looks like what I see in the logfile.

If I may… what do you think of this solution:
Assuming that result.array() is a byte array returned from the socket (or DatagramPacket object), then the result string could be built like so:

String receivedDataString = new String(byteArray, 0, actualNumberOfBytesReceived);

In this way, the receivedDataString contains the actual UDP payload.
Splitting or trimming may not get the right string.
(Although you could argue that trimming nulls or trailing white-space may be a good thing anyway).

It sounds reasonable. Would you open an issue or pull request, and see if other interested parties would test a code change?

1 Like

I guess I need a different account for github?
Anway… I see you’ve reopened the issue quoted above. Let’s see where it goes.