From babc6a48fc71446ec8d5fc18bd76238230d16285 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Wed, 13 May 2009 14:15:54 -0400 Subject: [PATCH 1/5] longer delay when flashing seems necessary. --- mc1322x-load.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mc1322x-load.pl b/mc1322x-load.pl index 6145768c9..f1b98838a 100755 --- a/mc1322x-load.pl +++ b/mc1322x-load.pl @@ -87,7 +87,7 @@ while(1) { while(read(FILE, $c, 1)) { $i++; usleep(50); # this is as fast is it can go... - usleep(25) if ($s==1); + usleep(50) if ($s==1); $ob->write($c); } } From 998313d2120d1cd1e75210a8516a4746005cbbfd Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Sun, 17 May 2009 15:33:59 -0400 Subject: [PATCH 2/5] added a tool to enter mesh data from a RIME collect sink into rrd's --- rimecollect-rrd/collect2rrd.pl | 64 +++++++++++++++++++++++++++++++++ rimecollect-rrd/default.rrdtmpl | 1 + 2 files changed, 65 insertions(+) create mode 100755 rimecollect-rrd/collect2rrd.pl create mode 100644 rimecollect-rrd/default.rrdtmpl diff --git a/rimecollect-rrd/collect2rrd.pl b/rimecollect-rrd/collect2rrd.pl new file mode 100755 index 000000000..7460fc2de --- /dev/null +++ b/rimecollect-rrd/collect2rrd.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl -w +use strict; +my $verbose = 1; + +#### +# Feed data on stdin from a RIME collect sink +# +# Enters data into rimeaddr.rrd +# +# Creates rimeaddr.rrd from a template if data shows up from a source and +# rimeaddr.rrd doesn't exist +# +# default template is read from default.rrdtmpl +# +# if rimeaddr.rrdtmpl exisits, that is used instead. + +#### +# +# Templates are shell scripts that create the desired rrd +# + +#### +# Data messages are in the form of: +# +# Sink got message from 1.0, seqno 109, hops 0: len 12 'GPIO29-High' +# +# + +my $datapattern = 'Sink got message from ([\d\.]+), seqno \d+, hops \d+: len \d+ \'([\w\d]+-[\w\d]+)\''; + +sub rrdcreate { + my ($newrrd_filename, $tmpl_filename) = @_; + open FILE, "$tmpl_filename" or die $!; + my $tmpl = ; + print "using template $tmpl found in $tmpl_filename\n" if $verbose; + `rrdtool create $newrrd_filename $tmpl`; +} + +while(<>) { + + next if($_ !~ /$datapattern/); + print("rimeaddr $1 data $2\n") if $verbose; + + my ($ds,$data) = split(/-/,$2); + print("ds: $ds, data: $data\n") if $verbose; + + if(-e "$1.rrd") { + # an rrd already exists for this device + # do an update + `rrdtool update $1.rrd -t $ds N:$data` + } else { + # an rrd for this device doesn't exist yet + # find a template and make it + my $tmpl = "DS:speed:COUNTER:600:U:U RRA:AVERAGE:0.5:6:10"; + print "creating new rrd $1.rrd... " if $verbose; + if(-e "$1.rrdtmpl") { + rrdcreate("$1.rrd","$1.rrdtmpl"); + } elsif(-e "default.rrdtmpl") { + rrdcreate("$1.rrd","default.rrdtmpl"); + } else { + print "can't create rrd for $1: no template found\n"; + } + } +} diff --git a/rimecollect-rrd/default.rrdtmpl b/rimecollect-rrd/default.rrdtmpl new file mode 100644 index 000000000..f5cbc5e96 --- /dev/null +++ b/rimecollect-rrd/default.rrdtmpl @@ -0,0 +1 @@ +-s 1 DS:GPIO29:GAUGE:600:U:U RRA:LAST:0.99:1:3600 From 674af7704406922f12c334f2e15bf0203db626e7 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Sun, 17 May 2009 18:03:12 -0400 Subject: [PATCH 3/5] update after creating a new rrd --- rimecollect-rrd/collect2rrd.pl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rimecollect-rrd/collect2rrd.pl b/rimecollect-rrd/collect2rrd.pl index 7460fc2de..197e02e3d 100755 --- a/rimecollect-rrd/collect2rrd.pl +++ b/rimecollect-rrd/collect2rrd.pl @@ -32,6 +32,7 @@ sub rrdcreate { my ($newrrd_filename, $tmpl_filename) = @_; open FILE, "$tmpl_filename" or die $!; my $tmpl = ; + chomp $tmpl; print "using template $tmpl found in $tmpl_filename\n" if $verbose; `rrdtool create $newrrd_filename $tmpl`; } @@ -55,8 +56,10 @@ while(<>) { print "creating new rrd $1.rrd... " if $verbose; if(-e "$1.rrdtmpl") { rrdcreate("$1.rrd","$1.rrdtmpl"); + `rrdtool update $1.rrd -t $ds N:$data` } elsif(-e "default.rrdtmpl") { rrdcreate("$1.rrd","default.rrdtmpl"); + `rrdtool update $1.rrd -t $ds N:$data` } else { print "can't create rrd for $1: no template found\n"; } From 6d75aa1bed9ace3a41c2262c5be94934df0ed16b Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Mon, 18 May 2009 17:53:51 -0400 Subject: [PATCH 4/5] added a script that creates a webpage of all the collected data. has basic naming capabilities. --- rimecollect-rrd/meshstat.cgi | 66 ++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 rimecollect-rrd/meshstat.cgi diff --git a/rimecollect-rrd/meshstat.cgi b/rimecollect-rrd/meshstat.cgi new file mode 100755 index 000000000..c95a1b3a7 --- /dev/null +++ b/rimecollect-rrd/meshstat.cgi @@ -0,0 +1,66 @@ +#!/usr/bin/perl -w + +# CGI script that creates a fill-out form +# and echoes back its values. + +use CGI qw/:standard/; + +# configs + +# paths +my $meshpath = "/home/malvira/work"; +my $wwwpath = "/var/www"; +my $hostname = "localhost"; + +# aliases +my %aliases = ( + "2.0" => { + alias => "Lower Door", + ds=> { + "GPIO29" => "Lock", + }, + }, + "4.0" => { + alias => "Upper Door", + }, + "1.0" => { + alias => "Sink (Hotdog)", + }, + ); + +opendir(MESHDIR, $meshpath); +my @files = readdir(MESHDIR); + +print header; +print start_html('Collect Mesh'); + + +foreach my $file (@files) { + next if $file !~ /([\d\.]+)\.rrd$/; + my $addr = $1; + print hr; + print h1("$addr: $aliases{$addr}{'alias'}"); + my @info = split(/\n/,qx(rrdtool info $meshpath/$addr.rrd)); + + my %ds; + foreach my $info (@info) { + next if $info !~ /ds\[([\w\d]+)\]/; + $ds{$1}++; + } + + foreach my $ds (keys(%ds)) { + print h2("$ds: $aliases{$addr}{'ds'}{$ds}"); + qx(rrdtool graph $wwwpath/$addr-$ds.png --start end-60min DEF:$ds=$meshpath/$addr.rrd:$ds:LAST LINE2:$ds#00a000:\"$ds\"); + print img({src=>"http://$hostname/$addr-$ds.png"}); + } + +} + +print hr; + +print end_html; + +#/var/www/demo.png --title="Door" --start end-60min +# --imginfo '' +# DEF:door=/home/malvira/work/2.0.rrd:GPIO29:LAST +# LINE2:door#00a000:"Door lock"> From 6cafcc123489aee536621ead3e604696a767faf6 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Mon, 18 May 2009 17:57:21 -0400 Subject: [PATCH 5/5] check if $count is defined. --- mc1322x-load.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mc1322x-load.pl b/mc1322x-load.pl index f1b98838a..f545ad89d 100755 --- a/mc1322x-load.pl +++ b/mc1322x-load.pl @@ -115,7 +115,7 @@ if(scalar(@ARGV)!=0) { my $c; my $count; while(1) { ($count, $c) = $ob->read(1); - print $c if ($count != 0); + print $c if (defined($count) && ($count != 0)); } $ob -> close or die "Close failed: $!\n";