simple plug-in example

Moderator: Mattk

Periklast
Junior Boarder
Junior Boarder
Posts: 34
Joined: Sun Apr 26, 2009 9:14 am

simple plug-in example

Post 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
skyewright
Platinum Boarder
Platinum Boarder
Posts: 873
Joined: Fri Jan 25, 2008 6:27 pm
Location: Isle of Skye, Scotland

Re:simple plug-in example

Post 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?
Periklast
Junior Boarder
Junior Boarder
Posts: 34
Joined: Sun Apr 26, 2009 9:14 am

Re:simple plug-in example

Post 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).
skyewright
Platinum Boarder
Platinum Boarder
Posts: 873
Joined: Fri Jan 25, 2008 6:27 pm
Location: Isle of Skye, Scotland

Re:simple plug-in example

Post 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?
Periklast
Junior Boarder
Junior Boarder
Posts: 34
Joined: Sun Apr 26, 2009 9:14 am

Re:simple plug-in example

Post by Periklast »

Billy
Senior Boarder
Senior Boarder
Posts: 47
Joined: Sun Oct 11, 2009 1:00 pm

Re:simple plug-in example

Post 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.
Periklast
Junior Boarder
Junior Boarder
Posts: 34
Joined: Sun Apr 26, 2009 9:14 am

Re:simple plug-in example

Post by Periklast »

Thanks! That's work.
Maybe usefull if that's in the manual..
Periklast
Junior Boarder
Junior Boarder
Posts: 34
Joined: Sun Apr 26, 2009 9:14 am

Re:simple plug-in example

Post 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.
skyewright
Platinum Boarder
Platinum Boarder
Posts: 873
Joined: Fri Jan 25, 2008 6:27 pm
Location: Isle of Skye, Scotland

Re:simple plug-in example

Post 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.
skyewright
Platinum Boarder
Platinum Boarder
Posts: 873
Joined: Fri Jan 25, 2008 6:27 pm
Location: Isle of Skye, Scotland

Re:simple plug-in example

Post 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?
Periklast
Junior Boarder
Junior Boarder
Posts: 34
Joined: Sun Apr 26, 2009 9:14 am

Re:simple plug-in example

Post 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.
skyewright
Platinum Boarder
Platinum Boarder
Posts: 873
Joined: Fri Jan 25, 2008 6:27 pm
Location: Isle of Skye, Scotland

Re:simple plug-in example

Post 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.
Periklast
Junior Boarder
Junior Boarder
Posts: 34
Joined: Sun Apr 26, 2009 9:14 am

Re:simple plug-in example

Post 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);
}
skyewright
Platinum Boarder
Platinum Boarder
Posts: 873
Joined: Fri Jan 25, 2008 6:27 pm
Location: Isle of Skye, Scotland

Re:simple plug-in example

Post 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...
Periklast
Junior Boarder
Junior Boarder
Posts: 34
Joined: Sun Apr 26, 2009 9:14 am

Re:simple plug-in example

Post 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!
Post Reply