UDP Listener Plugin

Posted on
Wed May 02, 2018 8:36 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: UDP Listener Plugin

howartp wrote:
They can’t all listen at once as they all need to bind to the same port, so they have to bind then unbind when not actively searching.


Incorrect - as long as you set the socket options correctly any number of different processes can listen on the same port. I would caution developers to be extremely careful about creating a dependency between your plugin and another plugin, particularly to just get around this issue. Users are going to be very confused about having to deal with dependencies between plugins (it's already a big enough problem when a plugin requires a Python module).

Note - I'm not dissing this plugin, just that for this specific use case I think creating a dependency between plugins is going to cause lots of user confusion, particularly when it's a simple code fix.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed May 02, 2018 12:32 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: UDP Listener Plugin

howartp wrote:
My use case is on behalf of other users and other plugin devs.

Half a dozen plugins use UDP listening to locate devices - Rogue’s TV Plugins, my abandoned Sky+ plugin, SecuritySpy I believe.


In addition to what Jay already wrote, it's not clear to me that this problem actually exists. I looked at the source for a couple of RP's plugins, and the SecuritySpy plugin, and none of them were trying to do discovery on the same ports. Maybe I wasn't looking at the right plugins. I couldn't find your Sky+ plugin to look at.

Did you actually run into this problem, or was this a theoretical issue. If you actually did run into it, please let me know the exact plugins that caused it and I'll look and see if changing the socket bindings per Jay's post would have fixed the issue. Because what you propose is, as Jay said, already doable at the socket level.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed May 02, 2018 12:34 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: UDP Listener Plugin

MartinG wrote:
I had a stream of errors yesterday with 0.0.1 Beta 2. Here's one:

Code: Select all
   UDP Listener Error              Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
  File "plugin.py", line 107, in runConcurrentThread
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 8: ordinal not in range(128)

   UDP Listener Error              plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)



Fixed in 0.0.4

MartinG wrote:
And today, running 0.0.4:


Code: Select all
Starting plugin "UDP Listener 0.0.4" (pid 99716)
   UDP Listener Debug              logLevel = 5
   Started plugin "UDP Listener 0.0.4"
   UDP Listener                    Starting UDP Listener
   UDP Listener Debug              BETA RakoListener: Device Current Version = 0
   UDP Listener Debug              BETA RakoListener: Device Version is up to date
   UDP Listener Debug              BETA RakoListener: Starting device (udpListener)
   UDP Listener Error              exception in deviceStartComm(BETA RakoListener): 'key multiGroup not found in dict'


You just need to update the device to include the new config key. Edit the device, open the details panel, then save it all.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed May 02, 2018 7:00 pm
mclass offline
Posts: 312
Joined: May 13, 2015
Location: Melbourne, Australia

Re: UDP Listener Plugin

Thanks Joe - the new version now works a treat!

However, when I use the received message to trigger a status request, I get an "address in use error" from my script suggesting the UDP Listening device ties up the port. When I get time I will attempt a brief delay between receiving the UDP message and making the status request, but was wondering if your plug in adopts Jay's recommendations in a previous post to this thread regarding port sharing/reuse.

Again, many thanks for pursuing this plugin when you don't have a use case!!

mclass

Posted on
Wed May 02, 2018 7:03 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: UDP Listener Plugin

Yes, the plugin sets the SO_REUSEPORT flag.

Post your code (in a zip file attachment is fine) and I'll take a look at it.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu May 03, 2018 12:02 am
agame offline
Posts: 514
Joined: Jul 13, 2017
Location: Melbourne, Australia

Re: UDP Listener Plugin

just confirming that I've been running [beta2] for several days now without an error message.
Amazingly useful, thank you again!! :D

Posted on
Thu May 03, 2018 2:14 am
MartinG offline
Posts: 116
Joined: Aug 19, 2016

Re: UDP Listener Plugin

Updating the device solved the errors - thanks. The plugin has been reporting state changes without error for the last 12h or so.

For example:

Code: Select all
3 May 2018, 09:03:22
   UDP Listener Debug              BETA RakoListener: UDP msg from: ('192.168.1.xxx', 2861), data: 53:07:00:21:00:31:00:00:ae
   UDP Listener Debug              Checking Trigger RakoListener (1439662918), Type: messageReceived
   Trigger                         RakoListener


Which means Set Scene 0 (all off) in room 0x21

Lovely - thanks.

Posted on
Thu May 03, 2018 5:59 am
mclass offline
Posts: 312
Joined: May 13, 2015
Location: Melbourne, Australia

Re: UDP Listener Plugin

Thanks for the offer Joe, but I think I’m sorted!

I inserted a one second delay between the trigger (from the UDP message) and requesting the status from the Daikin AC and all’s fine.

I suspect the issue is with the Daikin SkyFi module that is always very SLOOOW. No wonder that Daikin has withdrawn it from sale, and has yet to replace t with something more “Daikin-worthy” (you may gather that I am less than impressed!).

I have been searching for Daikin’s proprietary protocol that is used between its wall controller and indoor unit so that I can access the AC directly, rather than via their WiFly based module. However, it seems that it’s a more closely guarded secret than “the Colonel’s secret herbs & spices”.

Thanks again for your efforts in putting this plug in together!

mclass


Sent from my iPad using Tapatalk

Posted on
Thu May 03, 2018 8:37 am
MartinG offline
Posts: 116
Joined: Aug 19, 2016

Re: UDP Listener Plugin

A quick update on working with the plugin.

I tried running the plugin and my old Listener code in parallel so I can compare the outputs, and found that the two didn't play nicely together.

I first modified my code to match Jay's post on port sharing, but it still didn't work.

Looking at the plugin code, and found a small difference:

Jay's example:
Code: Select all
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)

UDP Listener plugin:
Code: Select all
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

I edited the plugin code to match Jay's, reloaded the plugin and bingo. Both listeners are running in parallel without interference.

The Unix man pages for these options say this:

SO_REUSEADDR enables local address reuse
SO_REUSEPORT enables duplicate address and port bindings

Which I take to mean that only SO_REUSEPORT explicitly enables port (vs address) reuse; that seems to match the behaviours I'm seeing.

Posted on
Thu May 03, 2018 2:16 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: UDP Listener Plugin

MartinG wrote:
The Unix man pages for these options say this:

SO_REUSEADDR enables local address reuse
SO_REUSEPORT enables duplicate address and port bindings

Which I take to mean that only SO_REUSEPORT explicitly enables port (vs address) reuse; that seems to match the behaviours I'm seeing.


Exactly.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu May 03, 2018 2:40 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: UDP Listener Plugin

My bad. Out of town for a few days, so it’ll probably be Monday before I can post a fix.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu May 03, 2018 11:58 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: UDP Listener Plugin

In response to my use case and Jay and FD’s replies, this is my feature request from 3.5 years ago:

viewtopic.php?f=108&t=12550

I’m sure there’s also another thread, possibly within an old beta forum, where I was told it was a non-issue because Plugins shouldn’t hold the ports open when not actively using so my idea/request was a load of rubbish.

No suggestions back then to use socket sharing, and certainly one of my least favourite threads.


Sent from my iPhone using Tapatalk Pro

Posted on
Fri May 04, 2018 8:56 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: UDP Listener Plugin

So, here's the deal: everyone (not just Indigo and plugin developers) has to be a "good citizen" when it comes to listening on shared ports (like 1900 which is UPnP). This means not only plugins, but other apps as well. We could implement a listener at the server level and distribute the messages ourselves, but that's a lot of plumbing, particularly given that sharing a port is as simple as it is (when Matt replied back then we weren't aware of the reuseport option).

But, of course, it requires all applications that use port 1900 (or any other shared UDP port) to be good citizens - not just Indigo plugins. So, from that perspective, having the server open the port would still potentially have the conflicts with other apps (Sonos, etc) - the problem would just be moved from the plugin to the server. We can encourage plugin developers to do the right thing in their code - again the solution is simple - and we think that's the right approach for Indigo plugins. But implementing server-based UDP port listening infrastructure won't solve the problem of other apps not being good citizens.

The suggestion to unbind when not needed was my stopgap idea, again before we knew about the reuseport option. Once that option was identified, that measure was no longer really needed.

This plugin is a great solution for those that aren't writing plugins - it allows them to use devices to receive UPnP messages without writing any code. It also allows scripters to use the data without having to understand how to do socket communication.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue May 08, 2018 11:44 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: UDP Listener Plugin

Version 0.0.5 with fixed reuse flag is available: https://github.com/FlyingDiver/Indigo-U ... r/releases

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Oct 15, 2018 7:38 pm
agame offline
Posts: 514
Joined: Jul 13, 2017
Location: Melbourne, Australia

Re: UDP Listener Plugin

I have noticed that after a period of a day or so I stop detecting UDP multicast events (from a Global Cache Flex device that monitors - amongst other things - open/close status of a farm gate. But a restart of the UDP listener plugin - and no other action - fixes this and the plugin works perfectly again.

I'm using version 0.0.5; and there's nothing unusual looking in the (verbose logging) logs I can see. I don't recall seeing this before Indigo 7.2 but can't be 100%certain. Also that Indigo system is on Mojave...

The UDP Listener 'device' doesn't display status of any kind...is there something I could be checking?

I guess I could configure a periodic restart of the plugin...

Who is online

Users browsing this forum: No registered users and 2 guests