simple plug-in example
Moderator: Mattk
simple plug-in example
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
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
-
- Platinum Boarder
- Posts: 873
- Joined: Fri Jan 25, 2008 6:27 pm
- Location: Isle of Skye, Scotland
Re:simple plug-in example
Do you have autoflush set, e.g.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.
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
My perl code:
I run the file in 2 different ways:
or
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:
The meteohub log-files shows:
Code: Select all
#!/usr/bin/perl
use IO::Handle;
while (true){
print "sol0 1\\n";
STDOUT->autoflush(1);
sleep(5);
}
Code: Select all
./test.pl
Code: Select all
update-rc.d test.pl defaults
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
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).
-
- Platinum Boarder
- Posts: 873
- Joined: Fri Jan 25, 2008 6:27 pm
- Location: Isle of Skye, Scotland
Re:simple plug-in example
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.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); }
From the command line that should be fine.I run the file in 2 different ways:
Code: Select all
./test.pl
What do you have in the Weather Station setup?
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?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".
Perhaps I'm misunderstanding? Could you post a screen shot?
Re:simple plug-in example
This is my screenshot:
http://img690.imageshack.us/img690/9215/tempfi.jpg
http://img690.imageshack.us/img690/9215/tempfi.jpg
Re:simple plug-in example
I think your plugin path is not what meteohub expects.Periklast wrote:This is my screenshot:
http://img690.imageshack.us/img690/9215/tempfi.jpg
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
Thanks! That's work.
Maybe usefull if that's in the manual..
Maybe usefull if that's in the manual..
Re:simple plug-in example
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.
-
- Platinum Boarder
- Posts: 873
- Joined: Fri Jan 25, 2008 6:27 pm
- Location: Isle of Skye, Scotland
Re:simple plug-in example
Yes, the Weather Station setup needs the path as well as the name of the executable file itself.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.
-
- Platinum Boarder
- Posts: 873
- Joined: Fri Jan 25, 2008 6:27 pm
- Location: Isle of Skye, Scotland
Re:simple plug-in example
What exactly are you doing in your code?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.
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);
}
Re:simple plug-in example
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.
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.
-
- Platinum Boarder
- Posts: 873
- Joined: Fri Jan 25, 2008 6:27 pm
- Location: Isle of Skye, Scotland
Re:simple plug-in example
Please post the exact code you are running.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.
That code may or may not provide the answer, but without it we can only make guesses.
Re:simple plug-in example
Here is my code
or
Code: Select all
#!/usr/bin/perl
use IO::Handle;
my $value = 1;
STDOUT->autoflush(1);
while (true){
print "sol0 $value\\n";
$value++;
sleep(5);
}
Code: Select all
#!/usr/bin/perl
use IO::Handle;
my $value = 1;
while (true){
print "sol0 $value\\n";
STDOUT->autoflush(1);
$value++;
sleep(5);
}
-
- Platinum Boarder
- Posts: 873
- Joined: Fri Jan 25, 2008 6:27 pm
- Location: Isle of Skye, Scotland
Re:simple plug-in example
On my ALIX-1DPeriklast wrote:Here is my code
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 );
}
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
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!
Tomorrow, I will test it on my Alix-1D. Thanks!