Can a perl script be a plug-in?

Moderator: Mattk

Post Reply
skyewright
Platinum Boarder
Platinum Boarder
Posts: 873
Joined: Fri Jan 25, 2008 6:27 pm
Location: Isle of Skye, Scotland

Can a perl script be a plug-in?

Post by skyewright » Thu Feb 04, 2010 8:21 pm

Hi,

I've little Linux experience and I'm hoping this is a really simple question for someone who knows the answer. :laugh:

I've just got a "Cost Control CC128" electricity consumption monitor. I also got a serial to USB lead (uses the Prolific chip), and by adapting a simple script, installing a CPAN module and activating the prolific driver module I now have an executable perl script. So at the shell command line I can type:

./ccpi.pl

and I get plug-in style output, e.g.

data0 60500
data1 3433
data0 60500
data1 3411

However if I set up a plug-in weather station with a plug-in path of:

/srv/www/myweb/ccpi.pl

no sensors are seen by Meteohub.

Am I missing something obvious?

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

Re:Can a perl script be a plug-in?

Post by Billy » Sat Feb 06, 2010 1:10 am

Hi,
I don't know the answer, but I have a similar problem.
I wrote a perl script to get data from my heating system to meteohub. I also installed the CPAN module and the script was running well!

I get as an output for the temperatures:
t1 35
t2 340
t3 355
t4 470
.....
As the script is running in a {while}loop and print out the data every minute,
I setup the plug-in without filling in the plug-in path. Following an other thread in this forum.
But no sensors are seen in meteohub too.

error message: meteohub log

logger (05.02.2010 22:40:34): connect station 1 (Plug-in via Plug-in).
logger (05.02.2010 22:40:34): unexpected 0 bytes delivered from weather station 1 (Plug-in)
What is going wrong?

skyewright
Platinum Boarder
Platinum Boarder
Posts: 873
Joined: Fri Jan 25, 2008 6:27 pm
Location: Isle of Skye, Scotland

Re:Can a perl script be a plug-in?

Post by skyewright » Sat Feb 06, 2010 5:39 pm

Billy wrote:What is going wrong?
I'm not at all certain but I think that something is perhaps not "letting go" of the connection cleanly?

I have managed to get Meteohub to see plug-in output on a couple of occasions by pulling out then re-inserting the connector, but even when that 'works' (and that's not every time - possibly because of the connector picking up ttyUSB1 instead of ttyUSB0 sometimes?) Meteohub only sees one cycle of the reading loop. When Meteohub tries to restart the plug-in after 150 seconds of silence, there is still nothing.

Very strange.

Are you also using the Prolific driver?

I believe it used to be possible to get an old fashioned serial cable for the device I'm using (Current Cost CC128). I may see if I can get hold of one of those - that would at least take serial-to-USB considerations out of the equation!

User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 5879
Joined: Mon Oct 01, 2007 10:51 pm

Re:Can a perl script be a plug-in?

Post by admin » Sun Feb 07, 2010 1:04 pm

When Perl script runs but no data delivered to Meteohub, flushing might be a solution. When acting on pipes you don't have control when data is written from buffers to the listening device. So it might be that the Perl script writes data, but these just fill-up buffers. Of course buffers will be flushed after some amount of data (and when writing process terminates), but that can take time as you feed very little data in. From Meteohub's point of view no data is coming through, so it tries a restart and things start again...

Only solution to that is to manually flush buffers after having written your data to the pipe. Please change your Perl script accordingly give it a try.

Link to flushing in Perl: http://www.rocketaware.com/perl/perlfaq ... fileha.htm

skyewright
Platinum Boarder
Platinum Boarder
Posts: 873
Joined: Fri Jan 25, 2008 6:27 pm
Location: Isle of Skye, Scotland

Re:Can a perl script be a plug-in?

Post by skyewright » Sun Feb 07, 2010 2:16 pm

admin wrote:Only solution to that is to manually flush buffers after having written your data to the pipe. Please change your Perl script accordingly give it a try.
Thank you.

Adding the line

STDOUT->autoflush( 1 );

did the trick. :cheer:

However I may have found a slight deviation from the plug-in documentation, which states:
Data data# 0-39 system data [1/100 value]
In practice I seem to find that anything above data19 is seen but is listed as Type unknown.

I don't have more that 20 sensors (yet) but 30 are possible. The CC128 can read from up to 10 sensors (numbered 0 to 9), and each can have up to 3 'channels' *numbered 1 to 3). Those numbers are in the xml that I'm parsing and I'd hoped to use a regex so that each available value resulted in a line to stdout on the basis of:

data<channelNumber><sensorNumber> <valueX100>

e.g. Channel 1 on sensor 0 is data10, channel 2 on sensor 3 is data23, and so on up to, channel 3 on sensor 9 is data39.

Should that be possible?

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

Re:Can a perl script be a plug-in?

Post by Billy » Sun Feb 07, 2010 6:08 pm

Thanks a lot for these hints. I'll check it for my situation after one week on vacation.

:)

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

Re:Can a perl script be a plug-in?

Post by Billy » Thu Feb 18, 2010 9:09 am

As promised herewith my feedback.
Perl script is now running well after optimizing some "while loops".
STDOUT->autoflush( 1 ); was not necessary as I used $| = 1;for flushing.

BTW: Does anybody know if one can use Meteohub to log and display digital data 0/1 like:
eg. power off/on or pump off/on ?

Thanks for help.

Billy

skyewright
Platinum Boarder
Platinum Boarder
Posts: 873
Joined: Fri Jan 25, 2008 6:27 pm
Location: Isle of Skye, Scotland

Re:Can a perl script be a plug-in?

Post by skyewright » Thu Feb 18, 2010 11:28 am

Billy wrote:BTW: Does anybody know if one can use Meteohub to log and display digital data 0/1 like:
eg. power off/on or pump off/on ?
The generic "data" type always stores data with 2 decimal places, but the data itself could easily be integer in nature. How a web page or graph is then used to display and interpret the data is up to it.

e.g. php or javascript could easily use an if statement with a condition that branches on whether or not the value is equal to zero, or you could use Meteohub to graph the value (or it's "rise" &/or "fall" properties).

thlmobile
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: Thu Dec 27, 2012 10:15 am

Re: Can a perl script be a plug-in?

Post by thlmobile » Fri Dec 28, 2012 5:34 am

Boris fixed this right after my post, several versions ago. I'm currently running v4.5i, and wind reporting from the RainWise MkIII is fine. What version is your Meteohub?






______________________________________________________
Mobile Phones Lenovo LePad S2005A Lenovo LePhone P700

netsigi
Senior Boarder
Senior Boarder
Posts: 74
Joined: Wed Aug 05, 2009 7:27 pm

Re: Re:Can a perl script be a plug-in?

Post by netsigi » Sat Mar 07, 2015 12:39 pm

skyewright wrote:
Adding the line

STDOUT->autoflush( 1 );

did the trick. :cheer:
Wow, that helped me today too. Changed Bash/nc script to some quite serious Perl socket. Tested for weeks in SDTOUT, but never as plugin itself. Old posts are still useful.. :lol:

Post Reply