#!/bin/tclsh
#Version 1.2
#param 0 = Breitengrad (nördlich)
#param 1 = Längengrad (östlich)
#param 2 = künstlicher Horizont
#param 3 = PLZ
source /www/addons/lcd_msg/daemonize.tcl
load tclrega.so
puts "args: $argv"
set latitude [lindex $argv 0]
set longitude [lindex $argv 1]
set indoor_horizon [lindex $argv 2]
set plz [lindex $argv 3]
set timezone_start [expr {([clock scan "0 UTC"] - [clock scan "0"]) / 3600.0}]
set dayofyear [string trimleft [clock format [clock seconds] -format "%j"] "0"]
set dayofyear [expr {$dayofyear + ([clock format [clock seconds] -format "%Y"]%4)/4.0 + ($dayofyear)/365.0/4.0}]
puts "timezone: $timezone_start"
puts "day of year: $dayofyear"
proc calcTwilightTimes {latitude longitude timezone dayofyear horizon sunrisevar sunsetvar} {
upvar $sunrisevar sunrise
upvar $sunsetvar sunset
set timediff [expr {-0.171*sin(0.0337 * $dayofyear + 0.465) - 0.1299*sin(0.01787 * $dayofyear - 0.168)}]
set declination [expr {0.4095 * sin(0.016906 * ($dayofyear - 80.086) ) }]
set suntime [expr {12*acos((sin($horizon/57.29578) - sin($latitude/57.29578)*sin($declination)) / (cos($latitude/57.29578)*cos($declination)))/3.141592}]
set sunrise [expr {[clock scan "0"] + round((12 - $timediff - $suntime - $longitude/15.0 + $timezone)*3600)}]
set sunset [expr {[clock scan "0"] + round((12 - $timediff + $suntime - $longitude/15.0 + $timezone)*3600)}]
}
proc getTwilightHorizon {plz base_horizon} {
set url http://www.google.com/ig/api?weather=$plz-Germany&hl=de
catch {
exec /usr/bin/wget -q -O /tmp/twilightweather.xml $url
set f [open "/tmp/twilightweather.xml"]
set a [read $f]
close $f
regexp "
\n
Dämmerung | Morgens | Abends |
[lindex $twilight_types $i] | " } else { append display " | |
[lindex $twilight_types $i] | " } if {$i == $current_state-1} then {append display ""} if {$i == 5 && !$srw_set} then {append display ""} append display "[showTwilightTime [lindex $twilight_times $i]]" if {$i == 5 && !$srw_set} then {append display ""} if {$i == $current_state-1} then {append display ""} append display " | " if {$i == 12-$current_state} then {append display ""} if {$i == 5 && !$ssw_set} then {append display ""} append display "[showTwilightTime [lindex $twilight_times [expr {11-$i}]]]" if {$i == 5 && !$ssw_set} then {append display ""} if {$i == 12-$current_state} then {append display ""} } append display " |