Python Plugin Framework: UDP/IP Discovery Added

Python and python framework

Moderator: leecollings

Post Reply
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Python Plugin Framework: UDP/IP Discovery Added

Post 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.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Boredcat
Posts: 38
Joined: Friday 17 March 2017 9:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Netherlands
Contact:

Re: Python Plugin Framework: UDP/IP Discovery Added

Post by Boredcat »

This could be this issue :

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

Look at option 2. Sharing.
RFXCom(E) - Yeelight Lights - KaKu / Alexa HA Bridge
Windows 2012 / Windows 2012R2 / Xpenology/ Pi 3 / Milight / Home build ESP8266 / Sonoff
Veda
Posts: 2
Joined: Monday 12 November 2018 23:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin Framework: UDP/IP Discovery Added

Post 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?
Veda
Posts: 2
Joined: Monday 12 November 2018 23:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin Framework: UDP/IP Discovery Added

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest