#!/usr/bin/perl # run with crontab: # */5 * * * * (cd public_html/arduino; ./sample.pl) use strict; #my @data = `curl -s http://home.c2.com/k9ox/one-wire.cgi`; my @data = `curl -s 'http://98.232.243.25:8080/one-wire.cgi'`; my %code; my $time = time; for (@data) { next if /error/; $code{$1}++ if /(([0-9A-F]{1,2} ?){8})/; } for (sort keys %code) { vote($_, $code{$_}); } sub vote { my ($code, $samples) = @_; my %votes; for (@data) { $votes{$1}++ if /$code.*\t(\d+\.\d)\d*$/; } my @best = sort {$votes{$b} <=> $votes{$a}} keys %votes; my $best = shift @best; mkdir "results/$code" unless -e "results/$code"; open H, ">>results/$code/history.txt"; print H "$time\t$best\t$votes{$best}/$samples\n"; }