Switch webcam by time
Posted: Fri Feb 28, 2020 10:28 pm
I have 2 webcams. One is an outdoor cam and has IR lights, the other is an indoor cam looking out of a window. Both of them show pretty much the same view but I wanted to see if I could use a conditional statement to switch between the two based on time of day.
Found some PHP help on the Wide World of Webs and gave it a try. This seems to work nicely....
<?php
// webcam settings file
// Version: 6.0
// Created: 2020-02-27 00:12:49
date_default_timezone_set('America/Chicago');
$now = new Datetime("now");
$begintime = new DateTime('06:00');
$endtime = new DateTime('17:00');
if($now >= $begintime && $now <= $endtime){
$webcamURLs = 'http://foo.bar.net:3415/cam_2.cgi';
} else{
$webcamURLs = 'http://foo.bar.net:3415/cam_1.cgi';
}
$webcamTitles = "Backyard Webcam";
$webcamPositions = '';
$refreshInterval = '1';
$webcamBlockOpacity = false;
$mapPosition = 'BR';
?>
Switches to cam 2 during the day and cam 1 at night. Of course I'm going to have to manually adjust $begintime and $endtime as the year goes on.
Perhaps there is a way to make this conditional on sunrise and sunset times.
Gotta believe those values are already floating around in Meteotemplate somewhere, just have to figure out how to access them.
Found some PHP help on the Wide World of Webs and gave it a try. This seems to work nicely....
<?php
// webcam settings file
// Version: 6.0
// Created: 2020-02-27 00:12:49
date_default_timezone_set('America/Chicago');
$now = new Datetime("now");
$begintime = new DateTime('06:00');
$endtime = new DateTime('17:00');
if($now >= $begintime && $now <= $endtime){
$webcamURLs = 'http://foo.bar.net:3415/cam_2.cgi';
} else{
$webcamURLs = 'http://foo.bar.net:3415/cam_1.cgi';
}
$webcamTitles = "Backyard Webcam";
$webcamPositions = '';
$refreshInterval = '1';
$webcamBlockOpacity = false;
$mapPosition = 'BR';
?>
Switches to cam 2 during the day and cam 1 at night. Of course I'm going to have to manually adjust $begintime and $endtime as the year goes on.
Perhaps there is a way to make this conditional on sunrise and sunset times.
Gotta believe those values are already floating around in Meteotemplate somewhere, just have to figure out how to access them.