How to receive data on openhab using UDP ? (solved)



  • Hello !

    Here is the problem I am facing :

    I have an arduino node communicating using UDP. It sends on port 600 receives on port 500.
    I would like to be able to send and receive data to this node from the openhab.

    Sending data has been straight forward. It works nicely. On the other hand I did not manage to get
    any data from this node. I tried various changes in the config file and in the way to do the incoming
    binding but I still got warnings. Here are some information on my setup :

    items setup :

    String fromUDPnode "fromUDPnode" {udp="<[192.168.0.9:500:'REGEX((.*))']"}
    String toUDPnode "toUDPnode" {udp=">[192.168.0.9:500:'REGEX((.*))']"}
    
    

    config :

    udp:itemsharedconnections=true
    udp:bindingsharedconnections=true
    udp:directionssharedconnections=false
    udp:addressmask=true
    udp:postamble=
    udp:blocking=false
    udp:refreshinterval=250
    udp:port=600
    

    and here are the warnings I get :

     [WARN ] [AbstractDatagramChannelBinding] - Received data 10;59;1;0;23;0
             from an undefined remote end /192.168.0.9:500. We will not process it
     [WARN ] [AbstractDatagramChannelBinding] - No channel is active or defined for the data we received from /192.168.0.9:500. It will be discarded.
    

    seems openhab receives the data but discard them ...

    any clue on how to solve this issue ?

    Thanks



  • I had the same issue and found this post quite fast but although it says "(solved)" I found no solution. I am leaving my reply here for future reference.

    What I did to fix the "It will be discarded" message:

    [openhab.cfg]

    This sets up the receiving end of the binding i.e. the server that binds the 5005 port.

    udp:port=5005
    

    [default.items]

    This sets up the openhab binding to the string. Notice the asterisk after the IP address; because the client will connect to the server it will get assigned a random free port. The asterisk will catch all ports a client will get solving the "No channel is active or defined issue".

    String 	String_FF_Bath_Test 	"Test String[%s]" 	 {udp="<[127.0.0.1:\*:'REGEX((.\*))']"}
    

    [python]

    Just some test code to easily send a UDP message to openhab.

    import socket
    UDP_IP = "127.0.0.1"
    UDP_PORT = 5005
    MESSAGE = "Hello world!"
    
    print "UDP target IP:", UDP_IP
    print "UDP target port:", UDP_PORT
    print "message:", MESSAGE
    
    sock = socket.socket(socket.AF_INET, # Internet
                     socket.SOCK_DGRAM) # UDP
    sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))

Log in to reply
 

Suggested Topics

  • 3
  • 6
  • 2
  • 6
  • 8

1
Online

11.4k
Users

11.1k
Topics

112.7k
Posts