Subscribing to an object in a script

Posted on
Mon May 21, 2018 10:55 am
berkinet offline
User avatar
Posts: 3359
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Subscribing to an object in a script

Ok... I should know the answer to this. But, I don't :oops:

I would like two track changes in a device state looking for a pattern (this is for my mailbox monitor. Actually, what I want to track is the state lastUpdate as I am looking to determine the frequency of events. Ideally I would like to see the time in milliseconds. but, seconds might work. Once I have the input I want to maintain a moving average of the time delay between updates. as the moving average approaches 0 (or goes negative, if I can get millisecond times) I know an event has occurred.

I know I can write all changes to the log and then tail there log to get the data I want. But, that is messy and is a misuse of the log. I could also build a plugin, but it seems like overkill. So, my question is can this be done in a script, that I would launch with trigger at start up. Perhaps the question is simply "can I run subscribeToChanges() in a script?" But, asking it that directly precludes other options.

Thanks for any ideas

Posted on
Mon May 21, 2018 12:24 pm
FlyingDiver offline
Posts: 3444
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Subscribing to an object in a script

You can just trigger on any changes to the device state, I would think. Then the script runs on any change.

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

Posted on
Mon May 21, 2018 1:24 pm
jay (support) offline
Site Admin
User avatar
Posts: 15683
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Subscribing to an object in a script

berkinet wrote:
Perhaps the question is simply "can I run subscribeToChanges() in a script?" But, asking it that directly precludes other options.


The answer to this specific question is no: that method is a plugin-specific command because scripts don't/can't define a Plugin object.

I think FlyingDiver has the right idea though...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon May 21, 2018 1:32 pm
berkinet offline
User avatar
Posts: 3359
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Subscribing to an object in a script

FlyingDiver wrote:
You can just trigger on any changes to the device state, I would think. Then the script runs on any change.

The frequency of events is around 15 per second, for up to 10 seconds, when the mailbox is opened. So, I am concerned about calling a script at that rate. Also, I need to calculate a moving average of the delay between events so I need a way to store those events and then calculate the average. I could use variables. But, reading and writing 10 events 15 times per second just doesn't seem like a good idea. In a script, I could simply hold the most recent 10 events in an array and run it like a FIFO buffer.

OTOH, these event storm only happen two to maybe four times a day. And, I can reduce the frequency of events a bit by increasing the delta that must occur to fire an event. That might get it down to 6 or 8 per second.

Maybe a plugin is the way to go.

Posted on
Mon May 21, 2018 2:30 pm
jay (support) offline
Site Admin
User avatar
Posts: 15683
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Subscribing to an object in a script

I'd crank those way down - 10-15 a second seems like a lot of overkill...

And, yeah, a plugin is the only practical way to handle that volume (and if that were sustained it might also cause issues).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue May 22, 2018 1:17 am
berkinet offline
User avatar
Posts: 3359
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Subscribing to an object in a script

jay (support) wrote:
I'd crank those way down - 10-15 a second seems like a lot of overkill....

And, that is the problem. To crank down the frequency I have to increase the reporting delta -- the change in light level required to generate an event. Set it too high and I miss events, too low and too much data.

jay (support) wrote:
...And, yeah, a plugin is the only practical way to handle that volume (and if that were sustained it might also cause issues).

I will probably either create a very basic plugin for this or add the functionality to (the already overly-complex) Phidgets plugin.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest