How to get vars from an subroutine running as Process_Item

View: New views
10 Messages — Rating Filter:   Alert me  

How to get vars from an subroutine running as Process_Item

by Thorsten Weiss :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello everybody,

I added a Process_Item which uses a subroutine to get my 1-Wire values from owserver.

(When i do it in the mainloop it pauses MH for 20 seconds...)

But now i have the problem that my vars i'm using in the Sub would not actualized...

So i can't get my measueres out of the sub.

My Vars are declared with use_Vars or as Weather item.

Ist ist possible to get my readings out of the sub??

Please help.


regards, Thorsten



$owserver_process = new Process_Item;
set $owserver_process "&AbfrageOwserver";
set_timeout $owserver_process 60;

my $testvar;

sub AbfrageOwserver {
    print_log "Prozess AbfrageOwserver gestartet \n";
    #-----------------------Abfrage der Temperaturfühler------------------------------------------------
    $Weather{Fortluft} = sprintf ("%0.1f", ($owserver->read('/bus.0/10.F2FAE4000800/temperature')));
    $Weather{Warmwasser} = sprintf ("%0.1f", ($owserver->read('/bus.0/10.4B0AE5000800/temperature')));#new Owfs_Item ( "10.4B0AE5000800", "Warmwasser");
    $Weather{Aussenluft} = sprintf ("%0.1f", ($owserver->read('/bus.0/10.A81EE5000800/temperature')));#new Owfs_Item ( "10.A81EE5000800", "Aussenluft");
    $Weather{Abluft} = sprintf ("%0.1f", ($owserver->read('/bus.0/10.16FDE4000800/temperature')));#new Owfs_Item ( "10.16FDE4000800", "Abluft");
    $Weather{Zuluft} = sprintf ("%0.1f", ($owserver->read('/bus.0/10.AEFCE4000800/temperature')));#new Owfs_Item ( "10.AEFCE4000800", "Zuluft");
    $PoolTemp = sprintf ("%0.1f", ($owserver->read('/bus.0/28.69BBDF000000/temperature')));#new Owfs_Item ( "28.69BBDF000000", "Pooltemp");
    $Wonz_Temp  = sprintf ("%0.1f", ($owserver->read('/bus.0/28.5AC1DF000000/temperature')));#new Owfs_Item ( "28.5AC1DF000000", "Wohnzimmer");
    $fbh_kueche = sprintf ("%0.1f", ($owserver->read('/bus.0/28.6602AC010000/temperature')));#new Owfs_Item ( "28.6602AC010000", "RL Kueche");
    $fbh_flur = sprintf ("%0.1f", ($owserver->read('/bus.0/28.310CAE010000/temperature')));#new Owfs_Item ( "28.310CAE010000", "RL Flur");
    $fbh_wohnz2 = sprintf ("%0.1f", ($owserver->read('/bus.0/28.E912AE010000/temperature')));#new Owfs_Item ( "28.E912AE010000", "Wohnzimmer Kreis 2");
    $fbh_wohnz1 = sprintf ("%0.1f", ($owserver->read('/bus.0/28.A370AC010000/temperature')));#new Owfs_Item ( "28.A370AC010000", "Wohnzimmer Kreis 1");
   
    #------------------------Abfrage und Berechnung des Zisternenfüllstands------------------------------
    $Weather{TemperaturAD} = $owserver->read('/bus.0/26.C2A164000000/temperature');
    $fuell = $owserver->read('/bus.0/26.C2A164000000/VAD');
    $Weather{SpannungUb} = $owserver->read('/bus.0/26.C2A164000000/VDD');

    $dT = $Weather{TemperaturAD} - 20; #deltaT berechenen Refernztemp = 20�C
    $dP = $dT * 1.0; #deltaT x Faktor cm/K 0.6cm/K
    $fuell = sprintf ("%0.1f", (($fuell - 0.65)/0.006) - $dP );
    $liter = sprintf ("%0000u", ($fuell * 0.866 * 26.1));
        if ($liter > 3500){
            $liter = 3500;
            }    
        elsif ($liter < 0){
            $liter = 0;
            }
       
    $Weather{SpannungAD} = $fuell;
    $Weather{Liter} = $liter;
    $testvar = $liter;
    print_log"Füllstand Zisterne $Weather{Liter}\n";
    my $ret_var = "$Weather{Fortluft}, $Weather{Warmwasser}";
    return $ret_var;
    }
   

#------------------Start der OWserver-Abfrage--------------------------
my $rueckgabe;
if ($New_Minute){
    start $owserver_process;
}


if (done_now $owserver_process) {
    if (timed_out $owserver_process) {
        print_log 'AbfrageOwserver timed out';
    }
    else {
        print_log "AbfrageOwserver beendet";
        print_log "Messwerte: $rueckgabe, $Weather{Fortluft}, $Weather{Aussenluft}, $Weather{Abluft}, $Weather{Zuluft}, $Weather{Liter} \n ";
    }
}

Re: How to get vars from an subroutine running as Process_Item

by Jim Duda :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/02/2009 12:47 PM, Thorsten Weiss wrote:
>
> Hello everybody,
>
> I added a Process_Item which uses a subroutine to get my 1-Wire values from
> owserver.
>
> (When i do it in the mainloop it pauses MH for 20 seconds...)

I'm not surprised you are getting 20 second delays.

Each of the temperature conversions takes about 750 mS.
So, doing all the temperature readings at once is going to be a problem.
I suggest you build a loop which does them one at a time.  I found that
it was best to read each thermometer once every 5 seconds.  For temperature,
you don't need it to be fast.

I had to do a similar thing in mh/lib/Owfs_Thermostat.

>
> But now i have the problem that my vars i'm using in the Sub would not
> actualized...
>
> So i can't get my measueres out of the sub.

You should use Generic_Item variables.  The work much like Global Variables.
Look in the mh/doc/mh.txt a description of the Generic_Item method(s).

Jim



------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365


Re: How to get vars from an subroutine running as Process_Item

by David Norwood-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thorsten,

I think you added a process item so misterhouse wouldn't pause, right?  Are
you running Windows?  There is a known problem using the &subroutine option
with process item on windows.  One of the things on my todo list is to
investigate using threads instead of fork in process item.

Would you post your subroutine and process item creation code?

As far as getting your vars out of your process item subroutine, you
currently have to write them to a file and then read them back in from the
main misterhouse process.  You can use process item to capture stdout and
stderr to files, also.  One advantage to using threads is you get the return
value from the threaded subroutine.

David


----- Original Message -----
From: "Jim Duda" <jim@...>
To: <misterhouse-users@...>
Sent: Saturday, October 03, 2009 5:56 AM
Subject: Re: [mh] How to get vars from an subroutine running as Process_Item


> On 10/02/2009 12:47 PM, Thorsten Weiss wrote:
>>
>> Hello everybody,
>>
>> I added a Process_Item which uses a subroutine to get my 1-Wire values
>> from
>> owserver.
>>
>> (When i do it in the mainloop it pauses MH for 20 seconds...)
>
> I'm not surprised you are getting 20 second delays.
>
> Each of the temperature conversions takes about 750 mS.
> So, doing all the temperature readings at once is going to be a problem.
> I suggest you build a loop which does them one at a time.  I found that
> it was best to read each thermometer once every 5 seconds.  For
> temperature,
> you don't need it to be fast.
>
> I had to do a similar thing in mh/lib/Owfs_Thermostat.
>
>>
>> But now i have the problem that my vars i'm using in the Sub would not
>> actualized...
>>
>> So i can't get my measueres out of the sub.
>
> You should use Generic_Item variables.  The work much like Global
> Variables.
> Look in the mh/doc/mh.txt a description of the Generic_Item method(s).
>
> Jim
>
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry® Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9-12, 2009. Register
> now!
> http://p.sf.net/sfu/devconf
> ________________________________________________________
> To unsubscribe from this list, go to:
> http://sourceforge.net/mail/?group_id=1365
>



------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365


Re: How to get vars from an subroutine running as Process_Item

by Thorsten Weiss :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the hint...

I'm using linux so the sub runs properly...

I thought that i have acess to the variables i use in the sub from the main.loop...


As a workaround now i declare my process_Item as follows:

my $AbfrageOwserver_output = '/home/mh/data/owserver/owserver_readings.log';
$owserver_process = new Process_Item;
set $owserver_process "&AbfrageOwserver";
set_output $owserver_process $AbfrageOwserver_output;
set_timeout $owserver_process 60;

sub AbfrageOwserver {
    my $temp_fortluft = sprintf ("%0.1f", ($owserver->read('/bus.0/10.F2FAE4000800/temperature')));
    my $temp_warmwasser= sprintf ("%0.1f", ($owserver->read('/bus.0/10.4B0AE5000800/temperature')));
    my $temp_aussenluft = sprintf ("%0.1f", ($owserver->read('/bus.0/10.A81EE5000800/temperature')));
    my $temp_abluft = sprintf ("%0.1f", ($owserver->read('/bus.0/10.16FDE4000800/temperature')));
    my $temp_zuluft = sprintf ("%0.1f", ($owserver->read('/bus.0/10.AEFCE4000800/temperature')));
    my $temp_pool = sprintf ("%0.1f", ($owserver->read('/bus.0/28.69BBDF000000/temperature')));
    my $temp_wohnzimmer  = sprintf ("%0.1f", ($owserver->read('/bus.0/28.5AC1DF000000/temperature')));
    my $temp_fbh_kueche = sprintf ("%0.1f", ($owserver->read('/bus.0/28.6602AC010000/temperature')));
    my $_temp_fbh_flur = sprintf ("%0.1f", ($owserver->read('/bus.0/28.310CAE010000/temperature')));
    my $temp_fbh_wohnz2 = sprintf ("%0.1f", ($owserver->read('/bus.0/28.E912AE010000/temperature')));
    my $temp_fbh_wohnz1 = sprintf ("%0.1f", ($owserver->read('/bus.0/28.A370AC010000/temperature')));
    print "$Time_Now,$temp_fortluft,$temp_warmwasser,$temp_aussenluft,$temp_abluft,$temp_zuluft,$temp_pool,$temp_wohnzimmer,$temp_fbh_kueche,$_temp_fbh_flur,$temp_fbh_wohnz2,$temp_fbh_wohnz1\n";
    return ($temp_fortluft, $temp_warmwasser);
    }

if ($New_Minute){    
    start $owserver_process;
}




in the file /data/owserver_readings.log
is this data stored:

12:42 ,19.2,49.7,15.9,22.7,21.5,24.3,23.9,22.7,22.9,23.1,23.3
Process Eval results:

but why is there only the data from the print command and not the data from the return ($temp_fortluft, $temp_warmwasser) of the subroutine?


The only thing i have to do is to read the file /data/owserver_readings.log and put the data in my global vars...

Re: How to get vars from an subroutine running as Process_Item

by Michael Stovenour :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I had a very similar design problem when I rewrote internet_earthquakes.pl.
It turns out that you are running in a completely separate perl process so
you can not modify the memory space (variables) in the perl process where
the MH loop is running.  This is the same for both windows and perl.  I used
the technique described by David.  I choose to write the info to a dbm file
because it was many rows of data that I wanted to later filter.  For an
example you can look in the SVN repository for
code/common/internet_earthquakes.pl, bin/get_earthquakes, and
bin/get_earthqakes.bat.  (the bat is required by windows users and the perl
file in bin must not have an extension)

Michael

-----Original Message-----
From: Thorsten Weiss [mailto:thoweiss@...]
Sent: Sunday, October 04, 2009 5:48 AM
To: misterhouse-users@...
Subject: Re: [mh] How to get vars from an subroutine running as Process_Item


Thanks for the hint...

I'm using linux so the sub runs properly...

I thought that i have acess to the variables i use in the sub from the
main.loop...


As a workaround now i declare my process_Item as follows:

my $AbfrageOwserver_output = '/home/mh/data/owserver/owserver_readings.log';
$owserver_process = new Process_Item;
set $owserver_process "&AbfrageOwserver";
set_output $owserver_process $AbfrageOwserver_output;
set_timeout $owserver_process 60;

sub AbfrageOwserver {
    my $temp_fortluft = sprintf ("%0.1f",
($owserver->read('/bus.0/10.F2FAE4000800/temperature')));
    my $temp_warmwasser= sprintf ("%0.1f",
($owserver->read('/bus.0/10.4B0AE5000800/temperature')));
    my $temp_aussenluft = sprintf ("%0.1f",
($owserver->read('/bus.0/10.A81EE5000800/temperature')));
    my $temp_abluft = sprintf ("%0.1f",
($owserver->read('/bus.0/10.16FDE4000800/temperature')));
    my $temp_zuluft = sprintf ("%0.1f",
($owserver->read('/bus.0/10.AEFCE4000800/temperature')));
    my $temp_pool = sprintf ("%0.1f",
($owserver->read('/bus.0/28.69BBDF000000/temperature')));
    my $temp_wohnzimmer  = sprintf ("%0.1f",
($owserver->read('/bus.0/28.5AC1DF000000/temperature')));
    my $temp_fbh_kueche = sprintf ("%0.1f",
($owserver->read('/bus.0/28.6602AC010000/temperature')));
    my $_temp_fbh_flur = sprintf ("%0.1f",
($owserver->read('/bus.0/28.310CAE010000/temperature')));
    my $temp_fbh_wohnz2 = sprintf ("%0.1f",
($owserver->read('/bus.0/28.E912AE010000/temperature')));
    my $temp_fbh_wohnz1 = sprintf ("%0.1f",
($owserver->read('/bus.0/28.A370AC010000/temperature')));
    print
"$Time_Now,$temp_fortluft,$temp_warmwasser,$temp_aussenluft,$temp_abluft,$te
mp_zuluft,$temp_pool,$temp_wohnzimmer,$temp_fbh_kueche,$_temp_fbh_flur,$temp
_fbh_wohnz2,$temp_fbh_wohnz1\n";
    return ($temp_fortluft, $temp_warmwasser);
    }

if ($New_Minute){    
    start $owserver_process;
}




in the file /data/owserver_readings.log
is this data stored:

12:42 ,19.2,49.7,15.9,22.7,21.5,24.3,23.9,22.7,22.9,23.1,23.3
Process Eval results:

but why is there only the data from the print command and not the data from
the return ($temp_fortluft, $temp_warmwasser) of the subroutine?


The only thing i have to do is to read the file /data/owserver_readings.log
and put the data in my global vars...

--
View this message in context:
http://www.nabble.com/How-to-get-vars-from-an-subroutine-running-as-Process_
Item-tp25716738p25736860.html
Sent from the Misterhouse - User mailing list archive at Nabble.com.


----------------------------------------------------------------------------
--
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
________________________________________________________
To unsubscribe from this list, go to:
http://sourceforge.net/mail/?group_id=1365


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365


Re: How to get vars from an subroutine running as Process_Item

by Thorsten Weiss :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think the only way to acess the data is to write it into an external file, and then read the file from the mainloop.

I will try it it with xml-simple.

i crate an xml-file with the measures, and then i can process the xml in MH with xml::simple.


When i wrote the code i will post it here.



Regards,

Thorsten

Re: How to get vars from an subroutine running as Process_Item

by Michael Stovenour :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

One other potential option is to have the separate process send an xAP
message.  The xAP message can then be picked up by the MH main loop.  I
wanted to try this with another project, but I really do not understand how
to extend the xAP schema support in MH.  Oh, how I wish for a little
developer documentation....  ;^)

-----Original Message-----
From: Thorsten Weiss [mailto:thoweiss@...]
Sent: Thursday, October 08, 2009 2:49 AM
To: misterhouse-users@...
Subject: Re: [mh] How to get vars from an subroutine running as Process_Item


I think the only way to acess the data is to write it into an external file,
and then read the file from the mainloop.

I will try it it with xml-simple.

i crate an xml-file with the measures, and then i can process the xml in MH
with xml::simple.


When i wrote the code i will post it here.



Regards,

Thorsten

--
View this message in context:
http://www.nabble.com/How-to-get-vars-from-an-subroutine-running-as-Process_
Item-tp25716738p25799758.html
Sent from the Misterhouse - User mailing list archive at Nabble.com.


----------------------------------------------------------------------------
--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
________________________________________________________
To unsubscribe from this list, go to:
http://sourceforge.net/mail/?group_id=1365


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365


Re: How to get vars from an subroutine running as Process_Item

by Jim Duda :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 10/08/2009 11:21 PM, Michael Stovenour wrote:
> One other potential option is to have the separate process send an xAP
> message.  The xAP message can then be picked up by the MH main loop.  I
> wanted to try this with another project, but I really do not understand how
> to extend the xAP schema support in MH.  Oh, how I wish for a little
> developer documentation....  ;^)
>

xAP is straight forward.  Here is a snipet of code I use in a code
module to send and receive LIRC messages across the network.  You
should be able to tweak it for your needs.

You want to replace "xap-lirc" to something else.  You also need
to load the various hash elements for whatever you need.

I use the xapalyzer application to snoop the network.  You can
find xapalyzer on the internet somewhere.

# Send lirc to network
sub xAP_send_lirc {
     my ($code,$action,$key,$remote) = @_;
     my $interface = "lirc";
     print_log "xAP_LIRC:: send interface: $interface code: $code
action: $action key: $key remote: $remote" if $main::Debug{xap_echo};
     my $lirc_block;
     $lirc_block->{'interface'} = $interface;
     $lirc_block->{'code'} = $code;
     $lirc_block->{'action'} = $action;
     $lirc_block->{'key'} = $key;
     $lirc_block->{'remote'} = $remote;
     print_log "xAP_LIRC:: send interface: $interface code: $code
action: $action key: $key remote: $remote" if $main::Debug{xap_echo};
     &xAP::send('xAP', 'xap-lirc.data', 'xap-lirc.data' => $lirc_block);
}

# Receive lirc from network
$_xap_lirc_obj = new xAP_Item('xap-lirc.data');
if ($_xap_lirc_obj->state_now) {
    # dump some debugging information
#   foreach my $key (keys %{$_xap_lirc_obj->{'xap-header'}}) {
#     print_log ("xAP_lirc:: receive key: $key data:
$_xap_lirc_obj->{'xap-header'}{$key}") if $main::Debug{xap_echo};
#   }
#   foreach my $key (keys %{$_xap_lirc_obj->{'xap-lirc.data'}}) {
#     print_log ("xAP_lirc:: receive key: $key data:
$_xap_lirc_obj->{'xap-lirc.data'}{$key}") if $main::Debug{xap_echo};
#   }
    # validate the XAP packet
    my $classname = $_xap_lirc_obj->{'xap-header'}{class};
    return unless ($classname eq 'xap-lirc.data');
    my $interface = $_xap_lirc_obj->{'xap-lirc.data'}{interface};
    return unless (lc $interface eq 'lirc');
    my $code = $_xap_lirc_obj->{'xap-lirc.data'}{code};
    my $action = $_xap_lirc_obj->{'xap-lirc.data'}{action};
    my $key = $_xap_lirc_obj->{'xap-lirc.data'}{key};
    my $remote = $_xap_lirc_obj->{'xap-lirc.data'}{remote};
    print_log "xAP_LIRC:: receive interface: $interface code: $code
action: $action key: $key remote: $remote" if $main::Debug{xap_echo};
    &lirc_process($code,$action,$key,$remote);
}

Jim

> -----Original Message-----
> From: Thorsten Weiss [mailto:thoweiss@...]
> Sent: Thursday, October 08, 2009 2:49 AM
> To: misterhouse-users@...
> Subject: Re: [mh] How to get vars from an subroutine running as Process_Item
>
>
> I think the only way to acess the data is to write it into an external file,
> and then read the file from the mainloop.
>
> I will try it it with xml-simple.
>
> i crate an xml-file with the measures, and then i can process the xml in MH
> with xml::simple.
>
>
> When i wrote the code i will post it here.
>
>
>
> Regards,
>
> Thorsten
>



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365


Re: How to get vars from an subroutine running as Process_Item

by Thorsten Weiss :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jim,

using XAP is an good idea...


Actually i'm using XML::Simple to store the data into a XML-File and in the mailoop i read back the data.


This code is for writing the XML (sorry about the comments in german):

#Erstellen der XML-Struktur
    my @arr = {Temperatur=>[
            {'sensor'=>'fortluft', 'reading'=> $temp_fortluft},
            {'sensor'=>'warmwasser', 'reading'=> $temp_warmwasser},
            {'sensor'=>'aussenluft', 'reading'=> $temp_aussenluft},
            {'sensor'=>'abluft', 'reading'=> $temp_abluft},
            {'sensor'=>'zuluft', 'reading'=> $temp_zuluft},
            {'sensor'=>'pool', 'reading'=> $temp_pool},
            {'sensor'=>'wohnzimmer', 'reading'=> $temp_wohnzimmer},
            {'sensor'=>'zisterne', 'reading'=> $temp_zisterne},          
            {'sensor'=>'liter', 'reading'=> $temp_fuell},
            {'sensor'=>'spannungUB', 'reading'=> $temp_spannungUb},
             ]};

    # Objekt erstellen
    my $xml = new XML::Simple (RootName => 'Messwerte', XMLDecl => '', OutputFile => '/home/mh/data/owserver/owserver_readings.xml');
           
    # Perl-Array-Referenz in XML-Dokument umwandeln
    my $data = $xml->XMLout(@arr);



and this is the code for reading the xml-file:

 # Starten und Auswerten des Prozesses
    # Objekt erstellen
    my $xml_in = new XML::Simple(KeyAttr =>"sensor");

if ($New_Minute){    
    start $owserver_process;
    # XML-Datei einlesen
    my $data = $xml_in->XMLin('/home/mh/data/owserver/owserver_readings.xml');
    # Ausgabe
    #print Dumper($data);
   
    #--------Zuweisung der XML-Inhalte zu den Variablen----------------------------------
    my $Ausgabe = $data->{Temperatur}{"liter"}{reading};
    $Weather{Fortluft} = $data->{Temperatur}{"fortluft"}{reading};
    $Weather{Warmwasser} = $data->{Temperatur}{"warmwasser"}{reading};
    $Weather{Aussenluft} = $data->{Temperatur}{"aussenluft"}{reading};
    $Weather{Abluft} = $data->{Temperatur}{"abluft"}{reading};
    $Weather{Zuluft} = $data->{Temperatur}{"zuluft"}{reading};
    $PoolTemp = $data->{Temperatur}{"pool"}{reading};
    $Wonz_Temp  = $data->{Temperatur}{"wohnzimmer"}{reading};
    $fbh_kueche = $data->{Temperatur}{"aussenluft"}{reading};
    $fbh_flur = $data->{Temperatur}{"aussenluft"}{reading};
    $fbh_wohnz2 = $data->{Temperatur}{"aussenluft"}{reading};
    $fbh_wohnz1 = $data->{Temperatur}{"aussenluft"}{reading};
    $Weather{Liter} = $data->{Temperatur}{"liter"}{reading};
    $Weather{TemperaturAD} = $data->{Temperatur}{"zisterne"}{reading};
    $Weather{SpannungUb} = $data->{Temperatur}{"spannungUB"}{reading};
   
    #print_log "Messwert:".$Ausgabe."Liter\n";
}



maybe i will port the code for using with XAp but i don't now much about the XAp protocol.

Regards,

Thorsten.
 

Re: How to get vars from an subroutine running as Process_Item

by Michael Stovenour :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That does seem quite simple.  For some reason I thought that xAP/xPL somehow
required a linkage to MH objects.  In my haste I misunderstood the purpose
of the code for object mirroring to other MH systems that I found in
Generic_Item.pm.  I thought that xAP/xPL support was somehow directly linked
to MH objects.  I see now that I can write code that links xAP/xPL messages
to an object (like the zone minder code), but basic xAP/xPL support involves
nothing more than sending and receiving messages.

-----Original Message-----
From: Jim Duda [mailto:jim@...]
Sent: Friday, October 09, 2009 6:57 PM
To: misterhouse-users@...
Subject: Re: [mh] How to get vars from an subroutine running as Process_Item


On 10/08/2009 11:21 PM, Michael Stovenour wrote:
> One other potential option is to have the separate process send an xAP
> message.  The xAP message can then be picked up by the MH main loop.  I
> wanted to try this with another project, but I really do not understand
how
> to extend the xAP schema support in MH.  Oh, how I wish for a little
> developer documentation....  ;^)
>

xAP is straight forward.  Here is a snipet of code I use in a code
module to send and receive LIRC messages across the network.  You
should be able to tweak it for your needs.

You want to replace "xap-lirc" to something else.  You also need
to load the various hash elements for whatever you need.

I use the xapalyzer application to snoop the network.  You can
find xapalyzer on the internet somewhere.

# Send lirc to network
sub xAP_send_lirc {
     my ($code,$action,$key,$remote) = @_;
     my $interface = "lirc";
     print_log "xAP_LIRC:: send interface: $interface code: $code
action: $action key: $key remote: $remote" if $main::Debug{xap_echo};
     my $lirc_block;
     $lirc_block->{'interface'} = $interface;
     $lirc_block->{'code'} = $code;
     $lirc_block->{'action'} = $action;
     $lirc_block->{'key'} = $key;
     $lirc_block->{'remote'} = $remote;
     print_log "xAP_LIRC:: send interface: $interface code: $code
action: $action key: $key remote: $remote" if $main::Debug{xap_echo};
     &xAP::send('xAP', 'xap-lirc.data', 'xap-lirc.data' => $lirc_block);
}

# Receive lirc from network
$_xap_lirc_obj = new xAP_Item('xap-lirc.data');
if ($_xap_lirc_obj->state_now) {
    # dump some debugging information
#   foreach my $key (keys %{$_xap_lirc_obj->{'xap-header'}}) {
#     print_log ("xAP_lirc:: receive key: $key data:
$_xap_lirc_obj->{'xap-header'}{$key}") if $main::Debug{xap_echo};
#   }
#   foreach my $key (keys %{$_xap_lirc_obj->{'xap-lirc.data'}}) {
#     print_log ("xAP_lirc:: receive key: $key data:
$_xap_lirc_obj->{'xap-lirc.data'}{$key}") if $main::Debug{xap_echo};
#   }
    # validate the XAP packet
    my $classname = $_xap_lirc_obj->{'xap-header'}{class};
    return unless ($classname eq 'xap-lirc.data');
    my $interface = $_xap_lirc_obj->{'xap-lirc.data'}{interface};
    return unless (lc $interface eq 'lirc');
    my $code = $_xap_lirc_obj->{'xap-lirc.data'}{code};
    my $action = $_xap_lirc_obj->{'xap-lirc.data'}{action};
    my $key = $_xap_lirc_obj->{'xap-lirc.data'}{key};
    my $remote = $_xap_lirc_obj->{'xap-lirc.data'}{remote};
    print_log "xAP_LIRC:: receive interface: $interface code: $code
action: $action key: $key remote: $remote" if $main::Debug{xap_echo};
    &lirc_process($code,$action,$key,$remote);
}

Jim

> -----Original Message-----
> From: Thorsten Weiss [mailto:thoweiss@...]
> Sent: Thursday, October 08, 2009 2:49 AM
> To: misterhouse-users@...
> Subject: Re: [mh] How to get vars from an subroutine running as
Process_Item
>
>
> I think the only way to acess the data is to write it into an external
file,
> and then read the file from the mainloop.
>
> I will try it it with xml-simple.
>
> i crate an xml-file with the measures, and then i can process the xml in
MH

> with xml::simple.
>
>
> When i wrote the code i will post it here.
>
>
>
> Regards,
>
> Thorsten
>



----------------------------------------------------------------------------
--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
________________________________________________________
To unsubscribe from this list, go to:
http://sourceforge.net/mail/?group_id=1365


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365