Page 2 of 4

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Wed 21 May 2014 2:01 pm
by ace2
Going to test cam uploading with this web tag <#isdaylight>.
Added a text with the webtag into cumulus which output the result been either a 1 or 0 to a file called onoff.text.

The script I'll run every 10 Minutes to check this file is :

Find "1" onoff.txt >nul && call "findpic.exe"

Now I think this will execute the findpic.exe which searches my NAS drive for the latest picture and uploads that.

I normally schedule findpic every 10 minutes and a swap htm to take the camera offline at a certain time.

By adding to the same script the line
Find "0" onoff.txt >nul && call "offline.exe"

This will do the picture swap to take the camera offline

This should automatically upload images between dawn and dusk and take the carema offline.
Now just have to wait till I get home to test this!!!

Have to find another solution to the stop start time lapse by nautical and astronomical twilight another time.

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Thu 22 May 2014 12:47 am
by MackerelSky
Thanks for posting the links BCJKiwi and for giving great insight on this topic.

Brad
BCJKiwi wrote:@ace2
Doing math on dates is absolutely do-able in a batch file.

Construct the batch file with sample data in the format that Cumulus will deliver it to test the match.
Then save the working batch file as batchT.txt
edit it to replace the test data with the webtag.
Cumulus will process the text file and save as batch.cmd
You then run batch.cmd in the program time slot of Cumulus' external programs.
The batch file can do any number of different things in the one file if you need more routines, or, you could have a separate batch file for each routine (from Cumulus or not) and chain them together in another batch file.

Time to study the many features of the batch file language ;)

All manner of things can be carried out in batch files - some complicated some less so.
There are also programs designed to extend and/or simplify these processes.

e.g. Math;
http://www.robvanderwoude.com/battech_math.php
Date and time
http://www.robvanderwoude.com/datetime.php

Also on that site many other commands are described;
http://www.robvanderwoude.com/batchfiles.php

I have also used the Kixtart program extensively over many years for login scripts and for routines similar to some php code.

While these references may appear old, nothing much has changed and these still work in all current versions of Windows AFAIK.

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Thu 22 May 2014 5:04 am
by ace2
Completed the script for webcam uploading using dusk/dawn times which also switches the htm page to take online/offline.

Testing seem to be working fine...

Now to the next one with what BCJKiwi has suggested......

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Thu 22 May 2014 8:37 am
by captzero
Thanks all.
I've checked the links and have a better understanding of how I might achieve my goal of starting and stopping a program based on sun position. I've decided to use either the <#isdaylight> or <#IsSunUp> tags to return 0 or 1.
This Windows Batch Scripting wiki has been a big help. http://en.wikibooks.org/wiki/Windows_Batch_Scripting but I've had to rely on sample batch files I've seen around the net and have cobbled together the following.....

Code: Select all

@REM Using cumulus webtags <#isdaylight> based on the dawn and dusk or <#IsSunUp> based on the sunrise/sunset
@REM if sun = 1 sun is up if sun = 0 sun has set
@ECHO off
@REM webtag variable 
SET sun=1
@REM Start program if sun equals 1
IF "!sun!"=="%1" START "" "C:\Program Files (x86)\Camstreams Media Encoder\Bin\CamstreamsEncoder.exe"
@REM Kill program if sun does not equal 1
IF not "!sun!"=="%1" taskkill /f /im CamstreamsEncoder.exe >nul 2>nul
exit
It will kill the program if its running if sun =0 or 1 and wont run it at all.
Although the links have been a help, I suspect the syntax and the structure are not correct.
I'd appreciate it if some one give me a nudge in the right direction.
Thanks

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Thu 22 May 2014 8:48 am
by mcrossley
As you are not using delayedexpansion change "!sun!" to "%sun%"

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Thu 22 May 2014 9:10 am
by captzero
Thanks Mark,
Perfect. How do you know this stuff???
Thanks again
(Also changed "%1" to "1")

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Thu 22 May 2014 9:15 am
by mcrossley
captzero wrote:How do you know this stuff???
A lifetime (often it feels like more) working in IT :cry:

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Thu 22 May 2014 9:43 am
by ace2
Now all we need to do is work out dawn/dusk times with either + or - x minutes or a webtag for nornautical and astronomical twilight!!

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Thu 22 May 2014 10:32 am
by captzero
If you want to capture images at sunrise and sunset you could use the <#isdaylight> tag to commence and cease capturing at dawn and dusk? Here in Brisbane at the moment, dawn is 25 mins before sunrise and dusk is 25 mins after sunset.

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Thu 22 May 2014 11:25 am
by ace2
captzero wrote:If you want to capture images at sunrise and sunset you could use the <#isdaylight> tag to commence and cease capturing at dawn and dusk? Here in Brisbane at the moment, dawn is 25 mins before sunrise and dusk is 25 mins after sunset.
My goal is to start my time lapse just before first light and just after, here in Adelaide first light breaks about 30 minutes before dawn and about the same after dusk times.
Which kind of sucks!!

But I'm using the <isdaylight> web tag to do my webcam shot, which basically copies latest jpg to web site every X minutes.

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Fri 23 May 2014 1:07 pm
by ace2
Just a thought. Say you wanted to start a time lapse recording just before first light.
I found a script that can minus/add minutes to current time, of course supplement current time for the dawn webtag and once current time is greater than output to a 1 to a txt file.

Then is a matter of running a script that looks at the text and if =1 turn on software and 0 turn off.
Just a thought.
You think it might work??

http://acoderslife.com/index.cfm/blog/A ... batch-file

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Fri 23 May 2014 10:56 pm
by BCJKiwi
There is a lot of irrelevant code in that example for your application.
From Cumulus you can get the hour and minute (separately) for the current time, sunrise and sunset.

create a var for the offset you want.
Do the math

a sample batch file is attached as timeswT.txt
This will set a sunRise Rflag to 1 45 mins before sunrise.
This will set a sunSet Sflag to 1 45 mins after sunset.

It gets the current time, sunset and sunrise times in hour and minutes separately.

converts these times to minutes.
adds/subtracts the offsets, does the comparisons and sets the flags.

You will want to modify it to suit.

All this from the information available in the original references I supplied in the links above.

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Sat 24 May 2014 2:36 am
by ace2
BCJKiwi wrote:There is a lot of irrelevant code in that example for your application.
From Cumulus you can get the hour and minute (separately) for the current time, sunrise and sunset.

create a var for the offset you want.
Do the math

a sample batch file is attached as timeswT.txt
This will set a sunRise Rflag to 1 45 mins before sunrise.
This will set a sunSet Sflag to 1 45 mins after sunset.

It gets the current time, sunset and sunrise times in hour and minutes separately.

converts these times to minutes.
adds/subtracts the offsets, does the comparisons and sets the flags.

You will want to modify it to suit.

All this from the information available in the original references I supplied in the links above.
That would work well, but i would need to process the webtags to a txt file as i have to convert cmd/bat into a exe as the bat/cmd popup interrupt playback on my media pc and output the flags to a txt.
But is a solution..............

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Sat 24 May 2014 6:14 am
by ace2
BCJKiwi
I forgot to say thank you for that script, as it is, it works perfectly and only requires a little modification for my needs.
I was going down a similar path to your script, but my scripting skills are poor....
So tx.

Re: Run External Programs based on Sunrise/Sunset webtags

Posted: Sat 24 May 2014 8:43 pm
by BCJKiwi
@ ace2;
Thnx

The main issue with batch files is understanding the rather arcane syntax.
Baby steps and example scripts along with tutorial type info such as that provided on the linked site in my first post are the way to go for me.

I have been at it since before windows existed but still need to refer back to source and apply trial and error as I just don't do it often enough anymore.