Page 1 of 2

simple plug-in example

Posted: Sat Mar 13, 2010 9:06 am
by Periklast
Can someone post a simple plugin-perl code sample for meteohub?

Just an simple script that output for example "sol0 1" each 30 seconds.
I wrote such a perl-script but meteohub doesn't recognize it.

Thanks

Re:simple plug-in example

Posted: Sat Mar 13, 2010 11:42 am
by skyewright
Periklast wrote:Just an simple script that output for example "sol0 1" each 30 seconds.
I wrote such a perl-script but meteohub doesn't recognize it.
Do you have autoflush set, e.g.

STDOUT->autoflush( 1 );

Boris mentioned why that might be needed in this posting.

If that doesn't help, maybe you could post your script and a screen shot of how you have set up the plug-in on the weather station setup page?

Re:simple plug-in example

Posted: Sat Mar 13, 2010 12:33 pm
by Periklast
My perl code:

Code: Select all

#!/usr/bin/perl
use IO::Handle;

while (true){
print "sol0 1\\n";
STDOUT->autoflush(1);
sleep(5);
}
I run the file in 2 different ways:

Code: Select all

./test.pl
or

Code: Select all

update-rc.d test.pl defaults
With the last method, the file will run to, but I can't reboot or the after reboot, the webserver can't start anymore.

On the meteohub-webpage, I created a new weather station (Plug-in) and on the sensor-page I created an sol0 sensor with the name "solar".
On that page, I see follow warning:

Code: Select all

Warning: Weather station does not have a sensor assigned on "Sensors" page
The meteohub log-files shows:

Code: Select all

logger (13.03.2010 11:33:13): connect station 0 (Plug-in via Plug-in).
logger (13.03.2010 11:33:13): unexpected 0 bytes delivered from weather station 0 (Plug-in)
logger (13.03.2010 11:33:13): disconnect station 0 (Plug-in).

Re:simple plug-in example

Posted: Sat Mar 13, 2010 3:55 pm
by skyewright
Periklast wrote:My perl code:

Code: Select all

#!/usr/bin/perl
use IO::Handle;

while (true){
print "sol0 1\\n";
STDOUT->autoflush(1);
sleep(5);
}
I'm not sure it's a significant difference, but I have the autoflush outside the loop. It's a "switch" rather than something you need to keep doing.
I run the file in 2 different ways:

Code: Select all

./test.pl
From the command line that should be fine.

What do you have in the Weather Station setup?
On the meteohub-webpage, I created a new weather station (Plug-in) and on the sensor-page I created an sol0 sensor with the name "solar".
That has me puzzled, as if there is a sensor there for you to assign I'd have thought that meant that the plug-in was working?

Perhaps I'm misunderstanding? Could you post a screen shot?

Re:simple plug-in example

Posted: Sun Mar 14, 2010 11:36 am
by Periklast

Re:simple plug-in example

Posted: Sun Mar 14, 2010 12:22 pm
by Billy
Periklast wrote:This is my screenshot:
http://img690.imageshack.us/img690/9215/tempfi.jpg
I think your plugin path is not what meteohub expects.
It should be something like
/data/plugin/test.pl

where test.pl is your actual perl script.

The perl script is then started by meteohub automatically. And will provide the expected sensor data.

Re:simple plug-in example

Posted: Sun Mar 14, 2010 12:29 pm
by Periklast
Thanks! That's work.
Maybe usefull if that's in the manual..

Re:simple plug-in example

Posted: Sun Mar 14, 2010 12:41 pm
by Periklast
Ah no, it doesn't refresh at the moment. I put an increment "sol 0" -> "sol 1" -> "sol 2" with time-interval of 5 seconds, but only "sol 0" is shown. The "last signal" value becomes larger and larger.

Re:simple plug-in example

Posted: Sun Mar 14, 2010 12:44 pm
by skyewright
Billy wrote:I think your plugin path is not what meteohub expects.
It should be something like
/data/plugin/test.pl

where test.pl is your actual perl script.
Yes, the Weather Station setup needs the path as well as the name of the executable file itself.

Re:simple plug-in example

Posted: Sun Mar 14, 2010 12:50 pm
by skyewright
Periklast wrote:Ah no, it doesn't refresh at the moment. I put an increment "sol 0" -> "sol 1" -> "sol 2" with time-interval of 5 seconds, but only "sol 0" is shown. The "last signal" value becomes larger and larger.
What exactly are you doing in your code?

If exactly as quoted then maybe it's just the lack of a digit after sol. e.g.

Code: Select all

my $value = 1;

while (true){ 
print "sol0 $value\\n";
$value++; 
sleep(5); 
} 
How's that?

Re:simple plug-in example

Posted: Sun Mar 14, 2010 1:01 pm
by Periklast
If I manually run that code you described, I see the change in my output every 5 seconds.

But meteohub can see only the first value (in this situation, only 0 ). Even if I STDOUT->autoflush(1) in every loop or before the loop.

Re:simple plug-in example

Posted: Sun Mar 14, 2010 1:20 pm
by skyewright
Periklast wrote:But meteohub can see only the first value (in this situation, only 0 ). Even if I STDOUT->autoflush(1) in every loop or before the loop.
Please post the exact code you are running.

That code may or may not provide the answer, but without it we can only make guesses.

Re:simple plug-in example

Posted: Sun Mar 14, 2010 1:25 pm
by Periklast
Here is my code

Code: Select all

#!/usr/bin/perl
use IO::Handle;
my $value = 1;
STDOUT->autoflush(1);
while (true){
print "sol0 $value\\n";

$value++;



sleep(5);
}
or

Code: Select all

#!/usr/bin/perl
use IO::Handle;
my $value = 1;

while (true){
print "sol0 $value\\n";
STDOUT->autoflush(1);
$value++;



sleep(5);
}

Re:simple plug-in example

Posted: Sun Mar 14, 2010 2:04 pm
by skyewright
Periklast wrote:Here is my code
On my ALIX-1D

The following works exactly as expected, i.e. providing Meteohub with a value that increments every 5 seconds.

Code: Select all

#!/usr/bin/perl -w
use strict;
use IO::Handle;
my $value = 1;
STDOUT->autoflush( 1 );
while ( 1 )
{
    print "sol0 $value\\n";

    $value++;
    sleep( 5 );
}
All I've done is

a) Add -w to the first line to turn on warnings.
b) Add use strict;
c) Change true to 1 to placate a warning message.

All of which are largely just a matter of coding style!

Strange...

Re:simple plug-in example

Posted: Sun Mar 14, 2010 2:10 pm
by Periklast
The code above doesn't work for me. Maybe it's because I'm testing within vmware?

Tomorrow, I will test it on my Alix-1D. Thanks!