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.
Switch webcam by time
- MrData
- Observer
- Posts: 35
- Joined: Tue Oct 31, 2017 3:02 pm
- Location: Southeast Wisconsin, USA
- Station model: Davis Vantage Pro II
- Software: Meteobridge
- Contact:
Switch webcam by time
HEALTH WARNING: Caution...these posts may contain traces of nut.
My Backyard Webcam temporarily offline
My Meteotemplate Weather Station temporarily offline
My Backyard Webcam temporarily offline
My Meteotemplate Weather Station temporarily offline
- Asobig
- Advisor
- Posts: 72
- Joined: Mon Aug 21, 2017 7:05 am
- Location: Almere
- Station model: Davis Vantage VP2+
- Software: Meteobridge (Red)
- Contact:
Re: Switch webcam by time
The webcam plugin has that routine.
It is in the file 'updateWebcam.php', perhaps you can modify that to your needs?
It is in the file 'updateWebcam.php', perhaps you can modify that to your needs?
Code: Select all
if($recordDay==false){
$updateWebcam = true; // interval passed, recording enabled during night as well
}
else{ // only record during the day
$dateTimeZone = new DateTimeZone($stationTZ);
$dateTime = new DateTime("now", $dateTimeZone);
$my = $dateTimeZone->getOffset($dateTime);
$offset = $my/3600;
$sunRiseTodayHours = date_sunrise(time(),SUNFUNCS_RET_STRING,$stationLat,$stationLon,90.5,$offset);
$sunSetTodayHours = date_sunset(time(),SUNFUNCS_RET_STRING,$stationLat,$stationLon,90.5,$offset);
$sunRiseTimestamp = strtotime(date("Y")."-".date('m')."-".date('d')." ".$sunRiseTodayHours) - (60*60); // subtract one hour to start recording before sunrise
$sunSetTimestamp = strtotime(date("Y")."-".date('m')."-".date('d')." ".$sunSetTodayHours) + (60*60); // add one hour to stop recording after sun set
if(time()>=$sunRiseTimestamp && time()<=$sunSetTimestamp){
$updateWebcam = true;
}
else{
echo "Night time.<br>";
}
- MrData
- Observer
- Posts: 35
- Joined: Tue Oct 31, 2017 3:02 pm
- Location: Southeast Wisconsin, USA
- Station model: Davis Vantage Pro II
- Software: Meteobridge
- Contact:
Re: Switch webcam by time
Thanx, I'll look into that.
I'm going to try this for now.........
date_default_timezone_set('America/Chicago');
$now = date('H:i');
$sunrise = date_sunrise(time(), SUNFUNCS_RET_STRING, 43.1141, -88.5101, 90, -6);
$sunset = date_sunset(time(), SUNFUNCS_RET_STRING, 43.1141, -88.5101, 90, -6);
if($now >= $sunrise && $now <= $sunset){
$webcamURLs = 'http://foo.bar:3415/cam_2.cgi';
} else{
$webcamURLs = 'http://foo.bar:3415/cam_1.cgi';
}
I'm going to try this for now.........
date_default_timezone_set('America/Chicago');
$now = date('H:i');
$sunrise = date_sunrise(time(), SUNFUNCS_RET_STRING, 43.1141, -88.5101, 90, -6);
$sunset = date_sunset(time(), SUNFUNCS_RET_STRING, 43.1141, -88.5101, 90, -6);
if($now >= $sunrise && $now <= $sunset){
$webcamURLs = 'http://foo.bar:3415/cam_2.cgi';
} else{
$webcamURLs = 'http://foo.bar:3415/cam_1.cgi';
}
HEALTH WARNING: Caution...these posts may contain traces of nut.
My Backyard Webcam temporarily offline
My Meteotemplate Weather Station temporarily offline
My Backyard Webcam temporarily offline
My Meteotemplate Weather Station temporarily offline