electronic lock needs adaptation
no more intrusion detection, replaced by open/close action when button push also adapted lights change scriptmaster
parent
0f425271f4
commit
68934624dd
|
@ -0,0 +1,20 @@
|
||||||
|
perl did not work
|
||||||
|
556 wget https://github.com/OpenLightingProject/libartnet/releases/download/1.1.2/libartnet-1.1.2.tar.gz
|
||||||
|
557 wget https://github.com/OpenLightingProject/artnet-examples/releases/download/0.3.13/artnet-examples-0.3.13.tar.gz
|
||||||
|
does not work with arduino (need reply on dmx node inquiry)
|
||||||
|
|
||||||
|
git clone https://github.com/philchristensen/python-artnet.git
|
||||||
|
cd python-artnet/
|
||||||
|
sudo python setup.py install
|
||||||
|
artnet script all_channels_full
|
||||||
|
ImportError: No module named cement.core
|
||||||
|
sudo easy_install setuptools_git
|
||||||
|
sudo easy_install bitstring
|
||||||
|
sudo easy_install cement
|
||||||
|
artnet script all_channels_full
|
||||||
|
# all lights are on, wow
|
||||||
|
artnet script all_channels_blackout
|
||||||
|
# all lights are off
|
||||||
|
sudo easy_install pip
|
||||||
|
sudo pip install pyyaml
|
||||||
|
|
|
@ -4,8 +4,11 @@ for i in $(ls /run/dhcp-leases/)
|
||||||
do
|
do
|
||||||
if ping -qc 1 -W 1 "$i" >/dev/null
|
if ping -qc 1 -W 1 "$i" >/dev/null
|
||||||
then
|
then
|
||||||
touch "/run/dhcp-leases/$ip"
|
if [ $(cat "/run/dhcp-leases/$i") -gt $(date --date yesterday +%s) ]
|
||||||
n=$((n+1))
|
then
|
||||||
|
touch "/run/dhcp-leases/$i"
|
||||||
|
n=$((n+1))
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
logger -t $(basename $0) "dhcp $i is not pingable anymore"
|
logger -t $(basename $0) "dhcp $i is not pingable anymore"
|
||||||
if [ $(stat -c %Y /run/dhcp-leases/$i) -lt $(date --date "1 hour ago" +%s) ]
|
if [ $(stat -c %Y /run/dhcp-leases/$i) -lt $(date --date "1 hour ago" +%s) ]
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# changes level2 state by the state of the main door
|
||||||
|
# i.e. people have to leave it open to keep status open
|
||||||
|
if [ "$1" = "pushed" ] &&
|
||||||
|
[ "$(cat /run/spacestatus)" = "open" ]
|
||||||
|
then
|
||||||
|
FORM_action="close" /root/pidor/webserver/cgi-bin/pidor.sh
|
||||||
|
/root/pidor/scripts/upd_status.sh
|
||||||
|
fi
|
||||||
|
if [ "$1" = "released" ] && # if switch was released (the door opened, or someone is playing with the switch)
|
||||||
|
[ "$(cat /run/spacestatus)" = "closed" ] # the status was closed
|
||||||
|
# [ $(stat -c "%Y" /run/spacestatus) -lt $(date --date "1 hour ago" +%s) ] # since at least one hour
|
||||||
|
then
|
||||||
|
FORM_action="open" /root/pidor/webserver/cgi-bin/pidor.sh
|
||||||
|
/root/pidor/scripts/upd_status.sh
|
||||||
|
# echo "intrusion detected: space was closed since some time and locked, but now is still closed but unlocked" | wall
|
||||||
|
# logger -t $(basename $0) "INTRUSION ALARM. door was opened while status is closed"
|
||||||
|
fi
|
|
@ -1,8 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
if [ "$1" = "released" ] && # if switch was released (the door opened, or someone is playing with the switch)
|
|
||||||
[ "$(cat /run/spacestatus)" = "closed" ] && # the status was closed
|
|
||||||
[ $(stat -c "%Y" /run/spacestatus) -lt $(date --date "1 hour ago" +%s) ] # since at least one hour
|
|
||||||
then
|
|
||||||
echo "intrusion detected: space was closed since some time and locked, but now is still closed but unlocked" | wall
|
|
||||||
logger -t $(basename $0) "INTRUSION ALARM. door was opened while status is closed"
|
|
||||||
fi
|
|
|
@ -2,10 +2,11 @@
|
||||||
# called by upd_status and lockbutton, so that whatever
|
# called by upd_status and lockbutton, so that whatever
|
||||||
# sequence is used, the lights go off
|
# sequence is used, the lights go off
|
||||||
if ( [ "$1" = "pushed" ] || [ "$1" = "closed" ] ) &&
|
if ( [ "$1" = "pushed" ] || [ "$1" = "closed" ] ) &&
|
||||||
[ "$(cat /run/spacestatus)" = "closed" ] &&
|
# [ "$(cat /run/spacestatus)" = "closed" ] &&
|
||||||
[ "$(cat /run/doorlockbutton)" = "pushed" ] &&
|
[ "$(cat /run/doorlockbutton)" = "pushed" ] &&
|
||||||
( [ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "5 minutes ago" +%s)" ] ||
|
# ( [ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "5 minutes ago" +%s)" ] ||
|
||||||
[ "$(stat -c %Y /run/doorlockbutton)" -gt "$(date --date "5 minutes ago" +%s)" ] )
|
# [ "$(stat -c %Y /run/doorlockbutton)" -gt "$(date --date "5 minutes ago" +%s)" ] )
|
||||||
|
[ "$(stat -c %Y /run/doorlockbutton)" -gt "$(date --date "5 minutes ago" +%s)" ]
|
||||||
then
|
then
|
||||||
logger -t $(basename $0) "switching all lights off"
|
logger -t $(basename $0) "switching all lights off"
|
||||||
for i in {1..16}
|
for i in {1..16}
|
||||||
|
@ -15,10 +16,11 @@ then
|
||||||
logger -t $(basename $0) "all lights should be off now"
|
logger -t $(basename $0) "all lights should be off now"
|
||||||
fi
|
fi
|
||||||
if [ "$1" = "released" ] && # the door has been opened
|
if [ "$1" = "released" ] && # the door has been opened
|
||||||
[ "$(cat /run/spacestatus)" = "open" ] && # status is open
|
# [ "$(cat /run/spacestatus)" = "open" ] && # status is open
|
||||||
[ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "50 minutes ago" +%s)" ] && # since less than 5 minutes
|
# [ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "50 minutes ago" +%s)" ] && # since less than 5 minutes
|
||||||
( [ "$(date +%H)" -gt 18 ] || [ "$(date +%H)" -lt 8 ] )
|
( [ "$(date +%s)" -gt $(/root/pidor/scripts/sunset) ] || [ "$(date +%s)" -lt $(/root/pidor/scripts/sunrise) ] )
|
||||||
then
|
then
|
||||||
|
#( [ "$(date +%H)" -gt 18 ] || [ "$(date +%H)" -lt 8 ] )
|
||||||
logger -t $(basename $0) "switching some lights on"
|
logger -t $(basename $0) "switching some lights on"
|
||||||
/usr/local/bin/433send 2 1A 1 1 #on
|
/usr/local/bin/433send 2 1A 1 1 #on
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -0,0 +1,231 @@
|
||||||
|
#!/usr/bin/awk -f
|
||||||
|
# converted from C to awk by gunstick@syn2cat.lu 2014/10/02
|
||||||
|
# based on http://www.sci.fi/~benefon/rscalc_cpp.html
|
||||||
|
# ugly C code gives ugly awk code, don't blame me
|
||||||
|
# input is like this: 49.5916 6.1407 2
|
||||||
|
|
||||||
|
# gawk program calculating the sunrise and sunset for
|
||||||
|
# the current date and a fixed location(latitude,longitude)
|
||||||
|
# Note, twilight calculation gives insufficient accuracy of results
|
||||||
|
# Jarmo Lammi 1999 - 2001
|
||||||
|
# Last update July 21st, 2001
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
|
||||||
|
pi = 3.14159;
|
||||||
|
degs = 0.0;
|
||||||
|
rads = 0.0;
|
||||||
|
|
||||||
|
L=g=daylen=0.0
|
||||||
|
SunDia = 0.53; # Sunradius degrees
|
||||||
|
|
||||||
|
AirRefr = 34.0 / 60.0; # athmospheric refraction degrees
|
||||||
|
}
|
||||||
|
# Get the days to J2000
|
||||||
|
# h is UT in decimal hours
|
||||||
|
# FNday only works between 1901 to 2099 - see Meeus chapter 7
|
||||||
|
|
||||||
|
function FNday (y, m, d, h) {
|
||||||
|
luku = int(-7 * (y + (m + 9)/12)/4 + 275*m/9 + d);
|
||||||
|
# type casting necessary on PC DOS and TClite to avoid overflow
|
||||||
|
luku+= y*367;
|
||||||
|
return luku - 730531.5 + h/24.0;
|
||||||
|
};
|
||||||
|
|
||||||
|
# the function below returns an angle in the range
|
||||||
|
# 0 to 2*pi
|
||||||
|
|
||||||
|
function FNrange ( x) {
|
||||||
|
b = 0.5*x / pi;
|
||||||
|
a = 2.0*pi * (b - int(b));
|
||||||
|
if (a < 0) a = 2.0*pi + a;
|
||||||
|
return a;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Calculating the hourangle
|
||||||
|
#
|
||||||
|
function f0( lat, declin) {
|
||||||
|
fo=dfo=0.0;
|
||||||
|
# Correction: different sign at S HS
|
||||||
|
dfo = rads*(0.5*SunDia + AirRefr)
|
||||||
|
if (lat < 0.0) { dfo = -dfo };
|
||||||
|
fo = tan(declin + dfo) * tan(lat*rads);
|
||||||
|
if (fo>0.99999) { fo=1.0 }; # to avoid overflow //
|
||||||
|
fo = asin(fo) + pi/2.0;
|
||||||
|
return fo;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Calculating the hourangle for twilight times
|
||||||
|
#
|
||||||
|
function f1(lat, declin) {
|
||||||
|
fi=df1=0.0;
|
||||||
|
# Correction: different sign at S HS
|
||||||
|
df1 = rads * 6.0; if (lat < 0.0) { df1 = -df1 };
|
||||||
|
fi = tan(declin + df1) * tan(lat*rads);
|
||||||
|
if (fi>0.99999) { fi=1.0 } ; # to avoid overflow //
|
||||||
|
fi = asin(fi) + pi/2.0;
|
||||||
|
return fi;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
# Find the ecliptic longitude of the Sun
|
||||||
|
|
||||||
|
function FNsun (d) {
|
||||||
|
|
||||||
|
# mean longitude of the Sun
|
||||||
|
|
||||||
|
L = FNrange(280.461 * rads + .9856474 * rads * d);
|
||||||
|
|
||||||
|
# mean anomaly of the Sun
|
||||||
|
|
||||||
|
g = FNrange(357.528 * rads + .9856003 * rads * d);
|
||||||
|
|
||||||
|
# Ecliptic longitude of the Sun
|
||||||
|
|
||||||
|
return FNrange(L + 1.915 * rads * sin(g) + .02 * rads * sin(2 * g));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
# Display decimal hours in hours and minutes
|
||||||
|
function showhrmn( dhr) {
|
||||||
|
hr=mn=0;
|
||||||
|
hr= int(dhr);
|
||||||
|
mn = int((dhr - hr)*60);
|
||||||
|
|
||||||
|
printf("%0d:%0d",hr,mn);
|
||||||
|
};
|
||||||
|
|
||||||
|
# awk misses some trigo functions
|
||||||
|
function asin(x) { return atan2(x, sqrt(1-x*x)) }
|
||||||
|
function tan(x) { return sin(x)/cos(x) }
|
||||||
|
{
|
||||||
|
|
||||||
|
y=m=day=h=latit=longit=0.0
|
||||||
|
inlat=inlon=intz=0
|
||||||
|
tzone=d=lambda=0
|
||||||
|
obliq=alpha=delta=LL=equation=ha=hb=twx=0
|
||||||
|
twam=altmax=noont=settm=riset=twpm=0
|
||||||
|
sekunnit=0;
|
||||||
|
tm =0;
|
||||||
|
|
||||||
|
degs = 180.0/pi;
|
||||||
|
rads = pi/180.0;
|
||||||
|
# get the date and time from the user
|
||||||
|
# read system date and extract the year
|
||||||
|
|
||||||
|
# First get time **/
|
||||||
|
sekunnit=systime();
|
||||||
|
|
||||||
|
# Next get localtime **/
|
||||||
|
|
||||||
|
#p=localtime(&sekunnit);
|
||||||
|
|
||||||
|
y = strftime("%Y",sekunnit) # p->tm_year;
|
||||||
|
# this is Y2K compliant method
|
||||||
|
#y+= 1900;
|
||||||
|
m= strftime("%m",sekunnit) #m = p->tm_mon + 1;
|
||||||
|
|
||||||
|
|
||||||
|
day=strftime("%d",sekunnit) # day = p->tm_mday;
|
||||||
|
|
||||||
|
h = 12;
|
||||||
|
|
||||||
|
printf("year %4d month %2d\n",y,m);
|
||||||
|
printf("Input latitude, longitude [and timezone]\n");
|
||||||
|
#scanf("%f", &inlat); scanf("%f", &inlon);
|
||||||
|
#scanf("%f", &intz);
|
||||||
|
inlat=$1 ; inlon=$2
|
||||||
|
if($3 != "") {
|
||||||
|
intz=$3
|
||||||
|
} else { # guess the timezone
|
||||||
|
intz=(systime()-mktime(strftime("%Y %m %d %H %M %S",systime(),1)))/3600
|
||||||
|
}
|
||||||
|
latit = inlat; longit = inlon;
|
||||||
|
tzone = intz;
|
||||||
|
|
||||||
|
# testing
|
||||||
|
# m=6; day=10;
|
||||||
|
|
||||||
|
|
||||||
|
d = FNday(y, m, day, h);
|
||||||
|
|
||||||
|
# Use FNsun to find the ecliptic longitude of the
|
||||||
|
# Sun
|
||||||
|
|
||||||
|
lambda = FNsun(d);
|
||||||
|
|
||||||
|
# Obliquity of the ecliptic
|
||||||
|
|
||||||
|
obliq = 23.439 * rads - .0000004 * rads * d;
|
||||||
|
|
||||||
|
# Find the RA and DEC of the Sun
|
||||||
|
|
||||||
|
alpha = atan2(cos(obliq) * sin(lambda), cos(lambda));
|
||||||
|
delta = asin(sin(obliq) * sin(lambda));
|
||||||
|
|
||||||
|
# Find the Equation of Time
|
||||||
|
# in minutes
|
||||||
|
# Correction suggested by David Smith
|
||||||
|
LL = L - alpha;
|
||||||
|
if (L < pi) { LL += 2.0*pi } ;
|
||||||
|
equation = 1440.0 * (1.0 - LL / pi/2.0);
|
||||||
|
ha = f0(latit,delta);
|
||||||
|
hb = f1(latit,delta);
|
||||||
|
twx = hb - ha; # length of twilight in radians
|
||||||
|
twx = 12.0*twx/pi; # length of twilight in hours
|
||||||
|
printf "ha= %.2f hb= %.2f \n",ha,hb ;
|
||||||
|
# Conversion of angle to hours and minutes //
|
||||||
|
daylen = degs*ha/7.5;
|
||||||
|
if (daylen<0.0001) {daylen = 0.0;}
|
||||||
|
# arctic winter //
|
||||||
|
|
||||||
|
riset = 12.0 - 12.0 * ha/pi + tzone - longit/15.0 + equation/60.0;
|
||||||
|
settm = 12.0 + 12.0 * ha/pi + tzone - longit/15.0 + equation/60.0;
|
||||||
|
noont = riset + 12.0 * ha/pi;
|
||||||
|
altmax = 90.0 + delta * degs - latit;
|
||||||
|
# Correction for S HS suggested by David Smith
|
||||||
|
# to express altitude as degrees from the N horizon
|
||||||
|
if (latit < delta * degs) altmax = 180.0 - altmax;
|
||||||
|
|
||||||
|
twam = riset - twx; # morning twilight begin
|
||||||
|
twpm = settm + twx; # evening twilight end
|
||||||
|
|
||||||
|
if (riset > 24.0) riset-= 24.0;
|
||||||
|
if (settm > 24.0) settm-= 24.0;
|
||||||
|
|
||||||
|
print "\n sunrise and set";
|
||||||
|
print "===============";
|
||||||
|
|
||||||
|
printf " year : %d \n",y ;
|
||||||
|
printf " month : %d \n",m ;
|
||||||
|
printf " day : %d \n\n",day ;
|
||||||
|
printf "Days since Y2K : %d \n",d;
|
||||||
|
|
||||||
|
printf "Latitude : %3.1f, longitude: %3.1f, timezone: %3.1f \n",latit,longit,tzone ;
|
||||||
|
printf "Declination : %.2f \n",delta * degs ;
|
||||||
|
printf "Daylength : " ; showhrmn(daylen); printf " hours \n" ;
|
||||||
|
print ""
|
||||||
|
printf "Civil twilight: " ;
|
||||||
|
showhrmn(twam);
|
||||||
|
print ""
|
||||||
|
printf "Sunrise : " ;
|
||||||
|
showhrmn(riset);
|
||||||
|
printf " %d",mktime(strftime("%Y %m %d 00 00 00"))+int(riset*3600)
|
||||||
|
print ""
|
||||||
|
|
||||||
|
printf "Sun altitude " ;
|
||||||
|
# Amendment by D. Smith
|
||||||
|
printf " %.2f degr",altmax ;
|
||||||
|
printf latit>=0.0 ? " South" : " North" ;
|
||||||
|
printf " at noontime " ; showhrmn(noont); ;
|
||||||
|
print ""
|
||||||
|
printf "Sunset : " ;
|
||||||
|
showhrmn(settm);
|
||||||
|
printf " %d",mktime(strftime("%Y %m %d 00 00 00"))+int(settm*3600)
|
||||||
|
print ""
|
||||||
|
printf "Civil twilight: " ;
|
||||||
|
showhrmn(twpm); print "" ;
|
||||||
|
print ""
|
||||||
|
|
||||||
|
#return 0;
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/bash
|
||||||
|
echo "49.5916 6.1407" | $(dirname "$0")/rscalc.awk |
|
||||||
|
awk '/^Sunrise/{print $NF}'
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/bash
|
||||||
|
echo "49.5916 6.1407" | $(dirname "$0")/rscalc.awk |
|
||||||
|
awk '/^Sunset/{print $NF}'
|
|
@ -2,10 +2,11 @@
|
||||||
# called by upd_status and lockbutton, so that whatever
|
# called by upd_status and lockbutton, so that whatever
|
||||||
# sequence is used, the lights go off
|
# sequence is used, the lights go off
|
||||||
if ( [ "$1" = "pushed" ] || [ "$1" = "closed" ] ) &&
|
if ( [ "$1" = "pushed" ] || [ "$1" = "closed" ] ) &&
|
||||||
[ "$(cat /run/spacestatus)" = "closed" ] &&
|
# [ "$(cat /run/spacestatus)" = "closed" ] &&
|
||||||
[ "$(cat /run/doorlockbutton)" = "pushed" ] &&
|
[ "$(cat /run/doorlockbutton)" = "pushed" ] &&
|
||||||
( [ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "5 minutes ago" +%s)" ] ||
|
# ( [ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "5 minutes ago" +%s)" ] ||
|
||||||
[ "$(stat -c %Y /run/doorlockbutton)" -gt "$(date --date "5 minutes ago" +%s)" ] )
|
# [ "$(stat -c %Y /run/doorlockbutton)" -gt "$(date --date "5 minutes ago" +%s)" ] )
|
||||||
|
[ "$(stat -c %Y /run/doorlockbutton)" -gt "$(date --date "5 minutes ago" +%s)" ]
|
||||||
then
|
then
|
||||||
logger -t $(basename $0) "switching all lights off"
|
logger -t $(basename $0) "switching all lights off"
|
||||||
for i in {1..16}
|
for i in {1..16}
|
||||||
|
@ -15,10 +16,11 @@ then
|
||||||
logger -t $(basename $0) "all lights should be off now"
|
logger -t $(basename $0) "all lights should be off now"
|
||||||
fi
|
fi
|
||||||
if [ "$1" = "released" ] && # the door has been opened
|
if [ "$1" = "released" ] && # the door has been opened
|
||||||
[ "$(cat /run/spacestatus)" = "open" ] && # status is open
|
# [ "$(cat /run/spacestatus)" = "open" ] && # status is open
|
||||||
[ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "50 minutes ago" +%s)" ] && # since less than 5 minutes
|
# [ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "50 minutes ago" +%s)" ] && # since less than 5 minutes
|
||||||
( [ "$(date +%H)" -gt 18 ] || [ "$(date +%H)" -lt 8 ] )
|
( [ "$(date +%s)" -gt $(/root/pidor/scripts/sunset) ] || [ "$(date +%s)" -lt $(/root/pidor/scripts/sunrise) ] )
|
||||||
then
|
then
|
||||||
|
#( [ "$(date +%H)" -gt 18 ] || [ "$(date +%H)" -lt 8 ] )
|
||||||
logger -t $(basename $0) "switching some lights on"
|
logger -t $(basename $0) "switching some lights on"
|
||||||
/usr/local/bin/433send 2 1A 1 1 #on
|
/usr/local/bin/433send 2 1A 1 1 #on
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue