Problem with UDP and specifying a port

Hi - I’m very new to OH and am trying to create a UDP item that will represent a sensor on a remote node. The sensor will send an update from a specific IP address and port; as there may be more than 1 sensor connected to the node I think the port is required to identify the actual sensor.

I modified the openhab.cfg file to have the following
# UDP parameters ™
net_addr(“127.0.0.1”)udp:updatewithresponse=false
pd:charset=ASCII
udp:port=9000

The item definition is
String Garage_Back_Door “Back Door [%s]” (Garage)
{
udp="<[192.168.0.100:7892:‘REGEX((.*))’]"
}

OH startup shows
2016-07-27 11:32:17.033 [INFO ] [.service.AbstractActiveService] - UDP Refresh Service has been started
2016-07-27 11:32:17.034 [INFO ] [t.protocol.internal.UDPBinding] - The maximum time out for blocking write operations will be set to the default vaulue of 3000
2016-07-27 11:32:17.036 [INFO ] [t.protocol.internal.UDPBinding] - The blocking nature of read/write operations will be set to the default vaulue of false
2016-07-27 11:32:17.042 [INFO ] [t.protocol.internal.UDPBinding] - The preamble for all write operations will be set to the default vaulue of
2016-07-27 11:32:17.043 [INFO ] [AbstractDatagramChannelBinding] - We will accept data coming from the remote end /192.168.0.100:7892
2016-07-27 11:32:17.044 [INFO ] [t.protocol.internal.UDPBinding] - The postamble for all write operations will be set to the default vaulue of
2016-07-27 11:32:17.052 [INFO ] [t.protocol.internal.UDPBinding] - The characterset will be set to the default vaulue of ASCII

When I send a test message from a client I get
2016-07-27 11:35:34.029 [WARN ] [AbstractDatagramChannelBinding] - Received data test
from an undefined remote end /192.168.0.100:7892. We will not process it
2016-07-27 11:35:34.032 [WARN ] [AbstractDatagramChannelBinding] - No channel is active or defined for the data we received from /192.168.0.100:7892. It will be discarded.

If I modify the item to use * for the port
String Garage_Back_Door “Back Door [%s]” (Garage)
{
udp="<[192.168.0.100::'REGEX((.))’]"
}

I get the following from the OH refresh
-27 11:37:10.227 [WARN ] [AbstractDatagramChannelBinding] - When using address masks we will not verify if we are already listening to similar incoming connections
2016-07-27 11:37:10.231 [INFO ] [AbstractDatagramChannelBinding] - We will accept data coming from the remote end 192.168.0.100:*
2016-07-27 11:37:10.234 [INFO ] [AbstractDatagramChannelBinding] - We will accept data coming from the remote end with mask 192.168.0.100:*

Running the test client now shows
2016-07-27 11:38:42.143 [INFO ] [runtime.busevents ] - Garage_Back_Door state updated to test

and the browser shows the item receiving the new “test” status

If I now change the item back to port 7892 the refresh shows
2016-07-27 11:42:04.075 [INFO ] [.service.AbstractActiveService] - UDP Refresh Service has been started
2016-07-27 11:42:04.079 [INFO ] [AbstractDatagramChannelBinding] - We will accept data coming from the remote end /192.168.0.100:7892

Running the test client produces
2016-07-27 11:43:01.995 [ERROR] [t.protocol.internal.UDPBinding] - transformation throws exception [transformation=null, response=test2
]
java.lang.NullPointerException: null
at java.util.regex.Matcher.getTextLength(Matcher.java:1283) ~[na:1.8.0_65]
at java.util.regex.Matcher.reset(Matcher.java:309) ~[na:1.8.0_65]
at java.util.regex.Matcher.(Matcher.java:229) ~[na:1.8.0_65]
at java.util.regex.Pattern.matcher(Pattern.java:1093) ~[na:1.8.0_65]
at org.openhab.binding.tcp.protocol.internal.UDPBinding.splitTransformationConfig(UDPBinding.java:236) [bundlefile:na]
at org.openhab.binding.tcp.protocol.internal.UDPBinding.transformResponse(UDPBinding.java:254) [bundlefile:na]
at org.openhab.binding.tcp.protocol.internal.UDPBinding.parseBuffer(UDPBinding.java:150) [bundlefile:na]
at org.openhab.binding.tcp.AbstractDatagramChannelBinding.parseChanneledBuffer(AbstractDatagramChannelBinding.java:998) [bundlefile:na]
at org.openhab.binding.tcp.AbstractDatagramChannelBinding.execute(AbstractDatagramChannelBinding.java:1505) [bundlefile:na]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) [org.openhab.core_1.8.3.jar:na]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) [org.openhab.core_1.8.3.jar:na]
2016-07-27 11:43:02.014 [INFO ] [runtime.busevents ] - Garage_Back_Door state updated to test2

However the status of the item is NOT updated; despite the statement in the OH output.

Am I doing something wrong in the configuration or transformation or ??

Any suggestions are much appreciated

Tom

@tjm

Hi Tom,

I think I have the same issue. Where you able to solve this somehow?

Michael

Hi Michael
I didn’t solve it in the manner I had hoped - using a UDP port
per sensor. Instead I created a string ITEM in HAB that receives a UDP
message containing a JSON record of all of the sensors and their states
from a single controller. A rule then parses the JSON record and posts
an update to each sensor. In the final analysis this probably results
in less WIFI traffic and less connect time. It will support multiple
controllers with sensors as each controller will have its own IP address
and I’m not planning on a large number of sensors per controller.

Good Luck
Tom

BTW I’m using an ESP8266 (NODEMCU) as the controller with 3 or 4 GPIO
connected switches

Hi Tom,

thanks for the fast and helpful answer!
Actually this is what I wanted to avoid :slight_smile:
I have a couple of Particle Photons doing similar things like your ESPs. They controls LED strips, measure temperatures and humidity. It’s a cool device. But I really struggle with the integration of the UDP responses from it.
Initially I have tried it in a similar way like you, but just via regex, but either I am too stupid or it simply doesn’t work. Then I have switched to send the different values from different ports. But then I figured out that openhab doesn’t receive data when I configure it with specific sender port like this:

String Temperature "Value: [%s]" { udp="<[192.168.178.40:8002:'REGEX((.*))']" }

Even more strange was that when I have switched to the wildcard

String Temperature "Value: [%s]" { udp="<[192.168.178.40:*:'REGEX((.*))']" }

and then back to the previous one it worked!
After a restard it was the same issue again. For me this is a bug. I also have posted something, but seems like nobody knows this topic.

Not sure what to do now, I still consider the parsing as a plan B but don’t like this solution.

Hi Michael
I agree its a bug but I don’t know what to do about it but I
may have to try OPENHAB 2 to see if it will work on that version and if
it still fails try and figure out how to report a bug rather than a
community post. (when and if I find time)

Cheers
Tom