Page 1 of 1

Python Plugin Framework: UDP/IP Discovery Added

Posted: Saturday 12 August 2017 9:52
by Dnpwwo
UDP/IP listening has been added to the framework to allow plugins find and configure remote hardware instances on the network during start up.

A sample showing how to capture and log Dynamic Device Discovery messages has been added to the examples on Github here: https://github.com/domoticz/domoticz/bl ... scovery.py.

Tested successfully on Linux. Works on Windows for messages generated on the machine where Domoticz is running, Windows 10 appears to filter broadcast UDP from network devices even if a firewall rule exists permitting (anyone who knows how to stop that please post here).

Useful IP Address and Port combinations that can be set via the Hardware page:
  • 239.255.250.250:9161-Dynamic Device Discovery (DDD) (default, shows Global Cache, Denon Amps and more)
  • 239.255.255.250:1900 -Simple Service Discovery Protocol (SSDP), (shows Windows, Kodi, Denon, Chromebooks, Gateways, ...)
listening is as easy as:

Code: Select all

self.BeaconConn = Domoticz.Connection(Name="Beacon", Transport="UDP/IP", Address=Parameters["Address"], Port=str(Parameters["Port"]))
self.BeaconConn.Listen()
messages are returned to the plugin via the 'onMessage' call back.

Available in next beta or now if building from source.

Re: Python Plugin Framework: UDP/IP Discovery Added

Posted: Monday 18 September 2017 19:43
by Boredcat
This could be this issue :

https://www.tenforums.com/tutorials/496 ... -10-a.html

Look at option 2. Sharing.

Re: Python Plugin Framework: UDP/IP Discovery Added

Posted: Monday 12 November 2018 23:15
by Veda
I am going to shamelessly bump this.

I was trying your example. It lacks a way to "ask" on the UDP port to 'ask' so to say which devices are there. I tried a couple of ways, but none did work:

The way I think it should work:

Code: Select all

        sAddress = "239.255.255.250"
        sPort = "1900"
        self.BeaconConn = Domoticz.Connection(Name="Beacon", Transport="UDP/IP", Address=sAddress, Port=str(sPort))
    
        data = \ 
            "M-SEARCH * HTTP/1.1\n"+\
            "HOST: 239.255.255.250:1900\n"+\
            "MAN: \"ssdp:discover\"\n"+\
            "MX: 1\n"+\
            "ST: ssdp:all\n\n";
        self.BeaconConn.Send(Message=data)
        self.BeaconConn.Listen()
Ended with Segmentation fault (core dumped)

Try with a separate connection. I suspect Domoticz to reuse the other connection, so internally this is probably more or less the same?

Code: Select all

        sAddress = "239.255.255.250"
        sPort = "1900"
        self.BeaconConn = Domoticz.Connection(Name="Beacon", Transport="UDP/IP", Address=sAddress, Port=str(sPort))
        self.BeaconConn2 = Domoticz.Connection(Name="Beacon2", Transport="UDP/IP", Address=sAddress, Port=str(sPort))
    
        data = \ 
            "M-SEARCH * HTTP/1.1\n"+\
            "HOST: 239.255.255.250:1900\n"+\
            "MAN: \"ssdp:discover\"\n"+\
            "MX: 1\n"+\
            "ST: ssdp:all\n\n";
        self.BeaconConn2.Send(Message=data)
        self.BeaconConn.Listen()
Also an Segmentation fault (core dumped)

So then maybe have a delay before we sent the data?

Code: Select all

        sAddress = "239.255.255.250"
        sPort = "1900"
        self.BeaconConn = Domoticz.Connection(Name="Beacon", Transport="UDP/IP", Address=sAddress, Port=str(sPort))
        #self.BeaconConn2 = Domoticz.Connection(Name="Beacon2", Transport="UDP/IP", Address=sAddress, Port=str(sPort))
    
        data = \ 
            "M-SEARCH * HTTP/1.1\n"+\
            "HOST: 239.255.255.250:1900\n"+\
            "MAN: \"ssdp:discover\"\n"+\
            "MX: 1\n"+\
            "ST: ssdp:all\n\n";
        self.BeaconConn.Send(Message=data, Delay=4)
        self.BeaconConn.Listen()
2018-11-12 23:12:30.033 Error: (myplugin) Connectionless Transport is listening, write directive to 'Beacon' ignored.


I am out of options. Got any clue?

Re: Python Plugin Framework: UDP/IP Discovery Added

Posted: Saturday 17 November 2018 22:51
by Veda
I figured out why the segmentation fault happened (I debugged the C++ code...). You need to put the "Protocol" thing in there. Adding Protocol="None" solved the segmentation fault.

Now with what I was trying to do, the devices do not answer in the broadcast channel but do only answer to the caller on that port. Domotics does not listen to that.