I just went created a new crater in my desk with my forehead trying to get udp bindings to work with a remote serial to tcp/udp bridge. There’s a few things you need to configure. I’ll ignore all the transformation side of things.
The Item binding is about the remote device that you’re controlling and not your local openHAB server. So your binding (below) is saying that you are expecting an incoming message FROM 192.168.20.12:5006. That is, the source port is 5006, not the destination port. You said the machine is sending from port xxxxx TO port 5006. So change your binding to look like this (wildcard the port):
Switch Light_Test "Light Test" <light> { udp="<[ON:192.168.20.12:*:'REGEX((ON))']" }
Next, to make openHAB listen on port 5006, add this into openhab.cfg
udp:port=5006
openHAB will also automatically listen on any port it opens to send commands to remote udp ports if you have an outbound binding configured as well.
I’m using two String item types since the RS485 bridge I’m using sends and receives state and command messages (to/from Philips Dynalite). Basically, the remote unit listens on port udp/1000 for incoming messages, and will send back messages TO udp/1001. So my items look like this:
String IO_Dynet_Send "[%s]" { udp=">[192.168.10.250:1000:'REGEX((.*))']" }
String IO_Dynet_Receive "[%s]" { udp="<[192.168.10.250:*:'REGEX((.*))']" }
Then in openhab.cfg I have (amongst other things):
udp:updatewithresponse=true
udp:charset=ASCII
udp:port=11001
And what this then shows when I look at open ports is (openHAB is on 192.168.10.200 and the bridge is .250):
[~/]# ss -napu | grep java
ESTAB 0 0 ::ffff:192.168.10.200:57694 ::ffff:192.168.10.250:1000 users:(("java",pid=5345,fd=229))
UNCONN 0 0 :::11001 :::* users:(("java",pid=5345,fd=227))
Any message coming from 192.168.10.250 for an incoming port of 11001 or 57694 will be captured. Next time openHAB restarts that 57xxx port will almost certainly be something else, and it’ll listen on that instead. The udp:updatewithresponse setting in openhab.cfg determines if the replies on that outgoing binding are taken in or ignored.
Those that are more observant and reading along, will have spotted that I mentioned incoming data will be arriving on port 1001, yet my configuration is for 11001. Neither of those are typos. The problem with 1001 is that it’s less than 1024, making it a privileged port and since openHAB doesn’t run as “root” on my server, it cannot listen on port 1001. So instead since it’s running on Linux and iptables really makes this sort of thing easy, I have an iptables rule in the PREROUTING chain of the nat table to redirect incoming udp/1001 traffic to udp/11001. Done like this:
iptables -A PREROUTING -p udp --dport 1001 -j REDIRECT --to-ports 11001
That last one took me a while to solve, because it didn’t even occur to me that it was a privileged port issue, and just like you I couldn’t make openHAB listen on the right port, no matter what I tried.
Alex.