Thanks for the input, @cruunnerr and @martinkooij.
I ended up going with @cruunnerr’s approach as it required fewer changes to my existing setup.
Here is what I did:
- Created a file that lists the devices and their IPs that we want to evaluate. Filename: “devices”.
myphone,192.168.0.200
mywatch,192.168.0.201
wifephone,192.168.0.202
wifewatch,192.168.0.203
- Created a perl script, “ping.pl”, that pings the devices listed in the file. If it gets a response it will write the results to a file named “ping_results”.
#!/usr/bin/perl
use Net::Ping;
open(INFILE, ";
close(INFILE);
#open(OUTFILE, ">", "ping_results") or die("unable to write output: $!");
chomp(@ip_array);
$p = Net::Ping->new();
foreach(@ip_array)
{
if($_ =~ /\d+.\d+.\d+.\d+/)
{
if($p->ping($&))
{
open(OUTFILE, ">", "ping_results") or die("unable to write output: $!");
print OUTFILE ("$`is responding to ping.\n");
close(OUTFILE);
}
}
}
- Added a crontab job to run the perl script at 04:55.
# m h dom mon dow command
# Execute Perl Script to check for devices
55 4 * * * perl /home/pi/ping.pl
- Created a shell script, “rpi-hdmi-on.sh” that will check to see if “ping_results” exists. If it does it will turn the monitor on and then delete the “ping_results” file. Added a crontab job to execute this script at 05:00.
if [ -e ping_results ]
then
vcgencmd display_power 1 >/dev/null
rm -f /home/pi/ping_results
fi
# m h dom mon dow command
# Turn HDMI On (05:00/5:00am)
0 5 * * * /home/pi/rpi-hdmi-on.sh
- Created a shell script, “rpi-hdmi-off.sh” that will turn the monitor off. Added a crontab job to execute this script at 21:30.
vcgencmd display_power 0 >/dev/null
# m h dom mon dow command
# Turn HDMI Off (21:30/9:30pm)
30 21 * * * /home/pi/rpi-hdmi-off.sh
I’ve done some testing and it seems to be working well.