After some help with a perl script

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
DervMan
Posts: 25
Joined: Tue Apr 29, 2008 11:11 am

After some help with a perl script

Post by DervMan »

Hi there,

I have a perl script which runs successfully manually but doesn't run under cacti. The script connects to a USB to serial adapter and waits up to 5 seconds to receive some data from a 'Current Cost' energy monitor.

Here's the output when I run it manually

steve@NAS:/usr/share/cacti/site/scripts$ ./cc-classic.pl
Watts:1285 Temperature:16.7


Here's what I get in the cacti log.

04/02/2011 10:10:13 AM - CMDPHP: Poller[0] Host[1] DS[101] CMD: /usr/bin/perl /usr/share/cacti/site/scripts/cc-classic.pl, output: U



I'm using the 'WeatherBug' perl script which works fine.


File permissions on the script.
-rwxrwxrwx 1 root root 495 2011-04-02 00:18 cc-classic.pl*

Here's the perl script
#!/usr/bin/perl -w

# Reads data from a Current Cost device via serial port.

use strict;
use Device::SerialPort qw( :PARAM :STAT 0.07 );

my $PORT = "/dev/ttyUSB0";

my $ob = Device::SerialPort->new($PORT);
$ob->baudrate(2400);
$ob->write_settings;

open(SERIAL, "+>$PORT");
while (my $line = <SERIAL>) {
if ($line =~ m!<ch1><watts>0*(\d+)</watts></ch1>.*<tmpr> *([\-\d.]+)</tmpr>!) {
my $watts = $1;
my $temp = $2;
print "Watts:$watts Temperature:$temp\n";
}
}





Any ideas?
Attachments
Data Template
Data Template
data-template.jpg (163.27 KiB) Viewed 421 times
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: After some help with a perl script

Post by gandalf »

Did you run this as "cactiuser". Does this user has access to the given port?
R.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests