UDP Bridge thing and Items

Tags: #<Tag:0x00007f5c953a72a0> #<Tag:0x00007f5c953a71b0> #<Tag:0x00007f5c953a70e8>

Hi There,
I am new with OpenHab2. I am trying get date from an UDP generic object (ESP8266 that sends UDP packets).
This object sends a JSON message, as below :

{ 
   "NodeID" : "8bf619a620a0", 
   "NodeName" : "node12", 
   "IPAddress" : "192.168.0.69", 
   "Temperature" : "21.00", 
   "Humidity" : "33.00%", 
   "ButtonState" : "0"
}

I would like to define a Things with multiple channels. I don’t knows if this is the best way but I thought a definition like this in the .things file :

Thing network:device:buttonbox117 "Bouton117" @ "Salle 117" {
  Channels:
       Number : Temperature [ udp="<[192.168.0.69:*:JSONPATH($.Temperature)"]
       Switch : ButtonState [ udp="<[192.168.0.69:*:JSONPATH($.ButtonState)"]
  }

… And then I have defined these Items in .items file :

// Don't erase this line : bug on UDP service. We need at least a UDP configuration to launch UDP Listener
Number X "Ignore" <temperature> {udp="<[192.168.0.254:6060:default]"}

Switch UDP_Boitier_button "Présence" <switch> ["Salle 117"] { Channel="network:device:buttonbox117#ButtonState" }
Number:Temperature UDP_Boitier "Température boitier" <temperature> ["Salle 117"] { Channel="network:device:buttonbox117#Temperature" }

Finally, I wrote a debug rule, of course in a .rules file :

rule "UDP Test"
when
    Item UDP_Boitier changed 
then
    var myState = getThingStatusInfo("network:device:buttonbox117#temperature") 
    if (myState != Null) {
        logInfo("UDP_Boitier sent ===========> ",  myState)
    } else {
        logWarn("UDP_Boitier sent No value ?? ", myState)
    }
end

When I take a look at the logs, I have some warning :

...
2019-01-28 17:46:10.697 [WARN ] [ing.tcp.protocol.internal.UDPBinding] - No provider could be found for the item 'UDP_Boitier'
2019-01-28 17:46:10.703 [WARN ] [ing.tcp.protocol.internal.UDPBinding] - No provider could be found for the item 'UDP_Boitier'
2019-01-28 17:46:10.709 [WARN ] [ing.tcp.protocol.internal.UDPBinding] - No provider could be found for the item 'UDP_Boitier'
2019-01-28 17:46:10.714 [WARN ] [ing.tcp.protocol.internal.UDPBinding] - No provider could be found for the item 'UDP_Boitier'
2019-01-28 17:46:10.719 [WARN ] [ing.tcp.protocol.internal.UDPBinding] - No provider could be found for the item 'UDP_Boitier'
2019-01-28 17:46:10.725 [WARN ] [ing.tcp.protocol.internal.UDPBinding] - No provider could be found for the item 'UDP_Boitier'
2019-01-28 17:46:10.730 [WARN ] [ing.tcp.protocol.internal.UDPBinding] - No provider could be found for the item 'UDP_Boitier'

I suppose these line are generated because of the thing declaration ?
I don’t know what I am doing wrong for now ?
Is there a complete tutorial to set a multiple channels Thing by configuration (i.e. writing in `/etc/openhab2/[things, Items, rules])

Well, first of all the Network binding is not going to do anything for you. It will just tell you whether a device is online of offline based on the result of ping or arping.

You need to use the TCP/UDP binding so make sure that is installed. The TCP/UDP binding is a 1.x version binding so it doesn’t support Things and Channels.

To read data from UDP, you must throw out the Thing entirely. Next you need to define your Item as documented in https://www.openhab.org/addons/bindings/tcp1/. It will probably look a lot like what you tried to put in the Thing definition only on the Item. See the two examples at the bottom of the page.

Thing definitions are completely defined by the binding you are using. The complete definition will be documented in the readme page for that specific binding. So there is no generic tutorial.

For the most part, although there is some controversy over this, you shouldn’t be defining things manually yourself (unless you have a really compelling reason to). Create Things through the UIs and let OH manage them. Then you don’t need to know the specifics of the format and you can take advantage of automatic discovery.

Hi,
Tanks for this usefull an comprehensive answer.

I unsderstand, but I don’t define a thing, how does the channels and linked Item appear in paperui user interface ?

Further more I have noticed that UDP Item binding won’t work with a specific defined port :

Number UDP_Boitier_Temp "Température boitier" <temperature> ["Salle 117"] { udp="<[192.168.0.69:6060:JSONPATH($.Temperature)]" }

This Item above does not work : UDP listening is nerver getting the UDP packet from 192.168.0.69, port 6060.
When I put a *instead of port number, this works fine.

Number UDP_Boitier_Temp "Température boitier" <temperature> ["Salle 117"] { udp="<[192.168.0.69:*:JSONPATH($.Temperature)]" }

this may be a bug ?

They don’t. PaperUI can only deal with OH 2.x version bindings. The TCP/UDP Binding is a 1.x version binding so you cannot do anything with it in PaperUI.

I don’t use this binding, but according to the docs, you set the ports to listen to in the usg.cfg file.

Perhaps it is working with TCP, but not with UDP. Only the * is working :thinking:, even if you set the port in udp.cfg.

Which UI can use to deal with UDP things ? habadmin ?

None. It’s a 1.x version binding. Only text based configs are possible.

I don’t use this binding so I can’t anything beyond help with the basics and what’s in the docs.

Perhaps it is working with TCP, but not with UDP. Only the * is working :thinking:, even if you set the port in udp.cfg.

It’s not a bug. The port definition in udp.cfg is for the incoming messages (destination), on this port the binding will run the listener. The port definition in the ‘item’ is part of the filter. There you can define, from which (source) ip-address:port messages shall be processed. Normally the source-port is a dynamic one, that’s the reason way you have to use a ‘*’ (wildcard) as port. Only if your client application uses a static (source) port, it will work without wildcard.

1 Like