-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprinklerProgram.pl
executable file
·54 lines (44 loc) · 1.71 KB
/
sprinklerProgram.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env perl
use warnings;
use strict;
use cycleSprinklers;
use weatherLib;
use dateLib;
$SIG{'INT'} = 'terminationHandler';
$SIG{'ABRT'} = 'terminationHandler';
$SIG{'TERM'} = 'terminationHandler';
$SIG{'SEGV'} = 'terminationHandler';
my $time = time;
if ( &isOddDay($time) ) {
die getDateString($time), " - odd day exiting\n";
}
my $currentConditions = getCurrentConditions();
if ( isRaining($currentConditions) ) {
die getDateString($time), " - - Rain: No Sprinklers\n";
}
my @yesterdayTemps = getYesterdayTemps($time);
my @pastWeekRainfall = getPastWeekRainfall($time);
my $adjustedRainfallCalculation = getAdjustedRainfallCalculation( @pastWeekRainfall );
$adjustedRainfallCalculation = adjustedForTemperature( $adjustedRainfallCalculation, @yesterdayTemps );
print "Week RainFall: ", join(", ", @pastWeekRainfall),
" Mean/Max Temp: ", join("/", @yesterdayTemps),
" calc: ", $adjustedRainfallCalculation, "\n";
if ( moreThenEnoughRainfall( $adjustedRainfallCalculation ) ) {
die getDateString($time), " - Wet: No Sprinklers\n";
}
print getDateString($time), " - Current:$currentConditions Rainfall:@pastWeekRainfall calc:$adjustedRainfallCalculation \n";
my $cyclesToWater = getCyclesToWater( $adjustedRainfallCalculation );
print getDateString($time), " - Watering $cyclesToWater\n";
&cycleSprinklers($cyclesToWater);
$time = time;
print getDateString($time), " - stopping\n";
my ($year, $month, $day) = parseDate( $time );
my $timeStr = sprintf("%04d%02d%02d", $year, $month, $day);
open( HISTORY, "> history/$timeStr.waterlog" );
print HISTORY $cyclesToWater, "\n";
close HISTORY;
sub terminationHandler {
print "Termination Signal Received - stopping\n";
turnSprinklersOff();
exit(-10);
}