PDA

View Full Version : component manager


mhwlng
December 10th, 2006, 07:32 AM
I've been playing with the new component manager, but don't quite get it yet :)

here are some assorted comments and questions :

I see this error in girder :
14:26:47:171 12/10/2006 Girder Core Could not aquire mutex for Device Table


Only if NR is already running when starting G5 then I see these :
14:43:46:910 12/10/2006 NetRemote Command SETVAR failed err: Connection Closed
console errors :
Error "Connection Closed"sending image/jpg to SERVER\CustomWeather\Local.CurrentConditions\Satel liteMap
Error "Connection Closed"sending image/jpg to SERVER\CustomWeather\Jacksonville.CurrentCondition s\SatelliteMap
Error "Connection Closed"sending image/jpg to SERVER\CustomWeather\Sydney.CurrentConditions\Sate lliteMap
Error "Connection Closed"sending image/jpg to SERVER\CustomWeather\Caracas.CurrentConditions\Sat elliteMap

In component manager :

rss feeds :
these two feeds don't work :
http://arstechnica.com/etc/rdf/ars.rdf
http://www.betanews.com/rss2

A function to transform the feed xml file via an xsl stylesheet to pretty html (or whatever) would be useful (see my rss class)

mediabridge:
please remove
--print (var,value)
it floods the console with messages

p.s. I see it's based on code from my mediabridge.lua class...
A mention of that in the code, would be nice :p

In general, I'm a bit confused about the proper use of components :
what is the proper way to read the current value of the collected data from lua ?
* custom weather
* mediabridge
* rss
* sun clock
* etc.
and also how do I let girder execute some of my lua code when new data has arrived (i.e. how does the event mechanism work)?

I can see a generic action which shows me all my variables and the current value...
but other than showing me the current value when double clicking it, what else can I do with this action ?

wmi :
how do you add stuff to the wmi component ?
it seems to have only cpu utilization ?

Once I figured out how to use your components, I hope that I can get rid of my :
* mediabridge.lua
* rss.lua
* worldmap.lua

Other modules in my setup that need to be replaced by components in the future:
* worldtime (including proper timezone handling) (see my worldtime.lua)
* discovered bluetooth devices (see my bluetooth.lua)
* SNMP data (see my adsl.lua)
* one-wire data (see my onewiretemp.lua and Dan's work)
* speedfan data (see my speedfan.lua)
* traffic data (see my traffic.lua [dutch only])
* xmltv based tv guide (see my xmltv.lua)

Are you already planning some of above functionality ? in that case, I'll wait developing those bits..

Marcel

Promixis
December 10th, 2006, 08:26 PM
Hi Marcel,

credit given where it is due (sorry)

please see my post re the CM.

have a look at componentmanager.lua and the directory. its fairly straight forward.

the next refresh of G5 will have a component class meant to handle multiple instances of a class. there are support DUI classes that will make adding a UI fast. the MB component has been converted to use this.

mhwlng
December 11th, 2006, 01:32 AM
Hello Mike,

your other post on the dm doesn't answer my questions I'm afraid...

*could you comment on the errors I'm seeing.

*could you answer above questions ?
-how to read a variable from lua
-how to set up your own event handler

*could you fix your rss class to handle the 2 problematic rss feeds (obviously, they work fine in my rss class :p )
and add an xsl transform function (you can take the one from my rss class if you want)

* other than displaying values while debugging, can you do something else with the generic action

* and tell me which of above missing components you are not planning, so I can start on those...

Promixis
December 11th, 2006, 07:42 AM
mutex error -> ignore

other errors -> i have asked Rob

to read a variable -> you have to get the component from the CM, and then read it from that component

Use one of these CM methods
-- retreieves a Component using its name
GetComponentUsingName = function (self,name)
return self.ComponentList:Get ({Name = name} )
end,


-- retreieves a Component using its id
GetComponentUsingID = function (self,id)
return self.ComponentList:Get ({ID = id} )
end,


You get events by calling the components Subscribe method with your own event handler


For the next while, I am not going to change the RSS class


* other than displaying values while debugging, can you do something else with the generic action

not sure what you mean



* worldtime (including proper timezone handling) (see my worldtime.lua)
* discovered bluetooth devices (see my bluetooth.lua)
* SNMP data (see my adsl.lua)
* one-wire data (see my onewiretemp.lua and Dan's work)
* speedfan data (see my speedfan.lua)
* traffic data (see my traffic.lua [dutch only])
* xmltv based tv guide (see my xmltv.lua)


none are on my short list in the next few weeks....


let me know what else you need.

mhwlng
December 11th, 2006, 07:51 AM
ok... so you're not making it easy for me...

can you make a simple complete working example how to get a variable and subscribe to an event ?




Quote:
* other than displaying values while debugging, can you do something else with the generic action

not sure what you mean




wel maybe I misunderstand how girder works....

I create an action by dragging from
device manager\generic

then select

device :eindhoven\forcecast tuesday
control : dewpoint
I see at the bottom of the edit screen :

current value : 5

now I hook this action up to an event.

I can't work out what happens when the event is fired...

the other device manager actions 'do' someting (e.g. switch a light on)

I can't work out what the generic action 'does' ?

Marcel

Promixis
December 11th, 2006, 08:13 AM
do you want to use a device or a component?

ie... components can create devices in the devicemanager

mhwlng
December 11th, 2006, 08:19 AM
both :-)

If I understand correctly :

* the sunclock is a component, so for the current image I need to get a variable from the component.

* in the mediabridge component you need to add a device for each MB instance (I have 2).
So to get the current playing track, I need to get a variable from the device.

or did I misunderstand (as usual)...

Marcel

Promixis
December 11th, 2006, 08:25 AM
ok -> now I get it :D

SunClock -> is a component. It also creates a device containing current images. So, the ideal way to use this component is via the device manager and not the component. the device manager publishes changes to this device which are updated in NR automatically. you can get notifications of the change directly using the device events in the logger. do you need to use this device in girder ie what are you trying to do.


MediaBridge -> is a component but does not currently export a device to the devicemanager. It will eventually, at least as a simple transport device.

mhwlng
December 11th, 2006, 08:43 AM
is a component but does not currently export a device to the devicemanager


I don't get it.
I defined 2 mediabridge instances in this component.
so are there now two components or something ?



what I'm trying to accomplish is (i.e. already working in my current G4 setup) :
some examples :
sun clock :
the image is updated every 5 minutes (or whatever).
I want an event to be called by the component manager where I can read the image at a resolution I want, do some processing and send it to NR.

mb:
I want to read the current playing track/artist/album from two mediabridge instances and create some pretty html from this data (and later send it to NR).

custom weather:
I defined 6 locations+ home location
I want to read the current temperature and weather icon from these 6 locations and combine it with the local time for these locations, then create pretty html.

for the local weather, I want to create a lua array containing the week's forecast and send this to NR for further processing (i.e. display in a web page template)


rss feed:
I defined 10 rss feeds.
I select one via a menu in NR and then girder should send NR the latest data for the appropriate rss feed (in html format)

some rss feeds are always on screen (news ticker,traffic report) and are automatically updated from girder at regular intervals.


some of above I would like to do via an event that your device generates when new data is available.

some is just based on a timer where I would read the actual values every x minutes...


Marcel

Promixis
December 11th, 2006, 09:38 AM
I don't get it.
I defined 2 mediabridge instances in this component.
so are there now two components or something ?



The MediaBridge in this case acts as a container for the instances. This code has changed slightly and will be in the next G5 refresh. Do not use it right now.




sun clock :
the image is updated every 5 minutes (or whatever).
I want an event to be called by the component manager where I can read the image at a resolution I want, do some processing and send it to NR.


I will create some code for you to do this...



mb:
I want to read the current playing track/artist/album from two mediabridge instances and create some pretty html from this data (and later send it to NR).



put this on hold for now



custom weather:
I defined 6 locations+ home location
I want to read the current temperature and weather icon from these 6 locations and combine it with the local time for these locations, then create pretty html.

for the local weather, I want to create a lua array containing the week's forecast and send this to NR for further processing (i.e. display in a web page template)



You can catch these events either via the DM or the CM.

The easiest would be to trigger a Node when the Device updates -> do you see the events in the logger?

OR you could subscribe to the CM and monitor changes there. Depends on how tightly you want to tie your code in the DM/CM.



rss feed:
I defined 10 rss feeds.
I select one via a menu in NR and then girder should send NR the latest data for the appropriate rss feed (in html format)

some rss feeds are always on screen (news ticker,traffic report) and are automatically updated from girder at regular intervals.


some of above I would like to do via an event that your device generates when new data is available.

some is just based on a timer where I would read the actual values every x minutes...


RSS devices automatically generate events and the devices are updated in NR automatically.


Given the things you want to do, I am guessing you may want to just handle events directly via the CM.

mhwlng
December 11th, 2006, 09:55 AM
RSS devices automatically generate events and the devices are updated in NR automatically.


I don't want any component manager stuff sent to NR automatically.

is there any way to switch this behaviour off ?

I noticed that since I added all these bits to the component manager NR now takes about 5 seconds to connect to girder (on a fast pc, don't know about ppc).

Marcel

Promixis
December 11th, 2006, 10:07 AM
the next iteration of G5 allows you to exclude devices from the devicemanager.

Promixis
December 26th, 2006, 05:03 PM
local sunclock = ComponentManager:GetComponentUsingName ('Sun Clock')
assert (sunclock,'SunClock component not enabled')

local function SunClockUpdateHandler (event,...)
print ('Sun Clock event:',event,' Params: ',unpack (arg))

if event == sunclock.Events.Update then -- we have an image update

print ('Sun Clock image updated with resolution ',arg [1], 'pixels wide')

-- to do some processing...

local imagestr = sunclock:GetImageString (arg [1])

local imagefilename = sunclock:GetImageFilename (arg [1])

end

end

sunclock:Subscribe (SunClockUpdateHandler)


how to use the sunclock component....

Promixis
December 26th, 2006, 07:30 PM
and for custom weather use



local CustomWeather = ComponentManager:GetComponentUsingName ('Custom Weather')
assert (CustomWeather,'CustomWeather component not enabled')

local function CustomWeatherUpdateHandler (event,...)
print ('CustomWeather event:',event,' Params: ',unpack (arg))

if event == CustomWeather.Events.Update then -- we have an image update

cwinstance = arg [2]
updatetype = arg [3]

end

end

CustomWeather:Subscribe (CustomWeatherUpdateHandler)

mhwlng
December 27th, 2006, 01:27 AM
Thanks, Mike

this is really helpful

but, what about reading variables directly, without an event ?

for example, if I have a timer running every 10 minutes and I want to
* read the current pressure for a certain location (I have several)
* or the current sunclock map.

Promixis
December 27th, 2006, 08:02 AM
weatherlocal = CustomWeather:GetInstance ({Name = 'name I gave the location'})




then open the CustomWeather class in luascript\classes - there are methods there to get the data as needed. Be sure to use the Get methods and not read data directly.