inital dump
This commit is contained in:
2
Software/3G Modem/Datenrate_Minumum.txt
Normal file
2
Software/3G Modem/Datenrate_Minumum.txt
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
5MB
|
||||
Binary file not shown.
BIN
Software/3G Modem/Sakis3G wiki.pdf
Normal file
BIN
Software/3G Modem/Sakis3G wiki.pdf
Normal file
Binary file not shown.
23
Software/3G Modem/Sakis3G/Installation.txt
Normal file
23
Software/3G Modem/Sakis3G/Installation.txt
Normal file
@ -0,0 +1,23 @@
|
||||
wget http://raspberry-at-home.com/files/sakis3g.tar.gz
|
||||
|
||||
sudo mkdir /usr/bin/modem3g
|
||||
|
||||
sudo chmod 777 /usr/bin/modem3g
|
||||
|
||||
sudo cp sakis3g.tar.gz /usr/bin/modem3g
|
||||
|
||||
cd /usr/bin/modem3g
|
||||
|
||||
sudo tar -zxvf sakis3g.tar.gz
|
||||
|
||||
sudo chmod +x sakis3g
|
||||
|
||||
sudo ./sakis3g --interactive
|
||||
|
||||
----------------
|
||||
1. 3G Verbinden
|
||||
2. <20>ber USB
|
||||
3. Huawei Mobile
|
||||
4. Interface 0
|
||||
-----------------
|
||||
|
||||
8502
Software/3G Modem/Sakis3G/sakis3g.sh
Normal file
8502
Software/3G Modem/Sakis3G/sakis3g.sh
Normal file
File diff suppressed because it is too large
Load Diff
BIN
Software/3G Modem/Sakis3G/sakis3g.tar.gz
Normal file
BIN
Software/3G Modem/Sakis3G/sakis3g.tar.gz
Normal file
Binary file not shown.
3
Software/3G Modem/Speedtest.txt
Normal file
3
Software/3G Modem/Speedtest.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Salmenkopf: Download: 4,52Mbit/s Upload: 3,10Mbit/s
|
||||
|
||||
Kirchkopf: Download: 2,40Mbit/s Upload: 3,00Mbit/s
|
||||
BIN
Software/3G Modem/USB Modeswitcher/.Installation.txt.kate-swp
Normal file
BIN
Software/3G Modem/USB Modeswitcher/.Installation.txt.kate-swp
Normal file
Binary file not shown.
8
Software/3G Modem/USB Modeswitcher/Installation.txt
Normal file
8
Software/3G Modem/USB Modeswitcher/Installation.txt
Normal file
@ -0,0 +1,8 @@
|
||||
sudo apt-get install ppp usb-modeswitch
|
||||
|
||||
|
||||
sudo usb_modeswitch -I -v 12d1 -p 1446 -V 12d1 -P 1446 -M '55534243123456780000000000000011062000000100000000000000000000'
|
||||
|
||||
|
||||
|
||||
sudo usb_modeswitch -v 12d1 -p 14fe -M '55534243123456780000000000000011062000000100000000000000000000'
|
||||
BIN
Software/3G Modem/USB Modeswitcher/libusb-1.0.9.tar.bz2
Normal file
BIN
Software/3G Modem/USB Modeswitcher/libusb-1.0.9.tar.bz2
Normal file
Binary file not shown.
BIN
Software/3G Modem/USB Modeswitcher/usb-modeswitch-2.5.0.tar.bz2
Normal file
BIN
Software/3G Modem/USB Modeswitcher/usb-modeswitch-2.5.0.tar.bz2
Normal file
Binary file not shown.
4
Software/3G Modem/modem cron 6 Stunden.txt
Normal file
4
Software/3G Modem/modem cron 6 Stunden.txt
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
|
||||
|
||||
0 */6 * * * sudo /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
25
Software/3G Modem/rc.local
Normal file
25
Software/3G Modem/rc.local
Normal file
@ -0,0 +1,25 @@
|
||||
#!/bin/sh -e
|
||||
# V0.1 17.03.2017
|
||||
# rc.local
|
||||
#
|
||||
# This script is executed at the end of each multiuser runlevel.
|
||||
# Make sure that the script will "exit 0" on success or any other
|
||||
# value on error.
|
||||
#
|
||||
# In order to enable or disable this script just change the execution
|
||||
# bits.
|
||||
#
|
||||
# By default this script does nothing.
|
||||
|
||||
printf "%sStarting 3G Modem%s /n"
|
||||
|
||||
sudo /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
|
||||
# Print the IP address
|
||||
_IP=$(hostname -I) || true
|
||||
if [ "$_IP" ]; then
|
||||
printf "My IP address is %s\n" "$_IP"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
60
Software/3G Modem/sakis reconnect stuff.txt
Normal file
60
Software/3G Modem/sakis reconnect stuff.txt
Normal file
@ -0,0 +1,60 @@
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g] disconnected')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection hopefully successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g] disconnected')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection hopefully successful')
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
16
Software/3G Modem/sakis.txt
Normal file
16
Software/3G Modem/sakis.txt
Normal file
@ -0,0 +1,16 @@
|
||||
/usr/bin/modem3g/sakis3g --interactive
|
||||
|
||||
|
||||
/usr/bin/modem3g/sakis3g connect --console APN='internet.eplus.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
|
||||
/usr/bin/modem3g/sakis3g info
|
||||
|
||||
/usr/bin/modem3g/sakis3g status
|
||||
|
||||
/usr/bin/modem3g/sakis3g disconnect
|
||||
|
||||
|
||||
|
||||
O2/WinSim/Drillisch/Handyvertag.de/AldiTalk APN: internet.eplus.de
|
||||
|
||||
vodafone APN: web.vodafone.de
|
||||
12
Software/Backup_CMD.txt
Normal file
12
Software/Backup_CMD.txt
Normal file
@ -0,0 +1,12 @@
|
||||
ls | grep Jun | mv /home/hendrik/ftp/files/camera03/Position02/2018/06_June/
|
||||
|
||||
|
||||
ls | grep Jun -exec mv {} /home/hendrik/ftp/files/camera03/Position02/2018/06_June/ \;
|
||||
|
||||
|
||||
find -maxdepth 1 -mtime +0 -type f -exec ls -l {} \;
|
||||
|
||||
|
||||
/home/hendrik/ftp/files/camera01/latest/
|
||||
|
||||
find -maxdepth 1 -mtime +0 -type f -exec mv {} /home/hendrik/ftp/files/camera01/2018/06_June/ \;
|
||||
16
Software/Betriebsspannung einlesen/Betriebsspannung.py
Normal file
16
Software/Betriebsspannung einlesen/Betriebsspannung.py
Normal file
@ -0,0 +1,16 @@
|
||||
from spidev import SpiDev
|
||||
|
||||
spi = SpiDev()
|
||||
spi.open(0,0)
|
||||
|
||||
def read(channel = 0):
|
||||
adc = spi.xfer2([1, (8 + channel) << 4, 0])
|
||||
data = ((adc[1] & 3) << 8) + adc[2]
|
||||
return data
|
||||
|
||||
value = read(channel = 0)
|
||||
|
||||
print("Anliegende Spannung: %.2f" % ((value / 1023.0 * 3.3)*6.62) )
|
||||
|
||||
|
||||
|
||||
4
Software/Betriebsspannung einlesen/Spannungsteiler
Normal file
4
Software/Betriebsspannung einlesen/Spannungsteiler
Normal file
@ -0,0 +1,4 @@
|
||||
[Desktop Entry]
|
||||
Icon=text-html
|
||||
Type=Link
|
||||
URL[$e]=http://www.electronicsplanet.ch/Spannungsteiler/spannungsteiler-berechnen.php
|
||||
1650
Software/Betriebsspannung einlesen/Thread-12v-batterieueberwachung
Normal file
1650
Software/Betriebsspannung einlesen/Thread-12v-batterieueberwachung
Normal file
File diff suppressed because it is too large
Load Diff
4
Software/Betriebsspannung einlesen/Widerstände
Normal file
4
Software/Betriebsspannung einlesen/Widerstände
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
R1 = 1k
|
||||
R2 = 186
|
||||
Vin = 21V
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
BIN
Software/Datenvolumen.ods
Normal file
BIN
Software/Datenvolumen.ods
Normal file
Binary file not shown.
5
Software/FTP/FTP login.txt
Normal file
5
Software/FTP/FTP login.txt
Normal file
@ -0,0 +1,5 @@
|
||||
User: uploader
|
||||
pw: de8f57022a3909151bd1
|
||||
|
||||
User: brunner
|
||||
pw: bb1753f214940e04b
|
||||
24
Software/FTP/Samba.txt
Normal file
24
Software/FTP/Samba.txt
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
|
||||
|
||||
|
||||
user: uploader
|
||||
|
||||
pw: klausi7T1w
|
||||
|
||||
|
||||
usermod -aG ftp-uploader www-data
|
||||
|
||||
|
||||
|
||||
[ftp]
|
||||
path = /home/hendrik/ftp/files
|
||||
valid users = www-data
|
||||
read list = www-data
|
||||
read only = Yes
|
||||
create mask = 0664
|
||||
directory mask = 0754
|
||||
|
||||
|
||||
|
||||
chown -R ftp-user:ftp-user /home/hendrik/ftp
|
||||
BIN
Software/FTP/Test_Verzeichnis.tar.zst
Normal file
BIN
Software/FTP/Test_Verzeichnis.tar.zst
Normal file
Binary file not shown.
8
Software/FTP/ftp_setup.txt
Normal file
8
Software/FTP/ftp_setup.txt
Normal file
@ -0,0 +1,8 @@
|
||||
1) mkdir /home/ftp
|
||||
2) sudo useradd -g ftp-uploader -d /home/ftp uploader
|
||||
passwd uploader
|
||||
3) sudo chown uploader:ftp-user /home/ftp
|
||||
4) sudo useradd -g ftp-user -d /home/ftp client
|
||||
passwd client
|
||||
5) sudo chown -R uploader:ftp-user /home/ftp
|
||||
6) sudo chmod -R 754 /home/ftp
|
||||
30
Software/Postpoduktion/Server_TLC_PostSW.txt
Normal file
30
Software/Postpoduktion/Server_TLC_PostSW.txt
Normal file
@ -0,0 +1,30 @@
|
||||
nohup java -jar tlc_post.jar -log -m createDB -r /home/hendrik/ftp/files/camera01/ -p /home/hendrik/tlc_post/TLC01/ -i counter -n 140780 >> TLC01/log01.txt
|
||||
|
||||
nohup java -jar tlc_post.jar -log -m createDB -r /home/hendrik/ftp/files/camera02/ -p /home/hendrik/tlc_post/TLC02/ -i counter -n 135414 >> TLC02/log02.txt
|
||||
|
||||
java -jar tlc_post.jar -log -m createDB -r /home/hendrik/ftp/files/camera04/ -p /home/hendrik/tlc_post/TLC04/ -i counter -n 11935 & >> TLC04/log04.txt
|
||||
|
||||
|
||||
printf "TLC01: " && tail -n 1 ./TLC01/log01.txt && printf "TLC02: " && tail -n 1 ./TLC02/log02.txt && printf "TLC04: " && tail -n 1 ./TLC04/log04.txt
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
while true; do
|
||||
|
||||
clear
|
||||
|
||||
printf "TLC01: " && tail -n 1 ./TLC01/log01.txt && printf "TLC02: " && tail -n 1 ./TLC02/log02.txt && printf "TLC04: " && tail -n 1 ./TLC04/log04.txt
|
||||
|
||||
printf "\n"
|
||||
|
||||
sleep 1
|
||||
|
||||
done
|
||||
|
||||
|
||||
|
||||
7
Software/Postpoduktion/brunner_cmd.txt
Normal file
7
Software/Postpoduktion/brunner_cmd.txt
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
-log -m createDB -r /home/hendrik/FTP/camera01/ -p /home/hendrik/Schreibtisch/TLC01/ -i counter -n 140780
|
||||
|
||||
-log -m createDB -r /home/hendrik/FTP/camera02/ -p /home/hendrik/Schreibtisch/TLC02/ -i counter -n 135414
|
||||
|
||||
-log -m createDB -r /home/hendrik/FTP/camera04/ -p /home/hendrik/Schreibtisch/TLC04/ -i counter -n 11935
|
||||
17
Software/RTC/Installation.txt
Normal file
17
Software/RTC/Installation.txt
Normal file
@ -0,0 +1,17 @@
|
||||
apt-get install i2c-tools
|
||||
|
||||
i2cdetect -y 1
|
||||
|
||||
modprobe rtc-ds1307
|
||||
|
||||
bash
|
||||
|
||||
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
|
||||
|
||||
exit
|
||||
|
||||
zeit mit internet syncroniseiren
|
||||
|
||||
hwclock -w
|
||||
|
||||
nano /etc/modules und rtc-ds1307 hinzufügen
|
||||
32
Software/RTC/RTC_Bug_fix.txt
Normal file
32
Software/RTC/RTC_Bug_fix.txt
Normal file
@ -0,0 +1,32 @@
|
||||
apt-get install i2c-tools
|
||||
|
||||
i2cdetect -y 1
|
||||
|
||||
modprobe rtc-ds1307
|
||||
|
||||
bash
|
||||
|
||||
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
|
||||
|
||||
exit
|
||||
|
||||
zeit mit internet synchronisieren
|
||||
|
||||
hwclock -w
|
||||
|
||||
nano /etc/modules und rtc-ds1307 hinzufügen
|
||||
|
||||
|
||||
nano /etc/rc.local
|
||||
----------------------------------------------------
|
||||
|
||||
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
|
||||
hwclock -s
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
|
||||
Zusatz:
|
||||
|
||||
date -s "29 AUG 1997 13:00:00"
|
||||
|
||||
1
Software/SchärfeTest/test.sh
Normal file
1
Software/SchärfeTest/test.sh
Normal file
@ -0,0 +1 @@
|
||||
raspivid -t -0
|
||||
1
Software/SchärfeTest/zoom.sh
Normal file
1
Software/SchärfeTest/zoom.sh
Normal file
@ -0,0 +1 @@
|
||||
raspivid -t -0 -roi 0.1,0.2,0.3,0.4
|
||||
6
Software/Speedtest API/Install.txt
Normal file
6
Software/Speedtest API/Install.txt
Normal file
@ -0,0 +1,6 @@
|
||||
wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
|
||||
|
||||
|
||||
chmod +x speedtest-cli
|
||||
|
||||
./speedtest-cli
|
||||
1430
Software/Speedtest API/speedtest.py
Normal file
1430
Software/Speedtest API/speedtest.py
Normal file
File diff suppressed because it is too large
Load Diff
9
Software/Temperatur/TempGrenzwerte.txt
Normal file
9
Software/Temperatur/TempGrenzwerte.txt
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
<= -5<>C --> Critical Coold
|
||||
|
||||
<= 5<>C --> Warning Coold
|
||||
|
||||
>= 45<34>C --> Warning Hot
|
||||
|
||||
>= 50<35>C --> Critical Hot
|
||||
11
Software/Temperatur/TempRead.txt
Normal file
11
Software/Temperatur/TempRead.txt
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
vcgencmd measure_temp
|
||||
|
||||
|
||||
import os
|
||||
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
84
Software/Vorlagen/Dokumentation_Produce_V03.txt
Normal file
84
Software/Vorlagen/Dokumentation_Produce_V03.txt
Normal file
@ -0,0 +1,84 @@
|
||||
Version 0.3
|
||||
Stand: 23.03.2017
|
||||
----------------------------------------------------------------------------
|
||||
User: pi PW: qaws
|
||||
User: root PW: qaws
|
||||
---------------------------------------------------------------------------
|
||||
1) neustes Rasbian Lite Image auf SD-Card schreiben
|
||||
|
||||
2) per UART SSH aktivieren User: pi PW: raspberry
|
||||
|
||||
3) per SSH einloggen mit User: pi PW: raspberry
|
||||
3.1) Root-Nutzer freigenen:
|
||||
3.1.1) --> PW: qaws
|
||||
3.1.2) sudo nano /etc/ssh/sshd_config <-- die Berechtigung für rootssh setzten, PermitRootLogin yes
|
||||
3.1.3) sudo reboot
|
||||
|
||||
4) mit root einloggen:
|
||||
4.1) raspi-config
|
||||
4.1.1) Change User Password --> User: pi PW: qaws
|
||||
4.1.2) Boot Options --> CLI ohne auto loggin
|
||||
4.1.3) Localisation Options
|
||||
4.1.3.1) Change Locale --> DE@de-UTF8
|
||||
4.1.3.2) Change Timezone --> Berlin
|
||||
4.1.4) Interfacing Options
|
||||
4.1.4.1) enable Camera
|
||||
4.1.5) reboot
|
||||
|
||||
5) mit root einloggen
|
||||
5.1) hostname -b TLCXX
|
||||
5.2) apt-get update
|
||||
5.3) apt-get upgrade
|
||||
5.4) apt-get install watchdog ppp usb-modeswitch weavedconnectd python3-picamera usbmount screenfetch
|
||||
5.5) Sakis
|
||||
5.5.1) wget http://raspberry-at-home.com/files/sakis3g.tar.gz
|
||||
5.5.2) mkdir /usr/bin/modem3g
|
||||
5.5.3) chmod 777 /usr/bin/modem3g
|
||||
5.5.4) cp sakis3g.tar.gz /usr/bin/modem3g
|
||||
5.5.5) cd /usr/bin/modem3g
|
||||
5.5.6) tar -zxvf sakis3g.tar.gz
|
||||
5.5.7) chmod +x sakis3g
|
||||
5.5.8) cd /root
|
||||
5.6) Speedtest CLI
|
||||
5.6.1) wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
|
||||
5.6.2) chmod +x speedtest-cli
|
||||
5.7) Swap deaktivieren
|
||||
5.7.1) dphys-swapfile swapoff
|
||||
5.7.2) systemctl disable dphys-swapfile
|
||||
5.7.3) apt-get purge dphys-swapfile
|
||||
5.8) Watchdog
|
||||
5.8.1) modprobe bcm2835_wdt
|
||||
5.8.2) echo "bcm2835_wdt" | tee -a /etc/modules
|
||||
5.8.3) nano /etc/watchdog.conf
|
||||
5.8.3.1) # entfernen bei: watchdog-device = /dev/watchdog UND max-load-1 = 24
|
||||
5.8.4) nano /lib/systemd/system/watchdog.service
|
||||
5.8.4.1) ergänzen um WantedBy=multi-user.target
|
||||
5.8.5) systemctl enable watchdog.service
|
||||
5.9) USB Mount
|
||||
5.9.1) nano /etc/usbmount/usbmount.conf
|
||||
5.9.2) FS_MOUNTOPTIONS="-fstype=vfat,gid=users,dmask=0007,fmask=0117" einfügen
|
||||
|
||||
Edit /lib/systemd/system/systemd-udevd.service and change the line
|
||||
MountFlags=slave
|
||||
to
|
||||
MountFlags=shared
|
||||
then reboot
|
||||
|
||||
6) mit WinSCP als root einloggen
|
||||
6.1) zoom.sh und test.sh in /root kopieren
|
||||
6.2) chmod +x zoom.sh
|
||||
6.3) chmod +x test.sh
|
||||
6.4) camera.py und config.txt in /home/pi/ kopieren <-- gehört user pi
|
||||
6.5) /home/pi/picture_Number.txt erstellen und 0 eintragen
|
||||
6.6) camera_boot.log erstellen
|
||||
|
||||
7) Auto Start
|
||||
7.1) crontab -e
|
||||
7.2) @reboot /usr/bin/python3 /home/pi/camera.py 2>&1 >> /home/pi/camera_boot.log 2>&1 einfügen
|
||||
|
||||
8) Ordner anlegen
|
||||
9.1) mkdir /media/usb/pictures
|
||||
9.2) mkdir /media/usb/log
|
||||
|
||||
|
||||
|
||||
115
Software/Vorlagen/Dokumentation_Produce_V04.txt
Normal file
115
Software/Vorlagen/Dokumentation_Produce_V04.txt
Normal file
@ -0,0 +1,115 @@
|
||||
Version 0.4
|
||||
Stand: 22.06.2018
|
||||
----------------------------------------------------------------------------
|
||||
User: pi PW: qaws
|
||||
User: root PW: qaws
|
||||
---------------------------------------------------------------------------
|
||||
1) neustes Rasbian Lite Image auf SD-Card schreiben
|
||||
|
||||
2) per UART SSH aktivieren User: pi PW: raspberry
|
||||
|
||||
3) per SSH einloggen mit User: pi PW: raspberry
|
||||
3.1) Root-Nutzer freigenen:
|
||||
3.1.1) --> PW: qaws
|
||||
3.1.2) sudo nano /etc/ssh/sshd_config <-- die Berechtigung für rootssh setzten, PermitRootLogin yes
|
||||
3.1.3) sudo nano /etc/ssh/sshd_config <-- Banner /home/pi/banner.txt
|
||||
3.1.3) sudo reboot
|
||||
|
||||
4) mit root einloggen:
|
||||
4.1) raspi-config
|
||||
4.1.1) Change User Password --> User: pi PW: qaws
|
||||
4.1.2) Boot Options --> CLI ohne auto loggin
|
||||
4.1.3) Localisation Options
|
||||
4.1.3.1) Change Locale --> DE@de-UTF8
|
||||
4.1.3.2) Change Timezone --> Berlin
|
||||
4.1.4) Interfacing Options
|
||||
4.1.4.1) enable Camera
|
||||
4.1.4.2) enable SPI
|
||||
4.1.4.3) enable I2C
|
||||
4.1.5) Expand Filesystem
|
||||
4.1.6) reboot
|
||||
|
||||
5) mit root einloggen
|
||||
5.1) hostname -b TLCXX
|
||||
5.2) apt-get update
|
||||
5.3) apt-get upgrade
|
||||
5.4) apt-get install watchdog ppp usb-modeswitch weavedconnectd python3-picamera usbmount screenfetch python3-RPi.GPIO python3-dev i2c-tools
|
||||
5.5) Sakis
|
||||
5.5.1) wget http://raspberry-at-home.com/files/sakis3g.tar.gz
|
||||
5.5.2) mkdir /usr/bin/modem3g
|
||||
5.5.3) chmod 777 /usr/bin/modem3g
|
||||
5.5.4) cp sakis3g.tar.gz /usr/bin/modem3g
|
||||
5.5.5) cd /usr/bin/modem3g
|
||||
5.5.6) tar -zxvf sakis3g.tar.gz
|
||||
5.5.7) chmod +x sakis3g
|
||||
5.5.8) cd /root
|
||||
5.6) Speedtest CLI
|
||||
5.6.1) wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
|
||||
5.6.2) chmod +x speedtest-cli
|
||||
5.7) Swap deaktivieren
|
||||
5.7.1) dphys-swapfile swapoff
|
||||
5.7.2) systemctl disable dphys-swapfile
|
||||
5.7.3) apt-get purge dphys-swapfile
|
||||
5.8) Watchdog
|
||||
5.8.1) modprobe bcm2835_wdt
|
||||
5.8.2) echo "bcm2835_wdt" | tee -a /etc/modules
|
||||
5.8.3) nano /etc/watchdog.conf
|
||||
5.8.3.1) # entfernen bei: watchdog-device = /dev/watchdog UND max-load-1 = 24
|
||||
5.8.4) nano /lib/systemd/system/watchdog.service
|
||||
5.8.4.1) ergänzen um WantedBy=multi-user.target
|
||||
5.8.5) systemctl enable watchdog.service
|
||||
5.9) USB Mount
|
||||
5.9.1) nano /etc/usbmount/usbmount.conf
|
||||
5.9.2) FS_MOUNTOPTIONS="-fstype=vfat,gid=users,dmask=0007,fmask=0117" einfügen
|
||||
5.10) SPI
|
||||
5.10.1) wget https://github.com/doceme/py-spidev/archive/master.zip
|
||||
5.10.2) unzip master.zip
|
||||
5.10.3) cd py-spidev-master
|
||||
5.10.4) python3 setup.py install
|
||||
5.10.5) cd /root/
|
||||
|
||||
6) mit WinSCP als root einloggen
|
||||
6.1) camera.py und config.txt in /home/pi/ kopieren <-- gehört user pi
|
||||
6.2) /home/pi/picture_Number.txt erstellen und 0 eintragen
|
||||
6.4) /home/pi/banner.txt kopieren
|
||||
|
||||
7) Auto Start
|
||||
nano /etc/systemd/system/TLC.service
|
||||
|
||||
############ INSERT BEGIN #################
|
||||
|
||||
[Unit]
|
||||
Description=TLC
|
||||
After=syslog.target
|
||||
|
||||
[Service]
|
||||
RestartSec=2s
|
||||
Type=simple
|
||||
User=root
|
||||
Group=root
|
||||
WorkingDirectory=/home/pi/
|
||||
ExecStart=/usr/bin/python3.4 /home/pi/camera.py
|
||||
Restart=always
|
||||
RestartSec=2s
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
############ INSERT END #################
|
||||
|
||||
systemctl enable TLC.service
|
||||
|
||||
#debug
|
||||
|
||||
journalctl -u TLC.service
|
||||
|
||||
|
||||
8) Banner
|
||||
8.1) nano /root/.profile <-- /bin/cat /home/pi/banner.txt
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
54
Software/Vorlagen/Dokumentation_Replace_V02.txt
Normal file
54
Software/Vorlagen/Dokumentation_Replace_V02.txt
Normal file
@ -0,0 +1,54 @@
|
||||
Version 0.2
|
||||
Stand: 17.03.2017
|
||||
----------------------------------------------------------------------------
|
||||
User: pi PW: qaws
|
||||
User: root PW: qaws
|
||||
---------------------------------------------------------------------------
|
||||
1) Image XXXX.img auf SD-Card schreiben
|
||||
|
||||
2) mit root einloggen per SSH
|
||||
2.1) hostname -b TLCXX
|
||||
|
||||
3) remot3.it einrichten
|
||||
3.1) weavedinstaller
|
||||
3.2) 1 - Sign on to your ...
|
||||
3.3) TLCXX <-- Name des Gerätes
|
||||
3.4) 1 - Attach/reinstall ...
|
||||
3.5) 1 - SSH on port 22
|
||||
3.6) yes
|
||||
3.7) SSH_TLCXX
|
||||
3.8) 4 - Exit
|
||||
|
||||
4) mit WinSCP als root einloggen
|
||||
4.1) aktualisieren von camera.py und config.txt in /home/pi/ kopieren <-- gehört user pi
|
||||
4.2) /home/pi/picture_Number.txt die gewünschte Nummer eintragen
|
||||
4.3) config.txt anpassen
|
||||
|
||||
5) Aufräumen
|
||||
5.1) in /root
|
||||
5.2) /media/usb
|
||||
|
||||
6) Passwörter ändern
|
||||
6.1) passwd pi
|
||||
6.1.1) das pi-PW für TLCXX
|
||||
6.2) passwd root
|
||||
6.2.1) das root-PW für TLCXX
|
||||
|
||||
7) Bei Modem-Version
|
||||
7.1) nano /etc/rc.local
|
||||
7.1.1) ergänzen um:
|
||||
|
||||
printf "%sStarting 3G Modem%s /n"
|
||||
sudo /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
|
||||
7.2) Startverzögerung
|
||||
7.2.1) crontab -e
|
||||
7.2.2) @reboot /bin/sleep 120 ; /usr/bin/python3 /home/pi/camera.py 2>&1 >> /home/pi/camera_boot.log 2>&1
|
||||
|
||||
|
||||
8) reboot
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
69
Software/Vorlagen/Dokumentation_Replace_V03.txt
Normal file
69
Software/Vorlagen/Dokumentation_Replace_V03.txt
Normal file
@ -0,0 +1,69 @@
|
||||
Version 0.3
|
||||
Stand: 22.06.2018
|
||||
----------------------------------------------------------------------------
|
||||
User: pi PW: qaws
|
||||
User: root PW: qaws
|
||||
---------------------------------------------------------------------------
|
||||
1) Image XXXX.img auf SD-Card schreiben
|
||||
|
||||
2) mit root einloggen per SSH
|
||||
2.1) hostname -b TLCXX
|
||||
2.2) nano /home/pi/banner.txt <-- TLCXX ändern
|
||||
|
||||
3) remot3.it einrichten
|
||||
3.1) weavedinstaller
|
||||
3.2) 1 - Sign on to your ...
|
||||
3.3) TLCXX <-- Name des Gerätes
|
||||
3.4) 1 - Attach/reinstall ...
|
||||
3.5) 1 - SSH on port 22
|
||||
3.6) yes
|
||||
3.7) SSH_TLCXX
|
||||
3.8) 4 - Exit
|
||||
|
||||
4) mit WinSCP als root einloggen
|
||||
4.1) aktualisieren von camera.py und config.txt in /home/pi/ kopieren <-- gehört user pi
|
||||
4.2) /home/pi/picture_Number.txt die gewünschte Nummer eintragen
|
||||
4.3) config.txt anpassen
|
||||
|
||||
5) Aufräumen
|
||||
5.1) in /root
|
||||
5.2) /media/usb
|
||||
|
||||
6) Passwörter ändern
|
||||
6.1) passwd pi
|
||||
6.1.1) das pi-PW für TLCXX
|
||||
6.2) passwd root
|
||||
6.2.1) das root-PW für TLCXX
|
||||
|
||||
7) Bei Modem-Version
|
||||
7.1) nano /etc/rc.local
|
||||
7.1.1) ergänzen um:
|
||||
|
||||
printf "%sStarting 3G Modem%s\n"
|
||||
sudo /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
|
||||
7.2) Startverzögerung
|
||||
7.2.1) crontab -e
|
||||
7.2.2) @reboot /bin/sleep 120 ; /usr/bin/python3 /home/pi/camera.py 2>&1 >> /home/pi/camera_boot.log 2>&1
|
||||
|
||||
|
||||
8) RTC bei I/O Board
|
||||
8.1) i2cdetect -y 1
|
||||
8.2) modprobe rtc-ds1307
|
||||
8.3) bash
|
||||
8.4) echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
|
||||
8.5) exit
|
||||
8.6) zeit mit internet synchronisieren
|
||||
8.7) hwclock -w
|
||||
8.8) nano /etc/modules und rtc-ds1307 hinzufügen
|
||||
|
||||
9) Ordner anlegen
|
||||
9.1) mkdir /media/usb/pictures
|
||||
9.2) mkdir /media/usb/log
|
||||
|
||||
10) reboot
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
53
Software/Website/install.txt
Normal file
53
Software/Website/install.txt
Normal file
@ -0,0 +1,53 @@
|
||||
mkdir -pv /home/timelapse
|
||||
|
||||
latest_ftp_image.sh hinein kopieren
|
||||
|
||||
nano /etc/systemd/system/TLCbackend.service
|
||||
|
||||
############ INSERT BEGIN #################
|
||||
|
||||
[Unit]
|
||||
Description=TLCbackend
|
||||
After=syslog.target
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
RestartSec=2s
|
||||
Type=oneshot
|
||||
User=root
|
||||
Group=root
|
||||
WorkingDirectory=/home/timelapse/
|
||||
ExecStart=/bin/sh /home/timelapse/latest_ftp_image.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
############ INSERT END #################
|
||||
|
||||
systemctl enable TLCbackend.service
|
||||
|
||||
nano /etc/systemd/system/TLCbackend.timer
|
||||
|
||||
############ INSERT BEGIN #################
|
||||
|
||||
[Unit]
|
||||
Description=TLCbackend Timer
|
||||
|
||||
[Timer]
|
||||
OnActiveSec=30s
|
||||
OnBootSec=10min
|
||||
OnUnitActiveSec=5m
|
||||
|
||||
[Install]
|
||||
WantedBy=basic.target
|
||||
|
||||
############ INSERT END #################
|
||||
|
||||
chmod 700 /home/timelapse/latest_ftp_image.sh
|
||||
|
||||
systemctl enable --now TLCbackend.timer
|
||||
|
||||
|
||||
#debug
|
||||
|
||||
journalctl -u TLCbackend.service
|
||||
43
Software/Website/latest_ftp_image.sh
Normal file
43
Software/Website/latest_ftp_image.sh
Normal file
@ -0,0 +1,43 @@
|
||||
#! /bin/bash
|
||||
|
||||
hostname=schuttercloud.com
|
||||
username=uploader
|
||||
password=XXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
cameraDir=/camera03/latest/
|
||||
webDir=test
|
||||
webFile=TLC03
|
||||
mask=mask.png
|
||||
|
||||
|
||||
echo starting
|
||||
|
||||
ftp -nv <<EOF
|
||||
open $hostname
|
||||
user $username $password
|
||||
cd $cameraDir
|
||||
nlist *.jpg index.txt
|
||||
bye
|
||||
EOF
|
||||
|
||||
latest_file=`tail -1 index.txt`
|
||||
rm index.txt
|
||||
|
||||
ftp -nv <<EOF
|
||||
open $hostname
|
||||
user $username $password
|
||||
binary
|
||||
cd $cameraDir
|
||||
get $latest_file
|
||||
bye
|
||||
EOF
|
||||
|
||||
# mask images
|
||||
composite $mask $latest_file $webFile.jpg
|
||||
rm $latest_file
|
||||
|
||||
# resize images
|
||||
convert $webFile.jpg -resize 1083x813 ${webFile}_resized.jpg
|
||||
|
||||
mv $webFile.jpg $webDir
|
||||
|
||||
mv ${webFile}_resized.jpg $webDir
|
||||
Binary file not shown.
76
Software/Wireless Access Point/install.txt
Normal file
76
Software/Wireless Access Point/install.txt
Normal file
@ -0,0 +1,76 @@
|
||||
|
||||
SSID: CopterSicht
|
||||
|
||||
PW: Mathe102
|
||||
|
||||
|
||||
|
||||
apt-get update
|
||||
|
||||
apt-get upgrade
|
||||
|
||||
apt-get install dnsmasq hostapd
|
||||
|
||||
systemctl stop dnsmasq
|
||||
|
||||
systemctl stop hostapd
|
||||
|
||||
nano /etc/dhcpcd.conf
|
||||
------------------------------------------
|
||||
interface wlan0
|
||||
static ip_address=192.168.1.1
|
||||
static routers=192.168.1.1
|
||||
static domain_name_servers=8.8.8.8
|
||||
------------------------------------------
|
||||
|
||||
mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
|
||||
|
||||
nano /etc/dnsmasq.conf
|
||||
------------------------------------------
|
||||
interface=wlan0
|
||||
domain-needed
|
||||
bogus-priv
|
||||
dhcp-range=192.168.1.8,192.168.1.250,12h
|
||||
------------------------------------------
|
||||
|
||||
nano /etc/hostapd/hostapd.conf
|
||||
------------------------------------------
|
||||
interface=wlan0
|
||||
driver=nl80211
|
||||
ssid=NameOfNetwork
|
||||
hw_mode=g
|
||||
channel=7
|
||||
wmm_enabled=0
|
||||
macaddr_acl=0
|
||||
auth_algs=1
|
||||
ignore_broadcast_ssid=0
|
||||
wpa=2
|
||||
wpa_passphrase=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
wpa_key_mgmt=WPA-PSK
|
||||
wpa_pairwise=TKIP
|
||||
rsn_pairwise=CCMP
|
||||
------------------------------------------
|
||||
|
||||
nano /etc/default/hostapd
|
||||
------------------------------------------
|
||||
DAEMON_CONF="/etc/hostapd/hostapd.conf"
|
||||
------------------------------------------
|
||||
|
||||
nano /etc/sysctl.conf
|
||||
------------------------------------------
|
||||
net.ipv4.ip_forward=1
|
||||
------------------------------------------
|
||||
|
||||
killall wpa_supplicant
|
||||
|
||||
hostapd -d /etc/hostapd/hostapd.conf
|
||||
|
||||
|
||||
|
||||
@reboot /bin/sleep 20 ; /usr/bin/killall wpa_supplicant & >> /home/pi/wifi_boot.log 2>&1
|
||||
|
||||
@reboot /bin/sleep 50 ; /usr/sbin/hostapd /etc/hostapd/hostapd.conf > /home/pi/wifi_boot.log &
|
||||
|
||||
|
||||
|
||||
|
||||
40
Software/ZK_python/Grenzwerte.txt
Normal file
40
Software/ZK_python/Grenzwerte.txt
Normal file
@ -0,0 +1,40 @@
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
|
||||
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
|
||||
|
||||
|
||||
Monat Auf Unter (in Stunden)
|
||||
_________________
|
||||
Jan 8 17
|
||||
|
||||
Feb 8 17.5
|
||||
|
||||
März 7 18
|
||||
|
||||
April 7 20
|
||||
|
||||
Mai 6 20.5
|
||||
|
||||
Juni 5.5 21.5
|
||||
|
||||
Juli 6 21.5
|
||||
|
||||
Aug 6.5 20.5
|
||||
|
||||
Sep 7.5 19.5
|
||||
|
||||
Okt 7.5 17.5
|
||||
|
||||
Nov 8 16.5
|
||||
|
||||
Dez 8 16.5
|
||||
|
||||
|
||||
|
||||
Auf = Wann geht die Sonne am spätesten im Monat auf.
|
||||
|
||||
Unter = Wann geht die Sonne am frühsten im Monat unter.
|
||||
|
||||
http://sunrisesunset.de/
|
||||
9
Software/ZK_python/Kameraeinstellungen.txt
Normal file
9
Software/ZK_python/Kameraeinstellungen.txt
Normal file
@ -0,0 +1,9 @@
|
||||
Version 0.1
|
||||
Stand 16.03.2017
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
|
||||
camera.iso = 50
|
||||
camera.resolution = (3280,2464)
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
21
Software/ZK_python/Ordnerstruktur.txt
Normal file
21
Software/ZK_python/Ordnerstruktur.txt
Normal file
@ -0,0 +1,21 @@
|
||||
Bilder:
|
||||
/camera01/session01/2018/01_January
|
||||
|
||||
|
||||
Logs:
|
||||
/logs/2018/01_January
|
||||
|
||||
Monate:
|
||||
|
||||
01_January
|
||||
02_February
|
||||
03_March
|
||||
04_April
|
||||
05_May
|
||||
06_June
|
||||
07_July
|
||||
08_August
|
||||
09_September
|
||||
10_October
|
||||
11_November
|
||||
12_December
|
||||
9
Software/ZK_python/TempGrenzwerte.txt
Normal file
9
Software/ZK_python/TempGrenzwerte.txt
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
<= -5<>C --> Critical Coold
|
||||
|
||||
<= 5<>C --> Warning Coold
|
||||
|
||||
>= 45<34>C --> Warning Hot
|
||||
|
||||
>= 50<35>C --> Critical Hot
|
||||
185
Software/ZK_python/camera_rc1_006.py
Normal file
185
Software/ZK_python/camera_rc1_006.py
Normal file
@ -0,0 +1,185 @@
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_directory = configParser.get('config', 'ftp_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
print('done!')
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_directory)
|
||||
f = open("picture_Number.txt",'r')
|
||||
wakeup_Time = [7,7,6,5,5,4,4,5,5,6,6,6]
|
||||
picture_number = int(f.read())
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path) #TODO fallback test
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path) #TODO fallback test
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 30
|
||||
time_name = time.asctime(time.localtime(time.time()))
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = '01_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit Name:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #nimmt bild 'image.jpg' auf
|
||||
picture_number += 1
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number))
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000:
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
if datetime.now().hour > wakeup_Time[datetime.now().month] and datetime.now().hour < 17:
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until'+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until'+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else:
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
193
Software/ZK_python/camera_rc1_007.py
Normal file
193
Software/ZK_python/camera_rc1_007.py
Normal file
@ -0,0 +1,193 @@
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
print('done!')
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
f = open("picture_Number.txt",'r')
|
||||
wakeup_Time = [7,7,6,5,5,4,4,5,5,6,6,6]
|
||||
picture_number = int(f.read())
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300
|
||||
time_name = time.asctime(time.localtime(time.time()))
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = '01_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit Name:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #nimmt bild 'image.jpg' auf
|
||||
picture_number += 1
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number))
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000:
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
if datetime.now().hour > wakeup_Time[datetime.now().month] and datetime.now().hour < 17:
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until'+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else:
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
199
Software/ZK_python/camera_rc1_008.py
Normal file
199
Software/ZK_python/camera_rc1_008.py
Normal file
@ -0,0 +1,199 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
print('done!')
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
f = open("picture_Number.txt",'r')
|
||||
wakeup_Time = [7,7,6,5,5,4,4,5,5,6,6,6]
|
||||
picture_number = int(f.read())
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300
|
||||
time_name = time.asctime(time.localtime(time.time()))
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit Name:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #nimmt bild 'image.jpg' auf
|
||||
picture_number += 1
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number))
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000:
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
if datetime.now().hour > wakeup_Time[datetime.now().month] and datetime.now().hour < 17:
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until'+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else:
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
245
Software/ZK_python/camera_rc1_009.py
Normal file
245
Software/ZK_python/camera_rc1_009.py
Normal file
@ -0,0 +1,245 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#009
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 009'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
print('done!')
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
f = open("picture_Number.txt",'r')
|
||||
wakeup_Time = [7,7,6,5,5,4,4,5,5,6,6,6]
|
||||
picture_number = int(f.read())
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
if datetime.now().hour > wakeup_Time[datetime.now().month] and datetime.now().hour < 17: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until'+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
248
Software/ZK_python/camera_rc1_010.py
Normal file
248
Software/ZK_python/camera_rc1_010.py
Normal file
@ -0,0 +1,248 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#009
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 009'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
print('done!')
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
f = open("picture_Number.txt",'r')
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
picture_number = int(f.read())
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month]*60*60 and seconds1 < bed_Time[datetime.now().month]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until'+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
248
Software/ZK_python/camera_rc1_011.py
Normal file
248
Software/ZK_python/camera_rc1_011.py
Normal file
@ -0,0 +1,248 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#011
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 011'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
print('done!')
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
f = open("picture_Number.txt",'r')
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
picture_number = int(f.read())
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
266
Software/ZK_python/camera_rc1_012.py
Normal file
266
Software/ZK_python/camera_rc1_012.py
Normal file
@ -0,0 +1,266 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#012
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 012'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
print('done!')
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
f = open("picture_Number.txt",'r')
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
picture_number = int(f.read())
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
268
Software/ZK_python/camera_rc1_013.py
Normal file
268
Software/ZK_python/camera_rc1_013.py
Normal file
@ -0,0 +1,268 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#012
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
import piexif
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 012'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
print('done!')
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
f = open("picture_Number.txt",'r')
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
picture_number = int(f.read())
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
piexif.remove(picture_path)
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
267
Software/ZK_python/camera_rc1_014.py
Normal file
267
Software/ZK_python/camera_rc1_014.py
Normal file
@ -0,0 +1,267 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#014
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
import piexif
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configParser.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'config.txt'))
|
||||
|
||||
version = 'starting camera version 014'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
print('done!')
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
f = open("picture_Number.txt",'r')
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
picture_number = int(f.read())
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
piexif.remove(picture_path)
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
277
Software/ZK_python/camera_rc2_015.py
Normal file
277
Software/ZK_python/camera_rc2_015.py
Normal file
@ -0,0 +1,277 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#015
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
import piexif
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configParser.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), '/home/pi/config.txt'))
|
||||
|
||||
version = 'starting camera version 015'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enamble_modem = configParser.get('config', 'enamble_modem')
|
||||
print('done!')
|
||||
|
||||
if enamble_modem == 'true':
|
||||
print('start modem connection ...')
|
||||
logging.info('start modem connection ...')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('connection successful')
|
||||
ogging.info(stdoutdata)
|
||||
logging.info('connection successful')
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
picture_number = int(f.read())
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' and enamble_modem == 'true':in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
piexif.remove(picture_path)
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if 'nicht' and enamble_modem == 'true':in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
279
Software/ZK_python/camera_rc2_016.py
Normal file
279
Software/ZK_python/camera_rc2_016.py
Normal file
@ -0,0 +1,279 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#015
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
import piexif
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configParser.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), '/home/pi/config.txt'))
|
||||
|
||||
version = 'starting camera version 015'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enamble_modem = configParser.get('config', 'enamble_modem')
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
if enamble_modem == 'true':
|
||||
print('start modem connection ...')
|
||||
logging.info('start modem connection ...')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('connection successful')
|
||||
ogging.info(stdoutdata)
|
||||
logging.info('connection successful')
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
picture_number = int(f.read())
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enamble_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
piexif.remove(picture_path)
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enamble_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
296
Software/ZK_python/camera_rc2_019.py
Normal file
296
Software/ZK_python/camera_rc2_019.py
Normal file
@ -0,0 +1,296 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#019
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
import piexif
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configParser.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), '/home/pi/config.txt'))
|
||||
|
||||
version = 'starting camera version 019'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enamble_modem = configParser.get('config', 'enamble_modem')
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
if enamble_modem == 'true':
|
||||
print('start modem connection ...')
|
||||
logging.info('start modem connection ...')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('connection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('connection successful')
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
picture_number = int(f.read())
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enamble_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
piexif.remove(picture_path)
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
os.remove(log_directory+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
os.remove(log_directory+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enamble_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
os.remove(log_directory+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
305
Software/ZK_python/camera_rc3_021.py
Normal file
305
Software/ZK_python/camera_rc3_021.py
Normal file
@ -0,0 +1,305 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#021
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
#configParser = configparser.RawConfigParser()
|
||||
#configParser.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), '/home/pi/config.txt'))
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 021'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
if enable_modem == 'true':
|
||||
print('start modem connection ...')
|
||||
logging.info('start modem connection ...')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('connection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('connection successful')
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('reading picture number ...')
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
print('picture number is:',str(picture_number))
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = ''
|
||||
camera.exif_tags['IFD0.Model '] = ''
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
os.remove(log_directory+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
os.remove(log_directory+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
os.remove(log_directory+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
297
Software/ZK_python/camera_rc3_022.py
Normal file
297
Software/ZK_python/camera_rc3_022.py
Normal file
@ -0,0 +1,297 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#022
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 022'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
logging.info('no internet connection on startup trying to reconnect later!')
|
||||
logging.info(str(ea))
|
||||
print('reading picture number ...')
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
print('picture number is:',str(picture_number))
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
os.remove(log_directory+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
os.remove(log_directory+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
os.remove(log_directory+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
297
Software/ZK_python/camera_rc3_023.py
Normal file
297
Software/ZK_python/camera_rc3_023.py
Normal file
@ -0,0 +1,297 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#023
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 023'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
logging.info('no internet connection on startup trying to reconnect later!')
|
||||
logging.info(str(ea))
|
||||
print('reading picture number ...')
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
print('picture number is:',str(picture_number))
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
os.remove(log_directory+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
#os.remove(log_directory+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
#os.remove(log_directory+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
293
Software/ZK_python/camera_rc3_024.py
Normal file
293
Software/ZK_python/camera_rc3_024.py
Normal file
@ -0,0 +1,293 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#024
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 024'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
|
||||
print('reading picture number ...')
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
print('picture number is:',str(picture_number))
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
142
Software/ZK_python/camera_rc_001.py
Normal file
142
Software/ZK_python/camera_rc_001.py
Normal file
@ -0,0 +1,142 @@
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP('schuttercloud.com','uploader','1234')
|
||||
ftp.cwd('/camera01')
|
||||
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
camera.shutter_speed = 500000
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
wakeup_Time = [7,7,6,5,5,4,4,5,5,6,6,6]
|
||||
i=0
|
||||
camera_number = '01'
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
print ('New ftp connection successfull! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successfull! current dicertory is: '+ftp.pwd())
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path) #TODO fallback test
|
||||
print('upload succesful!')
|
||||
logging.info('upload succesful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect('schuttercloud.com')
|
||||
ftp.login('uploader','1234')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path) #TODO fallback test
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
return
|
||||
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 3000
|
||||
time_name = time.asctime(time.localtime(time.time()))
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = '01_'+str(i).zfill(9)+'_'+time_name + '.jpg'
|
||||
picture_path = '/home/pi/Pictures/' + picture_name
|
||||
|
||||
print ("Zeit Name:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #nimmt bild 'image.jpg' auf
|
||||
i=i+1
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000:
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
if datetime.now().hour > wakeup_Time[datetime.now().month] and datetime.now().hour < 17:
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + log_name, open('/home/pi/'+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect('schuttercloud.com')
|
||||
ftp.login('uploader','1234')
|
||||
ftp.storbinary('STOR ' + log_name, open('/home/pi/'+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
156
Software/ZK_python/camera_rc_002.py
Normal file
156
Software/ZK_python/camera_rc_002.py
Normal file
@ -0,0 +1,156 @@
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP('schuttercloud.com','uploader','1234')
|
||||
ftp.cwd('/camera01')
|
||||
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
camera.shutter_speed = 500000
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
wakeup_Time = [7,7,6,5,5,4,4,5,5,6,6,6]
|
||||
i=0
|
||||
camera_number = '01'
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path) #TODO fallback test
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect('schuttercloud.com')
|
||||
ftp.login('uploader','1234')
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path) #TODO fallback test
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
return
|
||||
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 3000
|
||||
time_name = time.asctime(time.localtime(time.time()))
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = '01_'+str(i).zfill(9)+'_'+time_name + '.jpg'
|
||||
picture_path = '/home/pi/Pictures/' + picture_name
|
||||
|
||||
print ("Zeit Name:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #nimmt bild 'image.jpg' auf
|
||||
i=i+1
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000:
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
if datetime.now().hour > wakeup_Time[datetime.now().month] and datetime.now().hour < 17:
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + log_name, open('/home/pi/'+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect('schuttercloud.com')
|
||||
ftp.login('uploader','1234')
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + log_name, open('/home/pi/'+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
156
Software/ZK_python/camera_rc_003.py
Normal file
156
Software/ZK_python/camera_rc_003.py
Normal file
@ -0,0 +1,156 @@
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP('schuttercloud.com','uploader','1234')
|
||||
ftp.cwd('/camera01')
|
||||
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
camera.shutter_speed = 500000
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
wakeup_Time = [7,7,6,5,5,4,4,5,5,6,6,6]
|
||||
i=0
|
||||
camera_number = '01'
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path) #TODO fallback test
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect('schuttercloud.com')
|
||||
ftp.login('uploader','1234')
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path) #TODO fallback test
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
return
|
||||
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300
|
||||
time_name = time.asctime(time.localtime(time.time()))
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = '01_'+str(i).zfill(9)+'_'+time_name + '.jpg'
|
||||
picture_path = '/home/pi/Pictures/' + picture_name
|
||||
|
||||
print ("Zeit Name:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #nimmt bild 'image.jpg' auf
|
||||
i=i+1
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000:
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
if datetime.now().hour > wakeup_Time[datetime.now().month] and datetime.now().hour < 17:
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + log_name, open('/home/pi/'+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect('schuttercloud.com')
|
||||
ftp.login('uploader','1234')
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + log_name, open('/home/pi/'+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
158
Software/ZK_python/camera_rc_004.py
Normal file
158
Software/ZK_python/camera_rc_004.py
Normal file
@ -0,0 +1,158 @@
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP('schuttercloud.com','uploader','1234')
|
||||
ftp.cwd('/camera01')
|
||||
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
camera.shutter_speed = 500000
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
wakeup_Time = [7,7,6,5,5,4,4,5,5,6,6,6]
|
||||
i=0
|
||||
camera_number = '01'
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path) #TODO fallback test
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect('schuttercloud.com')
|
||||
ftp.login('uploader','1234')
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path) #TODO fallback test
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
return
|
||||
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300
|
||||
time_name = time.asctime(time.localtime(time.time()))
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = '01_'+str(i).zfill(9)+'_'+time_name + '.jpg'
|
||||
picture_path = '/home/pi/Pictures/' + picture_name
|
||||
|
||||
print ("Zeit Name:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #nimmt bild 'image.jpg' auf
|
||||
i=i+1
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000:
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
if datetime.now().hour > wakeup_Time[datetime.now().month] and datetime.now().hour < 17:
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + log_name, open('/home/pi/'+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect('schuttercloud.com')
|
||||
ftp.login('uploader','1234')
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + log_name, open('/home/pi/'+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
166
Software/ZK_python/camera_rc_005.py
Normal file
166
Software/ZK_python/camera_rc_005.py
Normal file
@ -0,0 +1,166 @@
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
|
||||
camera = PiCamera()
|
||||
ftp = FTP('schuttercloud.com','uploader','1234')
|
||||
ftp.cwd('/camera01')
|
||||
f = open("picture_Number.txt",'r')
|
||||
wakeup_Time = [7,7,6,5,5,4,4,5,5,6,6,6]
|
||||
picture_number = int(f.read())
|
||||
camera_number = '01'
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path) #TODO fallback test
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect('schuttercloud.com')
|
||||
ftp.login('uploader','1234')
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path) #TODO fallback test
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
return
|
||||
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 20
|
||||
time_name = time.asctime(time.localtime(time.time()))
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = '01_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = '/home/pi/Pictures/' + picture_name
|
||||
|
||||
print ("Zeit Name:", time_name)
|
||||
|
||||
try:
|
||||
camera.capture(picture_path) #nimmt bild 'image.jpg' auf
|
||||
picture_number += 1
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("picture_Number.txt",'w')
|
||||
f.write(str(picture_number))
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000:
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
if datetime.now().hour > wakeup_Time[datetime.now().month] and datetime.now().hour < 17:
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + log_name, open('/home/pi/'+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect('schuttercloud.com')
|
||||
ftp.login('uploader','1234')
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + log_name, open('/home/pi/'+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else:
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#maybe needed! needs to be tested
|
||||
# ftp.connect('schuttercloud.com')
|
||||
# ftp.login('uploader','1234')
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
294
Software/ZK_python/camera_test_025.py
Normal file
294
Software/ZK_python/camera_test_025.py
Normal file
@ -0,0 +1,294 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#025
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 025'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
|
||||
print('reading picture number ...')
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
print('picture number is:',str(picture_number))
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
299
Software/ZK_python/camera_test_026.py
Normal file
299
Software/ZK_python/camera_test_026.py
Normal file
@ -0,0 +1,299 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#026
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 026'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
|
||||
print('reading picture number ...')
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
print('picture number is:',str(picture_number))
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < 1800000: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
picture_number -= 1 #decrease picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_name)
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
300
Software/ZK_python/camera_test_027.py
Normal file
300
Software/ZK_python/camera_test_027.py
Normal file
@ -0,0 +1,300 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#027
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 027'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
|
||||
print('reading picture number ...')
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
print('picture number is:',str(picture_number))
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger().handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < picture_size: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
picture_number -= 1 #decrease picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger().handlers = []
|
||||
logging.basicConfig(filename=log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
300
Software/ZK_python/camera_v2_028.py
Normal file
300
Software/ZK_python/camera_v2_028.py
Normal file
@ -0,0 +1,300 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#028
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 028'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
|
||||
print('reading picture number ...')
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
print('picture number is:',str(picture_number))
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('re-connecting successful!')
|
||||
logging.info('re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < picture_size: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
picture_number -= 1 #decrease picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('Network Status: ' + stdoutdata)
|
||||
logging.info('Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('not connected, trying to reconnect')
|
||||
logging.info('not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('connected!')
|
||||
logging.info('connected!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
301
Software/ZK_python/camera_v2_029.py
Normal file
301
Software/ZK_python/camera_v2_029.py
Normal file
@ -0,0 +1,301 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#029
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 029'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
|
||||
print('reading picture number ...')
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
print('picture number is:',str(picture_number))
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
reconnect_counter = 0
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP]re-connecting successful!')
|
||||
logging.info('[FTP]re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP]upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print([sakis3g]'not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection successful')
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < picture_size: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
picture_number -= 1 #decrease picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('trying to reconnect ...')
|
||||
logging.info('trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
301
Software/ZK_python/camera_v2_030.py
Normal file
301
Software/ZK_python/camera_v2_030.py
Normal file
@ -0,0 +1,301 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#030
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 030'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
|
||||
print('reading picture number ...')
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
print('picture number is:',str(picture_number))
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
reconnect_counter = 0
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP]re-connecting successful!')
|
||||
logging.info('[FTP]re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP]upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection successful')
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < picture_size: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
picture_number -= 1 #decrease picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('[FTP]re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
308
Software/ZK_python/camera_v2_031.py
Normal file
308
Software/ZK_python/camera_v2_031.py
Normal file
@ -0,0 +1,308 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#031
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 031'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
|
||||
print('reading picture number ...')
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
print('picture number is:',str(picture_number))
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
reconnect_counter = 0
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP]re-connecting successful!')
|
||||
logging.info('[FTP]re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP]upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection successful')
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < picture_size: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
picture_number -= 1 #decrease picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('[FTP]re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('could not change ftp directory !')
|
||||
logging.error('could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
308
Software/ZK_python/camera_v2_032.py
Normal file
308
Software/ZK_python/camera_v2_032.py
Normal file
@ -0,0 +1,308 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#032
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 032'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
print('done!')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
|
||||
print('reading picture number ...')
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
print('picture number is:',str(picture_number))
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
reconnect_counter = 0
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
|
||||
logging.info(version)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP]re-connecting successful!')
|
||||
logging.info('[FTP]re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP]upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection successful')
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < picture_size: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
picture_number -= 1 #decrease picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('[FTP]re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --sudo --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('could not change ftp directory !')
|
||||
logging.error('could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
310
Software/ZK_python/camera_v2_033.py
Normal file
310
Software/ZK_python/camera_v2_033.py
Normal file
@ -0,0 +1,310 @@
|
||||
#(c)2017 Jannik Seiler
|
||||
#033
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 033'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
print('done!')
|
||||
|
||||
print('reading picture number...')
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
print('done, picture number is:',str(picture_number))
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
print('initializing logger...')
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
reconnect_counter = 0
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('done')
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
|
||||
logging.info(version)
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP]re-connecting successful!')
|
||||
logging.info('[FTP]re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP]upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection successful')
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < picture_size: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
uploadToFTP()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
picture_number -= 1 #decrease picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('uploading todays log befor going to sleep!')
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('[FTP]re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g connect --sudo --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('could not change ftp directory !')
|
||||
logging.error('could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
uploadToFTP()
|
||||
353
Software/ZK_python/camera_v3_034.py
Normal file
353
Software/ZK_python/camera_v3_034.py
Normal file
@ -0,0 +1,353 @@
|
||||
#(c)2017 Jannik Seiler & Hendrik Schutter
|
||||
|
||||
#034
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 034'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
internet = configParser.get('config', 'internet')
|
||||
modem_apn = configParser.get('config', 'modem_apn')
|
||||
|
||||
print('done!')
|
||||
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
print('initializing logger...')
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
reconnect_counter = 0
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('done')
|
||||
print('reading picture number...')
|
||||
try:
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
except Exception as ea:
|
||||
print('No picture_Number.txt found. Creating new .. ')
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(0))
|
||||
f.close()
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
logging.info('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('done, picture number is:',str(picture_number))
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
|
||||
if internet == 'true':
|
||||
print('Running in Online mode, internet connection is required')
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
else:
|
||||
print('Running in Offline mode, no internet connection is required')
|
||||
|
||||
logging.info(version)
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP]re-connecting successful!')
|
||||
logging.info('[FTP]re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP]upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g] disconnected')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection hopefully successful')
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
return
|
||||
|
||||
def checkCpuTemperature():
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
return
|
||||
|
||||
def sleepToNextPicture():
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + 300 #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Zeit:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
if os.path.getsize(picture_path) < picture_size: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
if internet == 'true': uploadToFTP()
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
picture_number -= 1 #decrease picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
if internet == 'true': print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
if internet == 'true': logging.info('uploading todays log befor going to sleep!')
|
||||
if internet == 'true':
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('[FTP]re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g] disconnected')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection hopefully successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('could not change ftp directory !')
|
||||
logging.error('could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
if internet == 'true': uploadToFTP()
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
|
||||
387
Software/ZK_python/camera_v3_035.py
Normal file
387
Software/ZK_python/camera_v3_035.py
Normal file
@ -0,0 +1,387 @@
|
||||
#(c)2017 Jannik Seiler & Hendrik Schutter
|
||||
|
||||
#035
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 035'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
internet = configParser.get('config', 'internet')
|
||||
modem_apn = configParser.get('config', 'modem_apn')
|
||||
upload_only = int(configParser.get('config', 'upload_only'))
|
||||
interval = int(configParser.get('config', 'interval'))
|
||||
|
||||
print('done!')
|
||||
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
print('initializing logger...')
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
reconnect_counter = 0
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('done')
|
||||
print('reading picture number...')
|
||||
try:
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
except Exception as ea:
|
||||
print('No picture_Number.txt found. Creating new .. ')
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(0))
|
||||
f.close()
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
logging.info('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('done, picture number is:',str(picture_number))
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
upload_every = upload_only
|
||||
|
||||
if internet == 'true':
|
||||
print('Running in Online mode, internet connection is required')
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
else:
|
||||
print('Running in Offline mode, no internet connection is required')
|
||||
|
||||
logging.info(version)
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP]re-connecting successful!')
|
||||
logging.info('[FTP]re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP]upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g] disconnected')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection hopefully successful')
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
return
|
||||
def checkDiskSpace():
|
||||
st = os.statvfs('/media/usb0')
|
||||
free = st.f_bavail * st.f_frsize
|
||||
total = st.f_blocks * st.f_frsize
|
||||
|
||||
freePercentaged = int(((st.f_bavail * st.f_frsize)/(st.f_blocks * st.f_frsize))*100)
|
||||
logging.info('Free disk space ' +str(freePercentaged)+' %')
|
||||
print('Free disk space ',str(freePercentaged),' %')
|
||||
if freePercentaged < 20: logging.warning('Storage Drive nearly full!')
|
||||
if freePercentaged < 10: logging.critical('Storage Drive full, Backup Space in use!')
|
||||
|
||||
return
|
||||
|
||||
def checkCpuTemperature():
|
||||
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
|
||||
return
|
||||
|
||||
def sleepToNextPicture():
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + interval #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Time:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
checkDiskSpace()
|
||||
if os.path.getsize(picture_path) < picture_size: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
print("uploadTimer",upload_every)
|
||||
if (internet == 'true')and(upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
logging.info('Skipping upload. Next upload in '+str(upload_every)+' pictures')
|
||||
print('Skipping upload. Next upload in',(upload_every),'pictures')
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
|
||||
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
picture_number -= 1 #decrease picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
if internet == 'true': print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
if internet == 'true': logging.info('uploading todays log befor going to sleep!')
|
||||
if internet == 'true':
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('[FTP]re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g] disconnected')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection hopefully successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('could not change ftp directory !')
|
||||
logging.error('could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
|
||||
if (internet == 'true')and(upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
logging.info('Skipping upload. Next upload in '+str(upload_every)+' pictures')
|
||||
print('Skipping upload. Next upload in',upload_every,'pictures')
|
||||
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
|
||||
407
Software/ZK_python/camera_v3_036.py
Normal file
407
Software/ZK_python/camera_v3_036.py
Normal file
@ -0,0 +1,407 @@
|
||||
#(c)2017 Jannik Seiler & Hendrik Schutter
|
||||
|
||||
#036
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
from spidev import SpiDev
|
||||
from time import sleep
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 036'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
internet = configParser.get('config', 'internet')
|
||||
modem_apn = configParser.get('config', 'modem_apn')
|
||||
upload_only = int(configParser.get('config', 'upload_only'))
|
||||
interval = int(configParser.get('config', 'interval'))
|
||||
ioBoard = configParser.get('config', 'I/O_Board')
|
||||
|
||||
print('done!')
|
||||
|
||||
wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
print('initializing logger...')
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
reconnect_counter = 0
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
logging.info(version)
|
||||
print('done')
|
||||
print('reading picture number...')
|
||||
try:
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
except Exception as ea:
|
||||
print('No picture_Number.txt found. Creating new .. ')
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(0))
|
||||
f.close()
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
logging.info('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('done, picture number is:',str(picture_number))
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
upload_every = upload_only
|
||||
|
||||
if ioBoard =="true":
|
||||
print('Running with the nice IO board!')
|
||||
spi = SpiDev()
|
||||
spi.open(0,0)
|
||||
else:
|
||||
print('Running without the nice IO board!')
|
||||
|
||||
if internet == 'true':
|
||||
print('Running in Online mode, internet connection is required')
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
else:
|
||||
print('Running in Offline mode, no internet connection is required')
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP]re-connecting successful!')
|
||||
logging.info('[FTP]re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP]upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g] disconnected')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection hopefully successful')
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
return
|
||||
|
||||
def checkDiskSpace():
|
||||
st = os.statvfs('/media/usb0')
|
||||
free = st.f_bavail * st.f_frsize
|
||||
total = st.f_blocks * st.f_frsize
|
||||
|
||||
freePercentaged = int(((st.f_bavail * st.f_frsize)/(st.f_blocks * st.f_frsize))*100)
|
||||
logging.info('Free disk space ' +str(freePercentaged)+' %')
|
||||
print('Free disk space ',str(freePercentaged),' %')
|
||||
if freePercentaged < 20 and freePercentaged > 10: logging.warning('Storage Drive nearly full!')
|
||||
if freePercentaged < 10: logging.critical('Storage Drive full, Backup Space in use!')
|
||||
return
|
||||
|
||||
def checkCpuTemperature():
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
return
|
||||
|
||||
def readMPC(channel):
|
||||
adc = spi.xfer2([1, (8 + channel) << 4, 0])
|
||||
data = ((adc[1] & 3) << 8) + adc[2]
|
||||
return data
|
||||
|
||||
def sleepToNextPicture():
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
def checkSystemVoltage():
|
||||
systemVoltage = (((readMPC(0) / 1023.0 * 3.3)*6.62)*0.95)
|
||||
print("System Input Voltage: %.2f" % systemVoltage, "Volt")
|
||||
logging.info('System Input Voltage: ' + str("%.2f" % systemVoltage) + ' Volt')
|
||||
if systemVoltage < 11.3 and systemVoltage > 9: logging.warning('Low System Input Voltage! Maybe bad power supply or no sun.')
|
||||
if systemVoltage < 9: logging.critical('Very low System Input Voltage! Bad power supply or no sun.')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + interval #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Time:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
checkDiskSpace()
|
||||
if ioBoard =="true": checkSystemVoltage()
|
||||
if os.path.getsize(picture_path) < picture_size: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
print("uploadTimer",upload_every)
|
||||
if (internet == 'true')and(upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
logging.info('Skipping upload. Next upload in '+str(upload_every)+' pictures')
|
||||
print('Skipping upload. Next upload in',(upload_every),'pictures')
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
|
||||
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
picture_number -= 1 #decrease picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
if internet == 'true': print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
if internet == 'true': logging.info('uploading todays log befor going to sleep!')
|
||||
if internet == 'true':
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('[FTP]re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g] disconnected')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection hopefully successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('could not change ftp directory !')
|
||||
logging.error('could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
|
||||
if (internet == 'true')and(upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
logging.info('Skipping upload. Next upload in '+str(upload_every)+' pictures')
|
||||
print('Skipping upload. Next upload in',upload_every,'pictures')
|
||||
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
|
||||
409
Software/ZK_python/camera_v3_037.py
Normal file
409
Software/ZK_python/camera_v3_037.py
Normal file
@ -0,0 +1,409 @@
|
||||
#(c)2017 Jannik Seiler & Hendrik Schutter
|
||||
|
||||
#037
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
from spidev import SpiDev
|
||||
from time import sleep
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
version = 'starting camera version 037'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
internet = configParser.get('config', 'internet')
|
||||
modem_apn = configParser.get('config', 'modem_apn')
|
||||
upload_only = int(configParser.get('config', 'upload_only'))
|
||||
interval = int(configParser.get('config', 'interval'))
|
||||
ioBoard = configParser.get('config', 'I/O_Board')
|
||||
|
||||
wakeup_Time = str(configParser.get('config', 'wakeup_Time')).split(',')
|
||||
bed_Time = str(configParser.get('config', 'bed_Time')).split(',')
|
||||
print('done!')
|
||||
|
||||
#wakeup_Time = [8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8]
|
||||
#bed_Time = [17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5]
|
||||
print('initializing logger...')
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
reconnect_counter = 0
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
logging.info(version)
|
||||
print('done')
|
||||
print('reading picture number...')
|
||||
try:
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
except Exception as ea:
|
||||
print('No picture_Number.txt found. Creating new .. ')
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(0))
|
||||
f.close()
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
logging.info('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('done, picture number is:',str(picture_number))
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
upload_every = upload_only
|
||||
|
||||
if ioBoard =="true":
|
||||
print('Running with the nice IO board!')
|
||||
spi = SpiDev()
|
||||
spi.open(0,0)
|
||||
else:
|
||||
print('Running without the nice IO board!')
|
||||
|
||||
if internet == 'true':
|
||||
print('Running in Online mode, internet connection is required')
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
else:
|
||||
print('Running in Offline mode, no internet connection is required')
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464
|
||||
camera.awb_mode = 'auto'
|
||||
camera.exposure_mode = 'auto'
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP]re-connecting successful!')
|
||||
logging.info('[FTP]re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP]upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g] disconnected')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection hopefully successful')
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
return
|
||||
|
||||
def checkDiskSpace():
|
||||
st = os.statvfs('/media/usb0')
|
||||
free = st.f_bavail * st.f_frsize
|
||||
total = st.f_blocks * st.f_frsize
|
||||
|
||||
freePercentaged = int(((st.f_bavail * st.f_frsize)/(st.f_blocks * st.f_frsize))*100)
|
||||
logging.info('Free disk space ' +str(freePercentaged)+' %')
|
||||
print('Free disk space ',str(freePercentaged),' %')
|
||||
if freePercentaged < 20 and freePercentaged > 10: logging.warning('Storage Drive nearly full!')
|
||||
if freePercentaged < 10: logging.critical('Storage Drive full, Backup Space in use!')
|
||||
return
|
||||
|
||||
def checkCpuTemperature():
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
return
|
||||
|
||||
def readMPC(channel):
|
||||
adc = spi.xfer2([1, (8 + channel) << 4, 0])
|
||||
data = ((adc[1] & 3) << 8) + adc[2]
|
||||
return data
|
||||
|
||||
def sleepToNextPicture():
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
def checkSystemVoltage():
|
||||
systemVoltage = (((readMPC(0) / 1023.0 * 3.3)*6.62)*0.95)
|
||||
print("System Input Voltage: %.2f" % systemVoltage, "Volt")
|
||||
logging.info('System Input Voltage: ' + str("%.2f" % systemVoltage) + ' Volt')
|
||||
if systemVoltage < 11.3 and systemVoltage > 9: logging.warning('Low System Input Voltage! Maybe bad power supply or no sun.')
|
||||
if systemVoltage < 9: logging.critical('Very low System Input Voltage! Bad power supply or no sun.')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + interval #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Time:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
checkDiskSpace()
|
||||
if ioBoard =="true": checkSystemVoltage()
|
||||
if os.path.getsize(picture_path) < picture_size: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > wakeup_Time[datetime.now().month-1]*60*60 and seconds1 < bed_Time[datetime.now().month-1]*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
print("uploadTimer",upload_every)
|
||||
if (internet == 'true')and(upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
logging.info('Skipping upload. Next upload in '+str(upload_every)+' pictures')
|
||||
print('Skipping upload. Next upload in',(upload_every),'pictures')
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
|
||||
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
picture_number -= 1 #decrease picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
if internet == 'true': print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
if internet == 'true': logging.info('uploading todays log befor going to sleep!')
|
||||
if internet == 'true':
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('[FTP]re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g] disconnected')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection hopefully successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('could not change ftp directory !')
|
||||
logging.error('could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (wakeup_Time[datetime.now().month-1]*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (wakeup_Time[datetime.now().month-1]*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(wakeup_Time[datetime.now().month-1]*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (wakeup_Time[datetime.now().month-1]*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
|
||||
if (internet == 'true')and(upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
logging.info('Skipping upload. Next upload in '+str(upload_every)+' pictures')
|
||||
print('Skipping upload. Next upload in',upload_every,'pictures')
|
||||
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
|
||||
443
Software/ZK_python/camera_v3_038.py
Normal file
443
Software/ZK_python/camera_v3_038.py
Normal file
@ -0,0 +1,443 @@
|
||||
#(c)2017 Jannik Seiler & Hendrik Schutter
|
||||
|
||||
#038
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
from spidev import SpiDev
|
||||
from time import sleep
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
#ioBoard
|
||||
piezo = 25
|
||||
bootSwitch = 17
|
||||
|
||||
version = 'starting camera version 038'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
internet = configParser.get('config', 'internet')
|
||||
modem_apn = configParser.get('config', 'modem_apn')
|
||||
upload_only = int(configParser.get('config', 'upload_only'))
|
||||
interval = int(configParser.get('config', 'interval'))
|
||||
ioBoard = configParser.get('config', 'I/O_Board')
|
||||
mute = configParser.get('config', 'mute')
|
||||
wakeup_Time = str(configParser.get('config', 'wakeup_Time')).split(',')
|
||||
bed_Time = str(configParser.get('config', 'bed_Time')).split(',')
|
||||
print('done!')
|
||||
|
||||
|
||||
print('initializing logger...')
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
reconnect_counter = 0
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
logging.info(version)
|
||||
print('done')
|
||||
print('reading picture number...')
|
||||
try:
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
except Exception as ea:
|
||||
print('No picture_Number.txt found. Creating new .. ')
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(0))
|
||||
f.close()
|
||||
f = open("/home/pi/picture_Number.txt",'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
logging.info('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('done, picture number is:',str(picture_number))
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
upload_every = upload_only
|
||||
|
||||
if ioBoard =="true":
|
||||
print('Running with the nice IO board!')
|
||||
spi = SpiDev()
|
||||
spi.open(0,0)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(piezo, GPIO.OUT)
|
||||
GPIO.setup(bootSwitch, GPIO.IN)
|
||||
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464s
|
||||
camera.start_preview()
|
||||
#camera.start_preview(fullscreen=False, window = (100, 20, 960, 720))
|
||||
print('---starting sharpness tool---')
|
||||
print('--------normal output--------')
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
sleep(5)
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera.stop_preview()
|
||||
print('---------zoom output---------')
|
||||
camera.crop = (0.5, 0.5, 0.3, 0.4)
|
||||
camera.start_preview()
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
else:
|
||||
camera.stop_preview()
|
||||
if mute == "false":
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(1)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
else:
|
||||
print('Running without the nice IO board!')
|
||||
|
||||
if internet == 'true':
|
||||
print('Running in Online mode, internet connection is required')
|
||||
try:
|
||||
ftp = FTP(ftp_url,ftp_user,ftp_pw,timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as ea:
|
||||
print('no internet connection on startup trying to reconnect later!')
|
||||
print ('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: '+ftp.pwd())
|
||||
else:
|
||||
print('Running in Offline mode, no internet connection is required')
|
||||
|
||||
#camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
#camera.shutter_speed = 500000
|
||||
camera.resolution = (3280,2464) #aufloesung der bilder maximal 3280,2464s
|
||||
camera.exposure_mode = 'auto'
|
||||
camera.crop = (0, 0, 0, 0)
|
||||
#camera.brightness = 50 #0 bis 100; default 50
|
||||
#camera.contrast = 0 #-100 bis 100; default 0
|
||||
#camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
#camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
#camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
#get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp)/1000
|
||||
|
||||
#uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP]re-connecting successful!')
|
||||
logging.info('[FTP]re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP]upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except ftplib.all_errors as e9:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g] disconnected')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection hopefully successful')
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
return
|
||||
|
||||
def checkDiskSpace():
|
||||
st = os.statvfs('/media/usb0')
|
||||
free = st.f_bavail * st.f_frsize
|
||||
total = st.f_blocks * st.f_frsize
|
||||
|
||||
freePercentaged = int(((st.f_bavail * st.f_frsize)/(st.f_blocks * st.f_frsize))*100)
|
||||
logging.info('Free disk space ' +str(freePercentaged)+' %')
|
||||
print('Free disk space ',str(freePercentaged),' %')
|
||||
if freePercentaged < 20 and freePercentaged > 10: logging.warning('Storage Drive nearly full!')
|
||||
if freePercentaged < 10: logging.critical('Storage Drive full, Backup Space in use!')
|
||||
return
|
||||
|
||||
def checkCpuTemperature():
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature())+ ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature())+ ' C')
|
||||
return
|
||||
|
||||
def readMPC(channel):
|
||||
adc = spi.xfer2([1, (8 + channel) << 4, 0])
|
||||
data = ((adc[1] & 3) << 8) + adc[2]
|
||||
return data
|
||||
|
||||
def sleepToNextPicture():
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix>0:
|
||||
print("sleeping now",time_sleep_unix,"seconds"+'\n')
|
||||
logging.info('sleeping now '+str(time_sleep_unix)+' seconds'+'\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
def checkSystemVoltage():
|
||||
systemVoltage = (((readMPC(0) / 1023.0 * 3.3)*6.62)*0.95)
|
||||
print("System Input Voltage: %.2f" % systemVoltage, "Volt")
|
||||
logging.info('System Input Voltage: ' + str("%.2f" % systemVoltage) + ' Volt')
|
||||
if systemVoltage < 11.3 and systemVoltage > 9: logging.warning('Low System Input Voltage! Maybe bad power supply or no sun.')
|
||||
if systemVoltage < 9: logging.critical('Very low System Input Voltage! Bad power supply or no sun.')
|
||||
return
|
||||
|
||||
#main programm (endless loop)
|
||||
while 1:
|
||||
|
||||
time_next_unix = time.time() + interval #time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) #get time for picture_name
|
||||
time_name = time_name.replace(" ","_")
|
||||
time_name = time_name.replace(":","-")
|
||||
picture_name = camera_number+'_'+str(picture_number).zfill(6)+'_'+time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print ("Time:", time_name)
|
||||
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = '5 minute interval'
|
||||
|
||||
if mute == "false": GPIO.output(piezo, GPIO.HIGH)
|
||||
camera.capture(picture_path) #capture image and save to picture_path (picture_directory + picture_name)
|
||||
if mute == "false": GPIO.output(piezo, GPIO.LOW)
|
||||
|
||||
picture_number += 1 #increase picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print ('Picture size:',os.path.getsize(picture_path),"Byte")
|
||||
logging.info('Picture size: '+str(os.path.getsize(picture_path))+' Byte')
|
||||
checkDiskSpace()
|
||||
if ioBoard =="true": checkSystemVoltage()
|
||||
if os.path.getsize(picture_path) < picture_size: #if picture size is under 1800000 Byte we could sleep
|
||||
print ('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds #seconds since midnight
|
||||
if seconds1 > float(wakeup_Time[datetime.now().month-1])*60*60 and seconds1 < float(bed_Time[datetime.now().month-1])*60*60: #if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print ('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
print("uploadTimer",upload_every)
|
||||
if (internet == 'true')and(upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
logging.info('Skipping upload. Next upload in '+str(upload_every)+' pictures')
|
||||
print('Skipping upload. Next upload in',(upload_every),'pictures')
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
|
||||
|
||||
else:
|
||||
os.remove(picture_path) #deleting picture because it's night!
|
||||
picture_number -= 1 #decrease picture_number
|
||||
print('picture_number:',str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt",'w')
|
||||
f.write(str(picture_number)) #save picture_number to a text file
|
||||
f.close()
|
||||
#uploading log file
|
||||
print ('skipping picture upload!')
|
||||
print('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
if internet == 'true': print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
if internet == 'true': logging.info('uploading todays log befor going to sleep!')
|
||||
if internet == 'true':
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e:
|
||||
print ('upload failed!')
|
||||
print (e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP]trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('[FTP]re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except ftplib.all_errors as e8:
|
||||
print('[FTP]re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP]re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('/usr/bin/modem3g/sakis3g status')
|
||||
print('[sakis3g]Network Status: ' + stdoutdata)
|
||||
logging.info('[sakis3g]Network Status: ' + stdoutdata)
|
||||
if enable_modem == 'true' and 'Nicht' in stdoutdata:
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
print('[sakis3g]not connected, trying to reconnect')
|
||||
logging.info('[sakis3g]not connected, trying to reconnect')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g] disconnected')
|
||||
stdoutdata = subprocess.getoutput("/usr/bin/modem3g/sakis3g --sudo disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[sakis3g]reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[sakis3g]reconnection hopefully successful')
|
||||
try:
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user,ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
logging.info('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory+log_name,'rb'),1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 '+log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
logging.info('[sakis3g]if this appears you are connected or there is a bug!')
|
||||
except Exception as e3:
|
||||
print(str(e3))
|
||||
logging.error(str(e3))
|
||||
|
||||
#try? check inet connection -> /usr/bin/modem3g/sakis3g status
|
||||
# if nicht dann neu verbinden -> /usr/bin/modem3g/sakis3g connect --console APN='web.vodafone.de' USBINTERFACE='0' USBMODEM='12d1:1436'
|
||||
# danach nochmal status if dann status = nicht dann reboot
|
||||
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('could not change ftp directory !')
|
||||
logging.error('could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
#sleep until next morning
|
||||
print ('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds #seconds since midnight
|
||||
if seconds < (float(wakeup_Time[datetime.now().month-1])*60*60): #if time between 0am and wakeup_Time
|
||||
sleep_time = (float(wakeup_Time[datetime.now().month-1])*60*60)-seconds
|
||||
else: #if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400-seconds+(float(wakeup_Time[datetime.now().month-1])*60*60)
|
||||
print ('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
logging.info('sleeping now '+str(sleep_time)+' seconds or until '+str(wakeup_Time[datetime.now().month-1])+'am!')
|
||||
sleep(sleep_time-10)
|
||||
|
||||
#wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds)+' < '+str((wakeup_Time[datetime.now().month-1]*60*60)))
|
||||
while(datetime.now() - midnight).seconds < (float(wakeup_Time[datetime.now().month-1])*60*60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number+'_'+str(datetime.now().strftime("%A %d. %B %Y"))+'.log'
|
||||
log_name = log_name.replace(" ","-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory+log_name,format='%(asctime)s [%(levelname)s] %(message)s',level=logging.DEBUG,datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for '+str(sleep_time)+' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for '+str(sleep_time)+' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
|
||||
if (internet == 'true')and(upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
logging.info('Skipping upload. Next upload in '+str(upload_every)+' pictures')
|
||||
print('Skipping upload. Next upload in',upload_every,'pictures')
|
||||
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
|
||||
533
Software/ZK_python/camera_v4_039.py
Normal file
533
Software/ZK_python/camera_v4_039.py
Normal file
@ -0,0 +1,533 @@
|
||||
# (c)2017 Jannik Seiler & Hendrik Schutter
|
||||
|
||||
# 039
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import http.client as httplib
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
from spidev import SpiDev
|
||||
from time import sleep
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
# get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open("/sys/class/thermal/thermal_zone0/temp")
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp) / 1000
|
||||
|
||||
|
||||
# uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except Exception as e:
|
||||
print('upload failed!')
|
||||
print(e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP] trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP] re-connecting successful!')
|
||||
logging.info('[FTP] re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP] upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except Exception as e9:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
return
|
||||
|
||||
|
||||
def checkDiskSpace():
|
||||
st = os.statvfs('/media/usb0')
|
||||
free = st.f_bavail * st.f_frsize
|
||||
total = st.f_blocks * st.f_frsize
|
||||
|
||||
freePercentaged = int(((st.f_bavail * st.f_frsize) / (st.f_blocks * st.f_frsize)) * 100)
|
||||
logging.info('Free disk space ' + str(freePercentaged) + ' %')
|
||||
print('Free disk space ', str(freePercentaged), ' %')
|
||||
if freePercentaged < 20 and freePercentaged > 10: logging.warning('Storage Drive nearly full!')
|
||||
if freePercentaged < 10: logging.critical('Storage Drive full, Backup Space in use!')
|
||||
return
|
||||
|
||||
|
||||
def checkCpuTemperature():
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature()) + ' C')
|
||||
return
|
||||
|
||||
|
||||
def readMPC(channel):
|
||||
adc = spi.xfer2([1, (8 + channel) << 4, 0])
|
||||
data = ((adc[1] & 3) << 8) + adc[2]
|
||||
return data
|
||||
|
||||
|
||||
def sleepToNextPicture():
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix > 0:
|
||||
print("sleeping now", time_sleep_unix, "seconds" + '\n')
|
||||
logging.info('sleeping now ' + str(time_sleep_unix) + ' seconds' + '\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
|
||||
def checkSystemVoltage():
|
||||
systemVoltage = (((readMPC(0) / 1023.0 * 3.3) * 6.62) * 0.95)
|
||||
print("System Input Voltage: %.2f" % systemVoltage, "Volt")
|
||||
logging.info('System Input Voltage: ' + str("%.2f" % systemVoltage) + ' Volt')
|
||||
if systemVoltage < 11.3 and systemVoltage > 9: logging.warning(
|
||||
'Low System Input Voltage! Maybe bad power supply or no sun.')
|
||||
if systemVoltage < 9: logging.critical('Very low System Input Voltage! Bad power supply or no sun.')
|
||||
return
|
||||
|
||||
|
||||
def reconnectToInternet():
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
print('Server is not online!')
|
||||
logging.info('Internet connection established')
|
||||
logging.error('Server is not online!')
|
||||
global interntTmp
|
||||
interntTmp = 'true'
|
||||
#checkConnectionToFTPServer()
|
||||
return 'true'
|
||||
except Exception as e2:
|
||||
conn.close()
|
||||
print('no Internet connection')
|
||||
print('trying to reconnect to internet')
|
||||
logging.error('no Internet connection!')
|
||||
logging.info('trying to reconnect to internet')
|
||||
if enable_modem == 'true':
|
||||
print('[MODEM] no UMTS connection')
|
||||
logging.error('[MODEM] no UMTS connection')
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/modem3g/sakis3g status')
|
||||
print('[MODEM] Network Status: ' + stdoutdata)
|
||||
logging.info('[MODEM] Network Status: ' + stdoutdata)
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[MODEM] disconnected')
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[MODEM] reconnection successful')
|
||||
logging.info(stdoutdata)
|
||||
sleep(10)
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
logging.info('Internet connection established')
|
||||
return 'true'
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e5))
|
||||
logging.error(str(e5))
|
||||
return 'false'
|
||||
except Exception as e4:
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
return 'false'
|
||||
else:
|
||||
print('LAN or WLAN not connected!')
|
||||
logging.error('LAN or WLAN not connected!')
|
||||
return 'false'
|
||||
|
||||
def checkConnectionToFTPServer():
|
||||
try:
|
||||
# ping ftp url instead something else
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
try:
|
||||
global ftp
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
global internetTmp
|
||||
internetTmp = 'true'
|
||||
global upload_every
|
||||
upload_every = upload_only
|
||||
except Exception as ea:
|
||||
print('no internet or ftp connection trying to reconnect later!')
|
||||
logging.error('no internet or ftp connection trying to reconnect later!')
|
||||
print('Server connection established')
|
||||
logging.info('Server connection established')
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('Server connection not established')
|
||||
logging.info('Server connection not established')
|
||||
reconnectToInternet()
|
||||
|
||||
return
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
# ioBoard
|
||||
piezo = 25
|
||||
bootSwitch = 17
|
||||
|
||||
version = 'starting camera version 039'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
internet = configParser.get('config', 'internet')
|
||||
modem_apn = configParser.get('config', 'modem_apn')
|
||||
upload_only = int(configParser.get('config', 'upload_only'))
|
||||
interval = int(configParser.get('config', 'interval'))
|
||||
ioBoard = configParser.get('config', 'I/O_Board')
|
||||
mute = configParser.get('config', 'mute')
|
||||
wakeup_Time = str(configParser.get('config', 'wakeup_Time')).split(',')
|
||||
bed_Time = str(configParser.get('config', 'bed_Time')).split(',')
|
||||
print('done!')
|
||||
|
||||
print('initializing logger...')
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
logging.info(version)
|
||||
print('done')
|
||||
print('reading picture number...')
|
||||
try:
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
except Exception as ea:
|
||||
print('No picture_Number.txt found. Creating new .. ')
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(0))
|
||||
f.close()
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
logging.info('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('done, picture number is:', str(picture_number))
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
upload_every = upload_only
|
||||
internetTmp = internet
|
||||
|
||||
|
||||
if ioBoard == "true":
|
||||
print('Running with the nice IO board!')
|
||||
spi = SpiDev()
|
||||
spi.open(0, 0)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setup(piezo, GPIO.OUT)
|
||||
GPIO.setup(bootSwitch, GPIO.IN)
|
||||
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera.resolution = (3280, 2464) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.start_preview()
|
||||
# camera.start_preview(fullscreen=False, window = (100, 20, 960, 720))
|
||||
print('---starting sharpness tool---')
|
||||
print('--------normal output--------')
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
sleep(5)
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera.stop_preview()
|
||||
print('---------zoom output---------')
|
||||
camera.crop = (0.5, 0.5, 0.3, 0.4)
|
||||
camera.start_preview()
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
else:
|
||||
camera.stop_preview()
|
||||
if mute == "false":
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(1)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
else:
|
||||
print('Running without the nice IO board!')
|
||||
|
||||
if internetTmp == 'true':
|
||||
print('Running in Online mode, internet connection is required')
|
||||
if enable_modem == 'true': reconnectToInternet()
|
||||
try:
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
except Exception as ea:
|
||||
print('no internet or ftp connection on startup trying to reconnect later!')
|
||||
logging.error('no internet or ftp connection on startup trying to reconnect later!')
|
||||
internetTmp = 'false'
|
||||
else:
|
||||
print('Running in Offline mode, no internet connection is required')
|
||||
|
||||
# camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
# camera.shutter_speed = 500000
|
||||
camera.resolution = (3280, 2464) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.exposure_mode = 'auto'
|
||||
camera.crop = (0, 0, 0, 0)
|
||||
|
||||
# camera.brightness = 50 #0 bis 100; default 50
|
||||
# camera.contrast = 0 #-100 bis 100; default 0
|
||||
# camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
# camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
# camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
|
||||
|
||||
# main programm (endless loop)
|
||||
while 1:
|
||||
time_next_unix = time.time() + interval # time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) # get time for picture_name
|
||||
time_name = time_name.replace(" ", "_")
|
||||
time_name = time_name.replace(":", "-")
|
||||
picture_name = camera_number + '_' + str(picture_number).zfill(6) + '_' + time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print("Time:", time_name)
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = 'interval capture'
|
||||
|
||||
if mute == "false": GPIO.output(piezo, GPIO.HIGH)
|
||||
print('Capturing image')
|
||||
logging.info('[Camera] Capturing image')
|
||||
camera.capture(picture_path) # capture image and save to picture_path (picture_directory + picture_name)
|
||||
if mute == "false": GPIO.output(piezo, GPIO.LOW)
|
||||
|
||||
picture_number += 1 # increase picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print('Picture size:', os.path.getsize(picture_path), "Byte")
|
||||
logging.info('Picture size: ' + str(os.path.getsize(picture_path)) + ' Byte')
|
||||
checkDiskSpace()
|
||||
if ioBoard == "true": checkSystemVoltage()
|
||||
if os.path.getsize(picture_path) < picture_size:
|
||||
print('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds # seconds since midnight
|
||||
if seconds1 > float(wakeup_Time[datetime.now().month - 1]) * 60 * 60 and seconds1 < float(bed_Time[
|
||||
datetime.now().month - 1]) * 60 * 60: # if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
print("uploadTimer", upload_every)
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
else:
|
||||
os.remove(picture_path) # deleting picture because it's night!
|
||||
picture_number -= 1 # decrease picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
# uploading log file
|
||||
print('skipping picture upload!')
|
||||
print('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': logging.info('uploading todays log befor going to sleep!')
|
||||
if internetTmp == 'true':
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e:
|
||||
print('upload failed!')
|
||||
print(e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('[FTP] re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e8:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
try:
|
||||
print()
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print('[FTP] re-connecting failed!')
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('could not change ftp directory !')
|
||||
logging.error('could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
# sleep until next morning
|
||||
print('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds # seconds since midnight
|
||||
if seconds < (
|
||||
float(wakeup_Time[
|
||||
datetime.now().month - 1]) * 60 * 60): # if time between 0am and wakeup_Time
|
||||
sleep_time = (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60) - seconds
|
||||
else: # if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400 - seconds + (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60)
|
||||
print('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
logging.info('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
sleep(sleep_time - 10)
|
||||
|
||||
# wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds) + ' < ' + str(
|
||||
(wakeup_Time[datetime.now().month - 1] * 60 * 60)))
|
||||
while (datetime.now() - midnight).seconds < (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for ' + str(sleep_time) + ' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for ' + str(sleep_time) + ' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
|
||||
if internet == 'true' and internetTmp == 'false':
|
||||
checkConnectionToFTPServer()
|
||||
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
|
||||
|
||||
|
||||
535
Software/ZK_python/camera_v4_040.py
Normal file
535
Software/ZK_python/camera_v4_040.py
Normal file
@ -0,0 +1,535 @@
|
||||
# (c)2017 Jannik Seiler & Hendrik Schutter
|
||||
|
||||
# 040
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import http.client as httplib
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
from spidev import SpiDev
|
||||
from time import sleep
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
# get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open("/sys/class/thermal/thermal_zone0/temp")
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp) / 1000
|
||||
|
||||
|
||||
# uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('upload successful!')
|
||||
except Exception as e:
|
||||
print('upload failed!')
|
||||
print(e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP] trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP] re-connecting successful!')
|
||||
logging.info('[FTP] re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP] upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except Exception as e9:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
return
|
||||
|
||||
|
||||
def checkDiskSpace():
|
||||
st = os.statvfs('/media/usb0')
|
||||
free = st.f_bavail * st.f_frsize
|
||||
total = st.f_blocks * st.f_frsize
|
||||
|
||||
freePercentaged = int(((st.f_bavail * st.f_frsize) / (st.f_blocks * st.f_frsize)) * 100)
|
||||
logging.info('Free disk space ' + str(freePercentaged) + ' %')
|
||||
print('Free disk space ', str(freePercentaged), ' %')
|
||||
if freePercentaged < 20 and freePercentaged > 10: logging.warning('Storage Drive nearly full!')
|
||||
if freePercentaged < 10: logging.critical('Storage Drive full, Backup Space in use!')
|
||||
return
|
||||
|
||||
|
||||
def checkCpuTemperature():
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
else:
|
||||
logging.info('Temperature: ' + str(getCpuTemperature()) + ' C')
|
||||
return
|
||||
|
||||
|
||||
def readMPC(channel):
|
||||
adc = spi.xfer2([1, (8 + channel) << 4, 0])
|
||||
data = ((adc[1] & 3) << 8) + adc[2]
|
||||
return data
|
||||
|
||||
|
||||
def sleepToNextPicture():
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix > 0:
|
||||
print("sleeping now", time_sleep_unix, "seconds" + '\n')
|
||||
logging.info('sleeping now ' + str(time_sleep_unix) + ' seconds' + '\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
|
||||
def checkSystemVoltage():
|
||||
systemVoltage = (((readMPC(0) / 1023.0 * 3.3) * 6.62) * 0.95)
|
||||
print("System Input Voltage: %.2f" % systemVoltage, "Volt")
|
||||
logging.info('System Input Voltage: ' + str("%.2f" % systemVoltage) + ' Volt')
|
||||
if systemVoltage < 11.3 and systemVoltage > 9: logging.warning(
|
||||
'Low System Input Voltage! Maybe bad power supply or no sun.')
|
||||
if systemVoltage < 9: logging.critical('Very low System Input Voltage! Bad power supply or no sun.')
|
||||
return
|
||||
|
||||
|
||||
def reconnectToInternet():
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
print('Server is maybe not online!')
|
||||
logging.info('Internet connection established')
|
||||
logging.error('Server maybe is not online!')
|
||||
global interntTmp
|
||||
interntTmp = 'true'
|
||||
#checkConnectionToFTPServer()
|
||||
return 'true'
|
||||
except Exception as e2:
|
||||
conn.close()
|
||||
print('no Internet connection')
|
||||
print('trying to reconnect to internet')
|
||||
logging.error('no Internet connection!')
|
||||
logging.info('trying to reconnect to internet')
|
||||
if enable_modem == 'true':
|
||||
print('[MODEM] no UMTS connection')
|
||||
logging.error('[MODEM] no UMTS connection')
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/modem3g/sakis3g status')
|
||||
print('[MODEM] Network Status: ' + stdoutdata)
|
||||
logging.info('[MODEM] Network Status: ' + stdoutdata)
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[MODEM] disconnected')
|
||||
sleep(20)
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[MODEM] reconnection successful attempt')
|
||||
logging.info('[MODEM] reconnection successful attempt')
|
||||
logging.info(stdoutdata)
|
||||
sleep(10)
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
logging.info('Internet connection established')
|
||||
return 'true'
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e5))
|
||||
logging.error(str(e5))
|
||||
return 'false'
|
||||
except Exception as e4:
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
return 'false'
|
||||
else:
|
||||
print('LAN or WLAN not connected!')
|
||||
logging.error('LAN or WLAN not connected!')
|
||||
return 'false'
|
||||
|
||||
def checkConnectionToFTPServer():
|
||||
try:
|
||||
# ping ftp url instead something else
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
try:
|
||||
global ftp
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
global internetTmp
|
||||
internetTmp = 'true'
|
||||
global upload_every
|
||||
upload_every = upload_only
|
||||
except Exception as ea:
|
||||
print('no internet or ftp connection trying to reconnect later!')
|
||||
logging.error('no internet or ftp connection trying to reconnect later!')
|
||||
print('Server connection established')
|
||||
logging.info('Server connection established')
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('Server connection not established')
|
||||
logging.info('Server connection not established')
|
||||
reconnectToInternet()
|
||||
|
||||
return
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
# ioBoard
|
||||
piezo = 25
|
||||
bootSwitch = 17
|
||||
|
||||
version = 'starting camera version 040'
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
internet = configParser.get('config', 'internet')
|
||||
modem_apn = configParser.get('config', 'modem_apn')
|
||||
upload_only = int(configParser.get('config', 'upload_only'))
|
||||
interval = int(configParser.get('config', 'interval'))
|
||||
ioBoard = configParser.get('config', 'I/O_Board')
|
||||
mute = configParser.get('config', 'mute')
|
||||
wakeup_Time = str(configParser.get('config', 'wakeup_Time')).split(',')
|
||||
bed_Time = str(configParser.get('config', 'bed_Time')).split(',')
|
||||
print('done!')
|
||||
|
||||
print('initializing logger...')
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
logging.info(version)
|
||||
print('done')
|
||||
print('reading picture number...')
|
||||
try:
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
except Exception as ea:
|
||||
print('No picture_Number.txt found. Creating new .. ')
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(0))
|
||||
f.close()
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
logging.info('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('done, picture number is:', str(picture_number))
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
upload_every = upload_only
|
||||
internetTmp = internet
|
||||
|
||||
|
||||
if ioBoard == "true":
|
||||
print('Running with the nice IO board!')
|
||||
spi = SpiDev()
|
||||
spi.open(0, 0)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setup(piezo, GPIO.OUT)
|
||||
GPIO.setup(bootSwitch, GPIO.IN)
|
||||
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera.resolution = (3280, 2464) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.start_preview()
|
||||
# camera.start_preview(fullscreen=False, window = (100, 20, 960, 720))
|
||||
print('---starting sharpness tool---')
|
||||
print('--------normal output--------')
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
sleep(5)
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera.stop_preview()
|
||||
print('---------zoom output---------')
|
||||
camera.crop = (0.5, 0.5, 0.3, 0.4)
|
||||
camera.start_preview()
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
else:
|
||||
camera.stop_preview()
|
||||
if mute == "false":
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(1)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
else:
|
||||
print('Running without the nice IO board!')
|
||||
|
||||
if internetTmp == 'true':
|
||||
print('Running in Online mode, internet connection is required')
|
||||
if enable_modem == 'true': reconnectToInternet()
|
||||
try:
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
except Exception as ea:
|
||||
print('no internet or ftp connection on startup trying to reconnect later!')
|
||||
logging.error('no internet or ftp connection on startup trying to reconnect later!')
|
||||
internetTmp = 'false'
|
||||
else:
|
||||
print('Running in Offline mode, no internet connection is required')
|
||||
|
||||
# camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
# camera.shutter_speed = 500000
|
||||
camera.resolution = (3280, 2464) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.exposure_mode = 'auto'
|
||||
camera.crop = (0, 0, 0, 0)
|
||||
|
||||
# camera.brightness = 50 #0 bis 100; default 50
|
||||
# camera.contrast = 0 #-100 bis 100; default 0
|
||||
# camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
# camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
# camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
|
||||
|
||||
# main programm (endless loop)
|
||||
while 1:
|
||||
time_next_unix = time.time() + interval # time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) # get time for picture_name
|
||||
time_name = time_name.replace(" ", "_")
|
||||
time_name = time_name.replace(":", "-")
|
||||
picture_name = camera_number + '_' + str(picture_number).zfill(6) + '_' + time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print("Time:", time_name)
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = 'interval capture'
|
||||
|
||||
if mute == "false": GPIO.output(piezo, GPIO.HIGH)
|
||||
print('Capturing image')
|
||||
logging.info('[Camera] Capturing image')
|
||||
camera.capture(picture_path) # capture image and save to picture_path (picture_directory + picture_name)
|
||||
if mute == "false": GPIO.output(piezo, GPIO.LOW)
|
||||
|
||||
picture_number += 1 # increase picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print('Picture size:', os.path.getsize(picture_path), "Byte")
|
||||
logging.info('Picture size: ' + str(os.path.getsize(picture_path)) + ' Byte')
|
||||
checkDiskSpace()
|
||||
if ioBoard == "true": checkSystemVoltage()
|
||||
if os.path.getsize(picture_path) < picture_size:
|
||||
print('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds # seconds since midnight
|
||||
if seconds1 > float(wakeup_Time[datetime.now().month - 1]) * 60 * 60 and seconds1 < float(bed_Time[
|
||||
datetime.now().month - 1]) * 60 * 60: # if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
print("uploadTimer", upload_every)
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
else:
|
||||
os.remove(picture_path) # deleting picture because it's night!
|
||||
picture_number -= 1 # decrease picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
# uploading log file
|
||||
print('skipping picture upload!')
|
||||
print('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': logging.info('uploading todays log befor going to sleep!')
|
||||
if internetTmp == 'true':
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e:
|
||||
print('upload failed!')
|
||||
print(e)
|
||||
logging.error('upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('[FTP] re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e8:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
try:
|
||||
print()
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print('[FTP] re-connecting failed!')
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('could not change ftp directory !')
|
||||
logging.error('could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
# sleep until next morning
|
||||
print('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds # seconds since midnight
|
||||
if seconds < (
|
||||
float(wakeup_Time[
|
||||
datetime.now().month - 1]) * 60 * 60): # if time between 0am and wakeup_Time
|
||||
sleep_time = (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60) - seconds
|
||||
else: # if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400 - seconds + (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60)
|
||||
print('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
logging.info('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
sleep(sleep_time - 10)
|
||||
|
||||
# wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds) + ' < ' + str(
|
||||
(wakeup_Time[datetime.now().month - 1] * 60 * 60)))
|
||||
while (datetime.now() - midnight).seconds < (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for ' + str(sleep_time) + ' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for ' + str(sleep_time) + ' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
|
||||
if internet == 'true' and internetTmp == 'false':
|
||||
checkConnectionToFTPServer()
|
||||
|
||||
checkCpuTemperature()
|
||||
sleepToNextPicture()
|
||||
|
||||
|
||||
|
||||
557
Software/ZK_python/camera_v4_041.py
Normal file
557
Software/ZK_python/camera_v4_041.py
Normal file
@ -0,0 +1,557 @@
|
||||
# (c)2017 Jannik Seiler & Hendrik Schutter
|
||||
|
||||
# 041
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import http.client as httplib
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
from spidev import SpiDev
|
||||
from time import sleep
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
# get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open("/sys/class/thermal/thermal_zone0/temp")
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp) / 1000
|
||||
|
||||
|
||||
# uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('[Upload] successful!')
|
||||
except Exception as e:
|
||||
print('upload failed!')
|
||||
print(e)
|
||||
logging.error('[Upload] failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP] trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP] re-connecting successful!')
|
||||
logging.info('[FTP] re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP] upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except Exception as e9:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
return
|
||||
|
||||
|
||||
def checkDiskSpace():
|
||||
st = os.statvfs('/media/usb0')
|
||||
free = st.f_bavail * st.f_frsize
|
||||
total = st.f_blocks * st.f_frsize
|
||||
|
||||
freePercentaged = int(((st.f_bavail * st.f_frsize) / (st.f_blocks * st.f_frsize)) * 100)
|
||||
logging.info('[Disk] Free space: ' + str(freePercentaged) + ' %')
|
||||
print('Free disk space ', str(freePercentaged), ' %')
|
||||
if freePercentaged < 20 and freePercentaged > 10: logging.warning('[Disk] Storage Drive nearly full!')
|
||||
if freePercentaged < 10: logging.critical('[Disk] Storage Drive full, Backup Space in use!')
|
||||
return
|
||||
|
||||
|
||||
def checkCpu():
|
||||
cpuUsage = (os.popen("top -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip())
|
||||
cpuUsage = (float(cpuUsage.replace(',', '.')))*25
|
||||
print('[CPU] Usage: ',str("%.2f" % cpuUsage),' %')
|
||||
logging.info('[CPU] Usage: '+ str("%.2f" % cpuUsage) + ' %')
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('[CPU] Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('[CPU] Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('[CPU] Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('[CPU] Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
else:
|
||||
logging.info('[CPU] Temperature: ' + str(getCpuTemperature()) + ' C')
|
||||
return
|
||||
|
||||
|
||||
def readMPC(channel):
|
||||
adc = spi.xfer2([1, (8 + channel) << 4, 0])
|
||||
data = ((adc[1] & 3) << 8) + adc[2]
|
||||
return data
|
||||
|
||||
|
||||
def sleepToNextPicture():
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix > 0:
|
||||
print("sleeping now", time_sleep_unix, "seconds" + '\n')
|
||||
logging.info('sleeping now ' + str(time_sleep_unix) + ' seconds' + '\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
|
||||
def checkSystemVoltage():
|
||||
systemVoltage = (((readMPC(0) / 1023.0 * 3.3) * 6.62) * 0.95)
|
||||
print("System Input Voltage: %.2f" % systemVoltage, "Volt")
|
||||
logging.info('[Voltage] ' + str("%.2f" % systemVoltage) + ' Volt')
|
||||
if systemVoltage < 11.3 and systemVoltage > 9:
|
||||
logging.warning('[Voltage] Low System Input Voltage! Maybe bad power supply or no sun.')
|
||||
if tvOut == 'auto':
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/tvservice -o ')
|
||||
print('[TV Out] Status: ' + stdoutdata)
|
||||
logging.info('[TV Out] Status: ' + stdoutdata)
|
||||
if systemVoltage < 9: logging.critical('[Voltage] Very low System Input Voltage! Bad power supply or no sun.')
|
||||
return
|
||||
|
||||
|
||||
def reconnectToInternet():
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
print('Server is maybe not online!')
|
||||
logging.info('Internet connection established')
|
||||
logging.error('Server maybe is not online!')
|
||||
global interntTmp
|
||||
interntTmp = 'true'
|
||||
#checkConnectionToFTPServer()
|
||||
return 'true'
|
||||
except Exception as e2:
|
||||
conn.close()
|
||||
print('no Internet connection')
|
||||
print('trying to reconnect to internet')
|
||||
logging.error('no Internet connection!')
|
||||
logging.info('trying to reconnect to internet')
|
||||
if enable_modem == 'true':
|
||||
print('[MODEM] no UMTS connection')
|
||||
logging.error('[MODEM] no UMTS connection')
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/modem3g/sakis3g status')
|
||||
print('[MODEM] Network Status: ' + stdoutdata)
|
||||
logging.info('[MODEM] Network Status: ' + stdoutdata)
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[MODEM] disconnected')
|
||||
sleep(20)
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[MODEM] reconnection successful attempt')
|
||||
logging.info('[MODEM] reconnection successful attempt')
|
||||
logging.info(stdoutdata)
|
||||
sleep(10)
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
logging.info('Internet connection established')
|
||||
return 'true'
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e5))
|
||||
logging.error(str(e5))
|
||||
return 'false'
|
||||
except Exception as e4:
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
return 'false'
|
||||
else:
|
||||
print('LAN or WLAN not connected!')
|
||||
logging.error('LAN or WLAN not connected!')
|
||||
return 'false'
|
||||
|
||||
def checkConnectionToFTPServer():
|
||||
try:
|
||||
# ping ftp url instead something else
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
try:
|
||||
global ftp
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP] New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('[FTP] New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
global internetTmp
|
||||
internetTmp = 'true'
|
||||
global upload_every
|
||||
upload_every = upload_only
|
||||
except Exception as ea:
|
||||
print('[FTP] no internet or ftp connection trying to reconnect later!')
|
||||
logging.error('[FTP] no internet or ftp connection trying to reconnect later!')
|
||||
print('[FTP] Server connection established')
|
||||
logging.info('[FTP] Server connection established')
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('[FTP] Server connection not established')
|
||||
logging.info('[FTP] Server connection not established')
|
||||
reconnectToInternet()
|
||||
|
||||
return
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
# ioBoard
|
||||
piezo = 25
|
||||
bootSwitch = 17
|
||||
|
||||
|
||||
version = 'starting camera version 041'
|
||||
print('Copyright CopterSicht - info@coptersicht.de 2015-2017')
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
internet = configParser.get('config', 'internet')
|
||||
modem_apn = configParser.get('config', 'modem_apn')
|
||||
upload_only = int(configParser.get('config', 'upload_only'))
|
||||
interval = int(configParser.get('config', 'interval'))
|
||||
ioBoard = configParser.get('config', 'I/O_Board')
|
||||
mute = configParser.get('config', 'mute')
|
||||
wakeup_Time = str(configParser.get('config', 'wakeup_Time')).split(',')
|
||||
bed_Time = str(configParser.get('config', 'bed_Time')).split(',')
|
||||
tvOut = configParser.get('config', 'TV_Output')
|
||||
print('done!')
|
||||
|
||||
print('initializing logger...')
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
logging.info(version)
|
||||
print('done')
|
||||
print('reading picture number...')
|
||||
try:
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
except Exception as ea:
|
||||
print('No picture_Number.txt found. Creating new .. ')
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(0))
|
||||
f.close()
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
logging.info('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('done, picture number is:', str(picture_number))
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
|
||||
sleep(15)
|
||||
|
||||
#camera = PiCamera()
|
||||
upload_every = upload_only
|
||||
internetTmp = internet
|
||||
|
||||
|
||||
if ioBoard == "true":
|
||||
print('Running with the nice IO board!')
|
||||
spi = SpiDev()
|
||||
spi.open(0, 0)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setup(piezo, GPIO.OUT)
|
||||
GPIO.setup(bootSwitch, GPIO.IN)
|
||||
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera = PiCamera()
|
||||
camera.resolution = (3280, 2464) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.start_preview()
|
||||
# camera.start_preview(fullscreen=False, window = (100, 20, 960, 720))
|
||||
print('---starting sharpness tool---')
|
||||
print('--------normal output--------')
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
sleep(5)
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera.stop_preview()
|
||||
print('---------zoom output---------')
|
||||
camera.crop = (0.5, 0.5, 0.3, 0.4)
|
||||
camera.start_preview()
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
else:
|
||||
camera.stop_preview()
|
||||
camera.close()
|
||||
if mute == "false":
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(1)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
else:
|
||||
print('Running without the nice IO board!')
|
||||
|
||||
|
||||
if tvOut == 'false':
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/tvservice -o ')
|
||||
print('[TV Out] Status: ' + stdoutdata)
|
||||
logging.info('[TV Out] Status: ' + stdoutdata)
|
||||
|
||||
if internetTmp == 'true':
|
||||
print('Running in Online mode, internet connection is required')
|
||||
if enable_modem == 'true': reconnectToInternet()
|
||||
try:
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
except Exception as ea:
|
||||
print('no internet or ftp connection on startup trying to reconnect later!')
|
||||
logging.error('no internet or ftp connection on startup trying to reconnect later!')
|
||||
internetTmp = 'false'
|
||||
else:
|
||||
print('Running in Offline mode, no internet connection is required')
|
||||
|
||||
# camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
# camera.shutter_speed = 500000
|
||||
|
||||
|
||||
# camera.brightness = 50 #0 bis 100; default 50
|
||||
# camera.contrast = 0 #-100 bis 100; default 0
|
||||
# camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
# camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
# camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
|
||||
|
||||
# main programm (endless loop)
|
||||
while 1:
|
||||
time_next_unix = time.time() + interval # time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) # get time for picture_name
|
||||
time_name = time_name.replace(" ", "_")
|
||||
time_name = time_name.replace(":", "-")
|
||||
picture_name = camera_number + '_' + str(picture_number).zfill(6) + '_' + time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print("Time:", time_name)
|
||||
camera = PiCamera()
|
||||
camera.resolution = (3280, 2464) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.exposure_mode = 'auto'
|
||||
camera.crop = (0, 0, 0, 0)
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2017 CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = 'interval capture'
|
||||
|
||||
if mute == "false": GPIO.output(piezo, GPIO.HIGH)
|
||||
print('Capturing image')
|
||||
logging.info('[Camera] Capturing image')
|
||||
camera.capture(picture_path) # capture image and save to picture_path (picture_directory + picture_name)
|
||||
camera.close()
|
||||
if mute == "false": GPIO.output(piezo, GPIO.LOW)
|
||||
|
||||
picture_number += 1 # increase picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print('Picture size:', os.path.getsize(picture_path), "Byte")
|
||||
logging.info('[Camera] Picture size: ' + str(os.path.getsize(picture_path)) + ' Byte')
|
||||
checkDiskSpace()
|
||||
if ioBoard == "true": checkSystemVoltage()
|
||||
if os.path.getsize(picture_path) < picture_size:
|
||||
print('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds # seconds since midnight
|
||||
if seconds1 > float(wakeup_Time[datetime.now().month - 1]) * 60 * 60 and seconds1 < float(bed_Time[
|
||||
datetime.now().month - 1]) * 60 * 60: # if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
print("uploadTimer", upload_every)
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
checkCpu()
|
||||
sleepToNextPicture()
|
||||
else:
|
||||
os.remove(picture_path) # deleting picture because it's night!
|
||||
picture_number -= 1 # decrease picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
# uploading log file
|
||||
print('skipping picture upload!')
|
||||
print('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': logging.info('uploading todays log befor going to sleep!')
|
||||
if internetTmp == 'true':
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('[FTP] uploaded log-file successful!')
|
||||
logging.info('[FTP] uploaded log-file successful!')
|
||||
except Exception as e:
|
||||
print('[FTP] upload failed!')
|
||||
print(e)
|
||||
logging.error('[FTP] upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('[FTP] re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e8:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
try:
|
||||
print()
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('[FTP] uploaded log-file successful!')
|
||||
logging.info('[FTP] uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print('[FTP] re-connecting failed!')
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('[FTP] could not change ftp directory !')
|
||||
logging.error('[FTP] could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
# sleep until next morning
|
||||
print('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds # seconds since midnight
|
||||
if seconds < (
|
||||
float(wakeup_Time[
|
||||
datetime.now().month - 1]) * 60 * 60): # if time between 0am and wakeup_Time
|
||||
sleep_time = (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60) - seconds
|
||||
else: # if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400 - seconds + (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60)
|
||||
print('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
logging.info('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
sleep(sleep_time - 10)
|
||||
|
||||
# wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds) + ' < ' + str(
|
||||
(wakeup_Time[datetime.now().month - 1] * 60 * 60)))
|
||||
while (datetime.now() - midnight).seconds < (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for ' + str(sleep_time) + ' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for ' + str(sleep_time) + ' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
|
||||
if internet == 'true' and internetTmp == 'false':
|
||||
checkConnectionToFTPServer()
|
||||
|
||||
checkCpu()
|
||||
sleepToNextPicture()
|
||||
|
||||
|
||||
|
||||
595
Software/ZK_python/camera_v4_042.py
Normal file
595
Software/ZK_python/camera_v4_042.py
Normal file
@ -0,0 +1,595 @@
|
||||
# (c)2017-2018 Jannik Seiler & Hendrik Schutter
|
||||
|
||||
# 042
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import http.client as httplib
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
from spidev import SpiDev
|
||||
import RPi.GPIO as GPIO
|
||||
import re
|
||||
import fcntl
|
||||
|
||||
# get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open("/sys/class/thermal/thermal_zone0/temp")
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp) / 1000
|
||||
|
||||
|
||||
# uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('[Upload] successful!')
|
||||
except Exception as e:
|
||||
print('upload failed!')
|
||||
print(e)
|
||||
logging.error('[Upload] failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP] trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP] re-connecting successful!')
|
||||
logging.info('[FTP] re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP] upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except Exception as e9:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
return
|
||||
|
||||
|
||||
def checkDiskSpace():
|
||||
st = os.statvfs('/media/usb0')
|
||||
free = st.f_bavail * st.f_frsize
|
||||
total = st.f_blocks * st.f_frsize
|
||||
|
||||
freePercentaged = int(((st.f_bavail * st.f_frsize) / (st.f_blocks * st.f_frsize)) * 100)
|
||||
logging.info('[Disk] Free space: ' + str(freePercentaged) + ' %')
|
||||
print('Free disk space ', str(freePercentaged), ' %')
|
||||
if freePercentaged < 20 and freePercentaged > 10: logging.warning('[Disk] Storage Drive nearly full!')
|
||||
if freePercentaged < 10: logging.critical('[Disk] Storage Drive full, Backup Space in use!')
|
||||
return
|
||||
|
||||
|
||||
def checkCpu():
|
||||
try:
|
||||
cpuUsage = (os.popen("top -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip())
|
||||
cpuUsage = (float(cpuUsage.replace(',', '.'))) * 25
|
||||
print('[CPU] Usage: ', str("%.2f" % cpuUsage), ' %')
|
||||
logging.info('[CPU] Usage: ' + str("%.2f" % cpuUsage) + ' %')
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('[CPU] Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('[CPU] Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('[CPU] Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('[CPU] Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
else:
|
||||
logging.info('[CPU] Temperature: ' + str(getCpuTemperature()) + ' C')
|
||||
return
|
||||
except Exception as e2:
|
||||
print('[CPU] ' + str(e2))
|
||||
logging.warning('[CPU] ' + str(e2))
|
||||
|
||||
def readMPC(channel):
|
||||
adc = spi.xfer2([1, (8 + channel) << 4, 0])
|
||||
data = ((adc[1] & 3) << 8) + adc[2]
|
||||
return data
|
||||
|
||||
def sleepToNextPicture():
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix > 0:
|
||||
print("sleeping now", time_sleep_unix, "seconds" + '\n')
|
||||
logging.info('sleeping now ' + str(time_sleep_unix) + ' seconds' + '\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
def checkSystemVoltage():
|
||||
systemVoltage = (((readMPC(0) / 1023.0 * 3.3) * 6.62) * 0.95)
|
||||
print("System Input Voltage: %.2f" % systemVoltage, "Volt")
|
||||
logging.info('[Voltage] ' + str("%.2f" % systemVoltage) + ' Volt')
|
||||
if systemVoltage < 11.3 and systemVoltage > 9:
|
||||
logging.warning('[Voltage] Low System Input Voltage! Maybe bad power supply or no sun.')
|
||||
if tvOut == 'auto':
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/tvservice -o ')
|
||||
print('[TV Out] Status: ' + stdoutdata)
|
||||
logging.info('[TV Out] Status: ' + stdoutdata)
|
||||
if systemVoltage < 9: logging.critical('[Voltage] Very low System Input Voltage! Bad power supply or no sun.')
|
||||
return
|
||||
|
||||
|
||||
def reconnectToInternet():
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
print('Server is maybe not online!')
|
||||
logging.info('Internet connection established')
|
||||
logging.error('Server maybe is not online!')
|
||||
global interntTmp
|
||||
interntTmp = 'true'
|
||||
#checkConnectionToFTPServer()
|
||||
return 'true'
|
||||
except Exception as e2:
|
||||
conn.close()
|
||||
print('no Internet connection')
|
||||
print('trying to reconnect to internet')
|
||||
logging.error('no Internet connection!')
|
||||
logging.info('trying to reconnect to internet')
|
||||
if enable_modem == 'true':
|
||||
print('[MODEM] no UMTS connection')
|
||||
logging.error('[MODEM] no UMTS connection')
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/modem3g/sakis3g status')
|
||||
print('[MODEM] Network Status: ' + stdoutdata)
|
||||
logging.info('[MODEM] Network Status: ' + stdoutdata)
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[MODEM] disconnected')
|
||||
sleep(20)
|
||||
resetModem()
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[MODEM] reconnection successful attempt')
|
||||
logging.info('[MODEM] reconnection successful attempt')
|
||||
logging.info(stdoutdata)
|
||||
sleep(10)
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
logging.info('Internet connection established')
|
||||
return 'true'
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e5))
|
||||
logging.error(str(e5))
|
||||
return 'false'
|
||||
except Exception as e4:
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
return 'false'
|
||||
else:
|
||||
print('LAN or WLAN not connected!')
|
||||
logging.error('LAN or WLAN not connected!')
|
||||
return 'false'
|
||||
|
||||
def checkConnectionToFTPServer():
|
||||
try:
|
||||
# ping ftp url instead something else
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
try:
|
||||
global ftp
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP] New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('[FTP] New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
global internetTmp
|
||||
internetTmp = 'true'
|
||||
global upload_every
|
||||
upload_every = upload_only
|
||||
except Exception as ea:
|
||||
print('[FTP] no internet or ftp connection trying to reconnect later!')
|
||||
logging.error('[FTP] no internet or ftp connection trying to reconnect later!')
|
||||
print('[FTP] Server connection established')
|
||||
logging.info('[FTP] Server connection established')
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('[FTP] Server connection not established')
|
||||
logging.info('[FTP] Server connection not established')
|
||||
reconnectToInternet()
|
||||
|
||||
return
|
||||
|
||||
def resetModem():
|
||||
try:
|
||||
lsusb_cmd = 'lsusb | grep {}'.format('Huawei')
|
||||
lsusb_out = subprocess.check_output(lsusb_cmd, shell=True)
|
||||
parts = re.search(r'Bus (?P<bus>\d+) Device (?P<dev>\d+): ID [:\d\w]+ (?P<desc>.*)$', str(lsusb_out))
|
||||
bus = parts.group('bus')
|
||||
dev = parts.group('dev')
|
||||
desc = parts.group('desc').strip()
|
||||
print('[Modem] Found device {} on bus {} for "{}"'.format(bus, dev, desc))
|
||||
f = open('/dev/bus/usb/{}/{}'.format(bus, dev), 'w', os.O_WRONLY)
|
||||
fcntl.ioctl(f, 21780, 0)
|
||||
sleep(15)
|
||||
print('[Modem] Reset successfully attempt')
|
||||
except Exception as ea:
|
||||
print('[Modem] Reset Error: ' + str(ea))
|
||||
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
# ioBoard
|
||||
piezo = 25
|
||||
bootSwitch = 17
|
||||
|
||||
version = 'starting camera version 042'
|
||||
print('Copyright CopterSicht - info@coptersicht.de 2015-' + str(datetime.now().year))
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
internet = configParser.get('config', 'internet')
|
||||
modem_apn = configParser.get('config', 'modem_apn')
|
||||
upload_only = int(configParser.get('config', 'upload_only'))
|
||||
interval = int(configParser.get('config', 'interval'))
|
||||
ioBoard = configParser.get('config', 'I/O_Board')
|
||||
mute = configParser.get('config', 'mute')
|
||||
wakeup_Time = str(configParser.get('config', 'wakeup_Time')).split(',')
|
||||
bed_Time = str(configParser.get('config', 'bed_Time')).split(',')
|
||||
tvOut = configParser.get('config', 'TV_Output')
|
||||
width = configParser.get('config', 'Width')
|
||||
height = configParser.get('config', 'Height')
|
||||
print('done!')
|
||||
|
||||
print('initializing logger...')
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
try:
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
except Exception as er:
|
||||
print('[Logger] Could not create .log' + str(er))
|
||||
print('[USB] Could not find USB storage!')
|
||||
while 1:
|
||||
checkConnectionToFTPServer()
|
||||
print('[Timlapse Core] Waiting for maintenance!')
|
||||
sleep(3600)
|
||||
logging.info(version)
|
||||
print('done')
|
||||
print('reading picture number...')
|
||||
try:
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
except Exception as ea:
|
||||
print('No picture_Number.txt found. Creating new .. ')
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(0))
|
||||
f.close()
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
logging.info('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('done, picture number is:', str(picture_number))
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
|
||||
sleep(15)
|
||||
|
||||
#camera = PiCamera()
|
||||
upload_every = upload_only
|
||||
internetTmp = internet
|
||||
|
||||
if ioBoard == "true":
|
||||
print('Running with the nice IO board!')
|
||||
spi = SpiDev()
|
||||
spi.open(0, 0)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setup(piezo, GPIO.OUT)
|
||||
GPIO.setup(bootSwitch, GPIO.IN)
|
||||
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera = PiCamera()
|
||||
camera.resolution = (3280, 2464) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.awb_mode = 'auto'
|
||||
camera.start_preview()
|
||||
# camera.start_preview(fullscreen=False, window = (100, 20, 960, 720))
|
||||
print('---starting sharpness tool---')
|
||||
print('--------normal output--------')
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
sleep(5)
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera.stop_preview()
|
||||
print('---------zoom output---------')
|
||||
camera.crop = (0.5, 0.5, 0.3, 0.4)
|
||||
camera.start_preview()
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
else:
|
||||
camera.stop_preview()
|
||||
camera.close()
|
||||
if mute == "false":
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(1)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
else:
|
||||
print('Running without the nice IO board!')
|
||||
|
||||
|
||||
if tvOut == 'false':
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/tvservice -o ')
|
||||
print('[TV Out] Status: ' + stdoutdata)
|
||||
logging.info('[TV Out] Status: ' + stdoutdata)
|
||||
|
||||
if internetTmp == 'true':
|
||||
print('Running in Online mode, internet connection is required')
|
||||
if enable_modem == 'true': reconnectToInternet()
|
||||
try:
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
except Exception as ea:
|
||||
print('no internet or ftp connection on startup trying to reconnect later!')
|
||||
logging.error('no internet or ftp connection on startup trying to reconnect later!')
|
||||
internetTmp = 'false'
|
||||
else:
|
||||
print('Running in Offline mode, no internet connection is required')
|
||||
|
||||
# camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
# camera.shutter_speed = 500000
|
||||
|
||||
|
||||
# camera.brightness = 50 #0 bis 100; default 50
|
||||
# camera.contrast = 0 #-100 bis 100; default 0
|
||||
# camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
# camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
# camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
print('[Camera] Resolution: ' + width + 'x' + height)
|
||||
logging.info('[Camera] Resolution: ' + width + 'x' + height)
|
||||
|
||||
|
||||
# main programm (endless loop)
|
||||
while 1:
|
||||
try:
|
||||
time_next_unix = time.time() + interval # time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) # get time for picture_name
|
||||
time_name = time_name.replace(" ", "_")
|
||||
time_name = time_name.replace(":", "-")
|
||||
picture_name = camera_number + '_' + str(picture_number).zfill(6) + '_' + time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print("Time:", time_name)
|
||||
camera = PiCamera()
|
||||
camera.resolution = (int(width), int(height)) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.exposure_mode = 'auto'
|
||||
camera.awb_mode = 'auto'
|
||||
camera.crop = (0, 0, 0, 0)
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) ' + str(datetime.now().year) + ' CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = 'interval capture'
|
||||
|
||||
if mute == "false": GPIO.output(piezo, GPIO.HIGH)
|
||||
print('Capturing image')
|
||||
logging.info('[Camera] Capturing image')
|
||||
camera.capture(picture_path) # capture image and save to picture_path (picture_directory + picture_name)
|
||||
camera.close()
|
||||
if mute == "false": GPIO.output(piezo, GPIO.LOW)
|
||||
picture_number += 1 # increase picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print('Picture size:', os.path.getsize(picture_path), "Byte")
|
||||
logging.info('[Camera] Picture size: ' + str(os.path.getsize(picture_path)) + ' Byte')
|
||||
checkDiskSpace()
|
||||
if ioBoard == "true": checkSystemVoltage()
|
||||
if os.path.getsize(picture_path) < picture_size:
|
||||
print('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds # seconds since midnight
|
||||
if seconds1 > float(wakeup_Time[datetime.now().month - 1]) * 60 * 60 and seconds1 < float(bed_Time[
|
||||
datetime.now().month - 1]) * 60 * 60: # if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
print("uploadTimer", upload_every)
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
checkCpu()
|
||||
sleepToNextPicture()
|
||||
else:
|
||||
os.remove(picture_path) # deleting picture because it's night!
|
||||
picture_number -= 1 # decrease picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
# uploading log file
|
||||
print('skipping picture upload!')
|
||||
print('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': logging.info('uploading todays log befor going to sleep!')
|
||||
if internetTmp == 'true':
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('[FTP] uploaded log-file successful!')
|
||||
logging.info('[FTP] uploaded log-file successful!')
|
||||
except Exception as e:
|
||||
print('[FTP] upload failed!')
|
||||
print(e)
|
||||
logging.error('[FTP] upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('[FTP] re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e8:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
try:
|
||||
print()
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('[FTP] uploaded log-file successful!')
|
||||
logging.info('[FTP] uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print('[FTP] re-connecting failed!')
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('[FTP] could not change ftp directory !')
|
||||
logging.error('[FTP] could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
# sleep until next morning
|
||||
print('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds # seconds since midnight
|
||||
if seconds < (
|
||||
float(wakeup_Time[
|
||||
datetime.now().month - 1]) * 60 * 60): # if time between 0am and wakeup_Time
|
||||
sleep_time = (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60) - seconds
|
||||
else: # if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400 - seconds + (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60)
|
||||
print('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
logging.info('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
sleep(sleep_time - 10)
|
||||
|
||||
# wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds) + ' < ' + str(
|
||||
(wakeup_Time[datetime.now().month - 1] * 60 * 60)))
|
||||
while (datetime.now() - midnight).seconds < (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for ' + str(sleep_time) + ' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for ' + str(sleep_time) + ' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
else:
|
||||
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
|
||||
if internet == 'true' and internetTmp == 'false':
|
||||
checkConnectionToFTPServer()
|
||||
|
||||
checkCpu()
|
||||
sleepToNextPicture()
|
||||
|
||||
except Exception as loopError:
|
||||
print('[Timlapse Core] ' + str(loopError))
|
||||
try:
|
||||
logging.error('[FTP] could not change ftp directory !')
|
||||
except Exception as er:
|
||||
print('[Timlapse Core] Could not log: ' + str(er))
|
||||
|
||||
|
||||
611
Software/ZK_python/camera_v4_043.py
Normal file
611
Software/ZK_python/camera_v4_043.py
Normal file
@ -0,0 +1,611 @@
|
||||
# (c)2017-2018 Jannik Seiler & Hendrik Schutter
|
||||
|
||||
# 043
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import http.client as httplib
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
from spidev import SpiDev
|
||||
import RPi.GPIO as GPIO
|
||||
import re
|
||||
import fcntl
|
||||
|
||||
# get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open("/sys/class/thermal/thermal_zone0/temp")
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp) / 1000
|
||||
|
||||
|
||||
# uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('[Upload] successful!')
|
||||
except Exception as e:
|
||||
print('upload failed!')
|
||||
print(e)
|
||||
logging.error('[Upload] failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP] trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP] re-connecting successful!')
|
||||
logging.info('[FTP] re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP] upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except Exception as e9:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
return
|
||||
|
||||
|
||||
def checkDiskSpace():
|
||||
st = os.statvfs('/media/usb0')
|
||||
free = st.f_bavail * st.f_frsize
|
||||
total = st.f_blocks * st.f_frsize
|
||||
|
||||
freePercentaged = int(((st.f_bavail * st.f_frsize) / (st.f_blocks * st.f_frsize)) * 100)
|
||||
logging.info('[Disk] Free space: ' + str(freePercentaged) + ' %')
|
||||
print('Free disk space ', str(freePercentaged), ' %')
|
||||
if freePercentaged < 20 and freePercentaged > 10: logging.warning('[Disk] Storage Drive nearly full!')
|
||||
if freePercentaged < 10: logging.critical('[Disk] Storage Drive full, Backup Space in use!')
|
||||
return
|
||||
|
||||
|
||||
def checkCpu():
|
||||
try:
|
||||
cpuUsage = (os.popen("top -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip())
|
||||
cpuUsage = (float(cpuUsage.replace(',', '.'))) * 25
|
||||
print('[CPU] Usage: ', str("%.2f" % cpuUsage), ' %')
|
||||
logging.info('[CPU] Usage: ' + str("%.2f" % cpuUsage) + ' %')
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('[CPU] Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('[CPU] Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('[CPU] Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('[CPU] Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
else:
|
||||
logging.info('[CPU] Temperature: ' + str(getCpuTemperature()) + ' C')
|
||||
return
|
||||
except Exception as e2:
|
||||
print('[CPU] ' + str(e2))
|
||||
logging.warning('[CPU] ' + str(e2))
|
||||
|
||||
def readMPC(channel):
|
||||
adc = spi.xfer2([1, (8 + channel) << 4, 0])
|
||||
data = ((adc[1] & 3) << 8) + adc[2]
|
||||
return data
|
||||
|
||||
def sleepToNextPicture():
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix > 0:
|
||||
print("sleeping now", time_sleep_unix, "seconds" + '\n')
|
||||
logging.info('sleeping now ' + str(time_sleep_unix) + ' seconds' + '\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
def checkSystemVoltage():
|
||||
systemVoltage = (((readMPC(0) / 1023.0 * 3.3) * 6.62) * 0.95)
|
||||
print("System Input Voltage: %.2f" % systemVoltage, "Volt")
|
||||
logging.info('[Voltage] ' + str("%.2f" % systemVoltage) + ' Volt')
|
||||
if systemVoltage < 11.3 and systemVoltage > 9:
|
||||
logging.warning('[Voltage] Low System Input Voltage! Maybe bad power supply or no sun.')
|
||||
if tvOut == 'auto':
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/tvservice -o ')
|
||||
print('[TV Out] Status: ' + stdoutdata)
|
||||
logging.info('[TV Out] Status: ' + stdoutdata)
|
||||
if systemVoltage < 9: logging.critical('[Voltage] Very low System Input Voltage! Bad power supply or no sun.')
|
||||
return
|
||||
|
||||
|
||||
def reconnectToInternet():
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.coptersicht.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
print('Server is maybe not online!')
|
||||
logging.info('Internet connection established')
|
||||
logging.error('Server maybe is not online!')
|
||||
global interntTmp
|
||||
interntTmp = 'true'
|
||||
#checkConnectionToFTPServer()
|
||||
return 'true'
|
||||
except Exception as e2:
|
||||
conn.close()
|
||||
print('no Internet connection')
|
||||
print('trying to reconnect to internet')
|
||||
logging.error('no Internet connection!')
|
||||
logging.info('trying to reconnect to internet')
|
||||
if enable_modem == 'true':
|
||||
print('[MODEM] no UMTS connection')
|
||||
logging.error('[MODEM] no UMTS connection')
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/modem3g/sakis3g status')
|
||||
print('[MODEM] Network Status: ' + stdoutdata)
|
||||
logging.info('[MODEM] Network Status: ' + stdoutdata)
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[MODEM] disconnected')
|
||||
sleep(20)
|
||||
resetModem()
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[MODEM] reconnection successful attempt')
|
||||
logging.info('[MODEM] reconnection successful attempt')
|
||||
logging.info(stdoutdata)
|
||||
sleep(10)
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
logging.info('Internet connection established')
|
||||
return 'true'
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e5))
|
||||
logging.error(str(e5))
|
||||
return 'false'
|
||||
except Exception as e4:
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
return 'false'
|
||||
else:
|
||||
print('LAN or WLAN not connected!')
|
||||
logging.error('LAN or WLAN not connected!')
|
||||
return 'false'
|
||||
|
||||
def checkConnectionToFTPServer():
|
||||
try:
|
||||
# ping ftp url instead something else
|
||||
conn = httplib.HTTPConnection("www.coptersicht.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
try:
|
||||
global ftp
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP] New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('[FTP] New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
global internetTmp
|
||||
internetTmp = 'true'
|
||||
global upload_every
|
||||
upload_every = upload_only
|
||||
print('[FTP] Server connection established')
|
||||
logging.info('[FTP] Server connection established')
|
||||
except Exception as ea:
|
||||
internetTmp = 'false'
|
||||
print('[FTP] no internet or ftp connection trying to reconnect later!')
|
||||
logging.error('[FTP] no internet or ftp connection trying to reconnect later!')
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('[FTP] Server connection not established')
|
||||
logging.info('[FTP] Server connection not established')
|
||||
reconnectToInternet()
|
||||
|
||||
return
|
||||
|
||||
def resetModem():
|
||||
try:
|
||||
lsusb_cmd = 'lsusb | grep {}'.format('Huawei')
|
||||
lsusb_out = subprocess.check_output(lsusb_cmd, shell=True)
|
||||
parts = re.search(r'Bus (?P<bus>\d+) Device (?P<dev>\d+): ID [:\d\w]+ (?P<desc>.*)$', str(lsusb_out))
|
||||
bus = parts.group('bus')
|
||||
dev = parts.group('dev')
|
||||
desc = parts.group('desc').strip()
|
||||
print('[Modem] Found device {} on bus {} for "{}"'.format(bus, dev, desc))
|
||||
f = open('/dev/bus/usb/{}/{}'.format(bus, dev), 'w', os.O_WRONLY)
|
||||
fcntl.ioctl(f, 21780, 0)
|
||||
sleep(15)
|
||||
print('[Modem] Reset successfully attempt')
|
||||
except Exception as ea:
|
||||
print('[Modem] Reset Error: ' + str(ea))
|
||||
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
# ioBoard
|
||||
piezo = 25
|
||||
bootSwitch = 17
|
||||
|
||||
version = 'starting camera version 043'
|
||||
print('Copyright CopterSicht - info@coptersicht.de 2015-' + str(datetime.now().year))
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
internet = configParser.get('config', 'internet')
|
||||
modem_apn = configParser.get('config', 'modem_apn')
|
||||
upload_only = int(configParser.get('config', 'upload_only'))
|
||||
interval = int(configParser.get('config', 'interval'))
|
||||
ioBoard = configParser.get('config', 'I/O_Board')
|
||||
mute = configParser.get('config', 'mute')
|
||||
wakeup_Time = str(configParser.get('config', 'wakeup_Time')).split(',')
|
||||
bed_Time = str(configParser.get('config', 'bed_Time')).split(',')
|
||||
tvOut = configParser.get('config', 'TV_Output')
|
||||
width = configParser.get('config', 'Width')
|
||||
height = configParser.get('config', 'Height')
|
||||
rebootCMD = configParser.get('config', 'Reboot')
|
||||
print('done!')
|
||||
|
||||
print('initializing logger...')
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
try:
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
except Exception as er:
|
||||
print('[Logger] Could not create .log' + str(er))
|
||||
print('[USB] Could not find USB storage!')
|
||||
while 1:
|
||||
checkConnectionToFTPServer()
|
||||
print('[Timlapse Core] Waiting for maintenance!')
|
||||
sleep(3600)
|
||||
logging.info(version)
|
||||
print('done')
|
||||
print('reading picture number...')
|
||||
try:
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
except Exception as ea:
|
||||
print('No picture_Number.txt found. Creating new .. ')
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(0))
|
||||
f.close()
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
logging.info('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('done, picture number is:', str(picture_number))
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
upload_every = upload_only
|
||||
internetTmp = internet
|
||||
rebootFlag = 'false'
|
||||
|
||||
if ioBoard == "true":
|
||||
print('Running with the nice IO board!')
|
||||
spi = SpiDev()
|
||||
spi.open(0, 0)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setup(piezo, GPIO.OUT)
|
||||
GPIO.setup(bootSwitch, GPIO.IN)
|
||||
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera = PiCamera()
|
||||
camera.resolution = (3280, 2464) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.awb_mode = 'auto'
|
||||
camera.start_preview()
|
||||
# camera.start_preview(fullscreen=False, window = (100, 20, 960, 720))
|
||||
print('---starting sharpness tool---')
|
||||
print('--------normal output--------')
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
sleep(5)
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera.stop_preview()
|
||||
print('---------zoom output---------')
|
||||
camera.crop = (0.5, 0.5, 0.3, 0.4)
|
||||
camera.start_preview()
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
else:
|
||||
camera.stop_preview()
|
||||
camera.close()
|
||||
if mute == "false":
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(1)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
else:
|
||||
print('Running without the nice IO board!')
|
||||
|
||||
if rebootCMD == 'true':
|
||||
print('Automatic reboot is allowed while wake up!')
|
||||
logging.info('Automatic reboot is allowed while wakeup!')
|
||||
|
||||
if tvOut == 'false':
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/tvservice -o ')
|
||||
print('[TV Out] Status: ' + stdoutdata)
|
||||
logging.info('[TV Out] Status: ' + stdoutdata)
|
||||
|
||||
if internetTmp == 'true':
|
||||
print('Running in Online mode, internet connection is required')
|
||||
if enable_modem == 'true': reconnectToInternet()
|
||||
try:
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
except Exception as ea:
|
||||
print('no internet or ftp connection on startup trying to reconnect later!')
|
||||
logging.error('no internet or ftp connection on startup trying to reconnect later!')
|
||||
internetTmp = 'false'
|
||||
else:
|
||||
print('Running in Offline mode, no internet connection is required')
|
||||
|
||||
# camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
# camera.shutter_speed = 500000
|
||||
|
||||
|
||||
# camera.brightness = 50 #0 bis 100; default 50
|
||||
# camera.contrast = 0 #-100 bis 100; default 0
|
||||
# camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
# camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
# camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
print('[Camera] Resolution: ' + width + 'x' + height)
|
||||
logging.info('[Camera] Resolution: ' + width + 'x' + height)
|
||||
|
||||
|
||||
# main programm (endless loop)
|
||||
while 1:
|
||||
try:
|
||||
time_next_unix = time.time() + interval # time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) # get time for picture_name
|
||||
time_name = time_name.replace(" ", "_")
|
||||
time_name = time_name.replace(":", "-")
|
||||
picture_name = camera_number + '_' + str(picture_number).zfill(6) + '_' + time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print("Time:", time_name)
|
||||
#camera = PiCamera()
|
||||
camera.resolution = (int(width), int(height)) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.exposure_mode = 'auto'
|
||||
camera.awb_mode = 'auto'
|
||||
camera.crop = (0, 0, 0, 0)
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) ' + str(datetime.now().year) + ' CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = 'interval capture'
|
||||
|
||||
if mute == "false": GPIO.output(piezo, GPIO.HIGH)
|
||||
print('Capturing image')
|
||||
logging.info('[Camera] Capturing image')
|
||||
camera.capture(picture_path) # capture image and save to picture_path (picture_directory + picture_name)
|
||||
#camera.close()
|
||||
if mute == "false": GPIO.output(piezo, GPIO.LOW)
|
||||
picture_number += 1 # increase picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print('Picture size:', os.path.getsize(picture_path), "Byte")
|
||||
logging.info('[Camera] Picture size: ' + str(os.path.getsize(picture_path)) + ' Byte')
|
||||
checkDiskSpace()
|
||||
if ioBoard == "true": checkSystemVoltage()
|
||||
if os.path.getsize(picture_path) < picture_size:
|
||||
print('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds # seconds since midnight
|
||||
if seconds1 > float(wakeup_Time[datetime.now().month - 1]) * 60 * 60 and seconds1 < float(bed_Time[
|
||||
datetime.now().month - 1]) * 60 * 60: # if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
print("uploadTimer", upload_every)
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
checkCpu()
|
||||
sleepToNextPicture()
|
||||
else:
|
||||
os.remove(picture_path) # deleting picture because it's night!
|
||||
picture_number -= 1 # decrease picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
# uploading log file
|
||||
print('skipping picture upload!')
|
||||
print('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': logging.info('uploading todays log befor going to sleep!')
|
||||
if internetTmp == 'true':
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('[FTP] uploaded log-file successful!')
|
||||
logging.info('[FTP] uploaded log-file successful!')
|
||||
except Exception as e:
|
||||
print('[FTP] upload failed!')
|
||||
print(e)
|
||||
logging.error('[FTP] upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('[FTP] re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e8:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
try:
|
||||
print()
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('[FTP] uploaded log-file successful!')
|
||||
logging.info('[FTP] uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print('[FTP] re-connecting failed!')
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('[FTP] could not change ftp directory !')
|
||||
logging.error('[FTP] could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
if internet == 'true' and internetTmp == 'false':
|
||||
checkConnectionToFTPServer()
|
||||
if internetTmp == 'false':
|
||||
rebootFlag = 'true'
|
||||
# sleep until next morning
|
||||
print('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds # seconds since midnight
|
||||
if seconds < (
|
||||
float(wakeup_Time[
|
||||
datetime.now().month - 1]) * 60 * 60): # if time between 0am and wakeup_Time
|
||||
sleep_time = (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60) - seconds
|
||||
else: # if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400 - seconds + (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60)
|
||||
print('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
logging.info('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
sleep(sleep_time - 10)
|
||||
|
||||
# wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds) + ' < ' + str(
|
||||
(wakeup_Time[datetime.now().month - 1] * 60 * 60)))
|
||||
while (datetime.now() - midnight).seconds < (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for ' + str(sleep_time) + ' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('slept for ' + str(sleep_time) + ' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
if rebootFlag == 'true':
|
||||
rebootFlag = 'false'
|
||||
stdoutdata = subprocess.getoutput('shutdown -r now')
|
||||
print('[Timelapse Core] Reboot: ' + stdoutdata)
|
||||
logging.info('[Timelapse Core] Reboot: ' + stdoutdata)
|
||||
sleep(70)
|
||||
else:
|
||||
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
|
||||
if internet == 'true' and internetTmp == 'false':
|
||||
checkConnectionToFTPServer()
|
||||
|
||||
checkCpu()
|
||||
sleepToNextPicture()
|
||||
|
||||
except Exception as loopError:
|
||||
print('[Timlapse Core] ' + str(loopError))
|
||||
try:
|
||||
logging.error('[FTP] could not change ftp directory !')
|
||||
except Exception as er:
|
||||
print('[Timlapse Core] Could not log: ' + str(er))
|
||||
|
||||
|
||||
653
Software/ZK_python/camera_v4_044.py
Normal file
653
Software/ZK_python/camera_v4_044.py
Normal file
@ -0,0 +1,653 @@
|
||||
# (c)2017-2018 Jannik Seiler & Hendrik Schutter
|
||||
|
||||
# 044
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import http.client as httplib
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
from spidev import SpiDev
|
||||
import RPi.GPIO as GPIO
|
||||
import re
|
||||
import fcntl
|
||||
|
||||
# get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open("/sys/class/thermal/thermal_zone0/temp")
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp) / 1000
|
||||
|
||||
|
||||
# uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('[Upload] successful!')
|
||||
except Exception as e:
|
||||
print('upload failed!')
|
||||
print(e)
|
||||
logging.error('[Upload] failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP] trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP] re-connecting successful!')
|
||||
logging.info('[FTP] re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP] upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except Exception as e9:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
return
|
||||
|
||||
|
||||
def checkDiskSpace():
|
||||
st = os.statvfs('/media/usb0')
|
||||
free = st.f_bavail * st.f_frsize
|
||||
total = st.f_blocks * st.f_frsize
|
||||
|
||||
freePercentaged = int(((st.f_bavail * st.f_frsize) / (st.f_blocks * st.f_frsize)) * 100)
|
||||
logging.info('[Disk] Free space: ' + str(freePercentaged) + ' %')
|
||||
print('Free disk space ', str(freePercentaged), ' %')
|
||||
if freePercentaged < 20 and freePercentaged > 10: logging.warning('[Disk] Storage Drive nearly full!')
|
||||
if freePercentaged < 10: logging.critical('[Disk] Storage Drive full, Backup Space in use!')
|
||||
return
|
||||
|
||||
|
||||
def checkCpu():
|
||||
try:
|
||||
cpuUsage = (os.popen("top -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip())
|
||||
cpuUsage = (float(cpuUsage.replace(',', '.'))) * 25
|
||||
cpuUsageStr = str(cpuUsage) + ' %'
|
||||
print('[CPU] Usage: ', cpuUsageStr)
|
||||
logging.info('[CPU] Usage: ' + str("%.2f" % cpuUsage) + ' %')
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('[CPU] Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 5.0:
|
||||
logging.warning('[CPU] Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('[CPU] Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('[CPU] Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
else:
|
||||
logging.info('[CPU] Temperature: ' + str(getCpuTemperature()) + ' C')
|
||||
return
|
||||
except Exception as e2:
|
||||
print('[CPU] ' + str(e2))
|
||||
logging.warning('[CPU] ' + str(e2))
|
||||
|
||||
def readMPC(channel):
|
||||
adc = spi.xfer2([1, (8 + channel) << 4, 0])
|
||||
data = ((adc[1] & 3) << 8) + adc[2]
|
||||
return data
|
||||
|
||||
def sleepToNextPicture():
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix > 0:
|
||||
print("sleeping now", time_sleep_unix, "seconds" + '\n')
|
||||
logging.info('sleeping now ' + str(time_sleep_unix) + ' seconds' + '\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
def checkSystemVoltage():
|
||||
systemVoltage = (((readMPC(0) / 1023.0 * 3.3) * 6.62) * 0.95)
|
||||
print("System Input Voltage: %.2f" % systemVoltage, "Volt")
|
||||
logging.info('[Voltage] ' + str("%.2f" % systemVoltage) + ' Volt')
|
||||
if systemVoltage < 11.3 and systemVoltage > 9:
|
||||
logging.warning('[Voltage] Low System Input Voltage! Maybe bad power supply or no sun.')
|
||||
if tvOut == 'auto':
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/tvservice -o ')
|
||||
print('[TV Out] Status: ' + stdoutdata)
|
||||
logging.info('[TV Out] Status: ' + stdoutdata)
|
||||
if systemVoltage < 9: logging.critical('[Voltage] Very low System Input Voltage! Bad power supply or no sun.')
|
||||
return
|
||||
|
||||
|
||||
def reconnectToInternet():
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.coptersicht.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
print('Server is maybe not online!')
|
||||
logging.info('Internet connection established')
|
||||
logging.error('Server maybe is not online!')
|
||||
global interntTmp
|
||||
interntTmp = 'true'
|
||||
#checkConnectionToFTPServer()
|
||||
return 'true'
|
||||
except Exception as e2:
|
||||
conn.close()
|
||||
print('no Internet connection')
|
||||
print('trying to reconnect to internet')
|
||||
logging.error('no Internet connection!')
|
||||
logging.info('trying to reconnect to internet')
|
||||
if enable_modem == 'true':
|
||||
print('[MODEM] no UMTS connection')
|
||||
logging.error('[MODEM] no UMTS connection')
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/modem3g/sakis3g status')
|
||||
print('[MODEM] Network Status: ' + stdoutdata)
|
||||
logging.info('[MODEM] Network Status: ' + stdoutdata)
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[MODEM] disconnected')
|
||||
sleep(20)
|
||||
resetModem()
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[MODEM] reconnection successful attempt')
|
||||
logging.info('[MODEM] reconnection successful attempt')
|
||||
logging.info(stdoutdata)
|
||||
sleep(10)
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
logging.info('Internet connection established')
|
||||
return 'true'
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e5))
|
||||
logging.error(str(e5))
|
||||
return 'false'
|
||||
except Exception as e4:
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
return 'false'
|
||||
else:
|
||||
print('LAN or WLAN not connected!')
|
||||
logging.error('LAN or WLAN not connected!')
|
||||
return 'false'
|
||||
|
||||
def checkConnectionToFTPServer():
|
||||
try:
|
||||
# ping ftp url instead something else
|
||||
conn = httplib.HTTPConnection("www.coptersicht.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
try:
|
||||
global ftp
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP] New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('[FTP] New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
global internetTmp
|
||||
internetTmp = 'true'
|
||||
global upload_every
|
||||
upload_every = upload_only
|
||||
print('[FTP] Server connection established')
|
||||
logging.info('[FTP] Server connection established')
|
||||
except Exception as ea:
|
||||
internetTmp = 'false'
|
||||
print('[FTP] no internet or ftp connection trying to reconnect later!')
|
||||
logging.error('[FTP] no internet or ftp connection trying to reconnect later!')
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('[FTP] Server connection not established')
|
||||
logging.info('[FTP] Server connection not established')
|
||||
reconnectToInternet()
|
||||
|
||||
return
|
||||
|
||||
def resetModem():
|
||||
try:
|
||||
lsusb_cmd = 'lsusb | grep {}'.format('Huawei')
|
||||
lsusb_out = subprocess.check_output(lsusb_cmd, shell=True)
|
||||
parts = re.search(r'Bus (?P<bus>\d+) Device (?P<dev>\d+): ID [:\d\w]+ (?P<desc>.*)$', str(lsusb_out))
|
||||
bus = parts.group('bus')
|
||||
dev = parts.group('dev')
|
||||
desc = parts.group('desc').strip()
|
||||
print('[Modem] Found device {} on bus {} for "{}"'.format(bus, dev, desc))
|
||||
f = open('/dev/bus/usb/{}/{}'.format(bus, dev), 'w', os.O_WRONLY)
|
||||
fcntl.ioctl(f, 21780, 0)
|
||||
sleep(15)
|
||||
print('[Modem] Reset successfully attempt')
|
||||
except Exception as ea:
|
||||
print('[Modem] Reset Error: ' + str(ea))
|
||||
|
||||
def rebootSystem():
|
||||
rebootFlag = 'false'
|
||||
os.system('sudo shutdown -r now')
|
||||
print('[Timelapse Core] Reboot')
|
||||
logging.info('[Timelapse Core] Reboot')
|
||||
if mute == "false":
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(1)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
sleep(1)
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(2)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
sleep(2)
|
||||
sleep(70)
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
# ioBoard
|
||||
piezo = 25
|
||||
bootSwitch = 17
|
||||
|
||||
version = 'starting camera version 044'
|
||||
print('Copyright CopterSicht - info@coptersicht.de 2015-' + str(datetime.now().year))
|
||||
print(version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
internet = configParser.get('config', 'internet')
|
||||
modem_apn = configParser.get('config', 'modem_apn')
|
||||
upload_only = int(configParser.get('config', 'upload_only'))
|
||||
interval = int(configParser.get('config', 'interval'))
|
||||
ioBoard = configParser.get('config', 'I/O_Board')
|
||||
mute = configParser.get('config', 'mute')
|
||||
wakeup_Time = str(configParser.get('config', 'wakeup_Time')).split(',')
|
||||
bed_Time = str(configParser.get('config', 'bed_Time')).split(',')
|
||||
tvOut = configParser.get('config', 'TV_Output')
|
||||
width = configParser.get('config', 'Width')
|
||||
height = configParser.get('config', 'Height')
|
||||
rebootCMD = configParser.get('config', 'Reboot')
|
||||
|
||||
print('done!')
|
||||
|
||||
print('initializing logger...')
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
try:
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
except Exception as er:
|
||||
print('[Logger] Could not create .log' + str(er))
|
||||
print('[USB] Could not find USB storage!')
|
||||
while 1:
|
||||
checkConnectionToFTPServer()
|
||||
if internet == 'true' and internetTmp == 'false':
|
||||
if internetTmp == 'false':
|
||||
rebootFlag = 'true'
|
||||
print('[Timelapse Core] Reboot Flag set')
|
||||
if rebootFlag == 'true':
|
||||
rebootSystem()
|
||||
print('[Timlapse Core] Waiting for maintenance!')
|
||||
sleep(3600)
|
||||
logging.info(version)
|
||||
print('done')
|
||||
print('reading picture number...')
|
||||
try:
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
except Exception as ea:
|
||||
print('No picture_Number.txt found. Creating new .. ')
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(0))
|
||||
f.close()
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
logging.info('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('done, picture number is:', str(picture_number))
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
upload_every = upload_only
|
||||
internetTmp = internet
|
||||
rebootFlag = 'false'
|
||||
|
||||
if ioBoard == "true":
|
||||
print('Running with the nice IO board!')
|
||||
spi = SpiDev()
|
||||
spi.open(0, 0)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setup(piezo, GPIO.OUT)
|
||||
GPIO.setup(bootSwitch, GPIO.IN)
|
||||
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera = PiCamera()
|
||||
camera.resolution = (3280, 2464) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.awb_mode = 'auto'
|
||||
camera.start_preview()
|
||||
# camera.start_preview(fullscreen=False, window = (100, 20, 960, 720))
|
||||
print('---starting sharpness tool---')
|
||||
print('--------normal output--------')
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
sleep(5)
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera.stop_preview()
|
||||
print('---------zoom output---------')
|
||||
camera.crop = (0.5, 0.5, 0.3, 0.4)
|
||||
camera.start_preview()
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
else:
|
||||
camera.stop_preview()
|
||||
camera.close()
|
||||
if mute == "false":
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(1)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
else:
|
||||
print('Running without the nice IO board!')
|
||||
|
||||
if rebootCMD == 'true':
|
||||
print('Automatic reboot is allowed while wake up!')
|
||||
logging.info('Automatic reboot is allowed while wakeup!')
|
||||
|
||||
if tvOut == 'false':
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/tvservice -o ')
|
||||
print('[TV Out] Status: ' + stdoutdata)
|
||||
logging.info('[TV Out] Status: ' + stdoutdata)
|
||||
|
||||
if internetTmp == 'true':
|
||||
print('Running in Online mode, internet connection is required')
|
||||
if enable_modem == 'true': reconnectToInternet()
|
||||
try:
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
except Exception as ea:
|
||||
print('no internet or ftp connection on startup trying to reconnect later!')
|
||||
logging.error('no internet or ftp connection on startup trying to reconnect later!')
|
||||
internetTmp = 'false'
|
||||
else:
|
||||
print('Running in Offline mode, no internet connection is required')
|
||||
|
||||
# camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
# camera.shutter_speed = 500000
|
||||
|
||||
|
||||
# camera.brightness = 50 #0 bis 100; default 50
|
||||
# camera.contrast = 0 #-100 bis 100; default 0
|
||||
# camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
# camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
# camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
print('[Camera] Resolution: ' + width + 'x' + height)
|
||||
logging.info('[Camera] Resolution: ' + width + 'x' + height)
|
||||
|
||||
|
||||
# main programm (endless loop)
|
||||
while 1:
|
||||
try:
|
||||
time_next_unix = time.time() + interval # time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) # get time for picture_name
|
||||
time_name = time_name.replace(" ", "_")
|
||||
time_name = time_name.replace(":", "-")
|
||||
picture_name = camera_number + '_' + str(picture_number).zfill(6) + '_' + time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print("Time:", time_name)
|
||||
#camera = PiCamera()
|
||||
camera.resolution = (int(width), int(height)) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.exposure_mode = 'auto'
|
||||
camera.awb_mode = 'auto'
|
||||
camera.crop = (0, 0, 0, 0)
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) ' + str(datetime.now().year) + ' CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = 'interval capture'
|
||||
|
||||
if mute == "false": GPIO.output(piezo, GPIO.HIGH)
|
||||
print('Capturing image')
|
||||
logging.info('[Camera] Capturing image')
|
||||
camera.capture(picture_path) # capture image and save to picture_path (picture_directory + picture_name)
|
||||
#camera.close()
|
||||
if mute == "false": GPIO.output(piezo, GPIO.LOW)
|
||||
picture_number += 1 # increase picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print('Picture size:', os.path.getsize(picture_path), "Byte")
|
||||
logging.info('[Camera] Picture size: ' + str(os.path.getsize(picture_path)) + ' Byte')
|
||||
checkDiskSpace()
|
||||
if ioBoard == "true": checkSystemVoltage()
|
||||
if os.path.getsize(picture_path) < picture_size:
|
||||
print('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds # seconds since midnight
|
||||
if seconds1 > float(wakeup_Time[datetime.now().month - 1]) * 60 * 60 and seconds1 < float(bed_Time[
|
||||
datetime.now().month - 1]) * 60 * 60: # if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
print("uploadTimer", upload_every)
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
#checkCpu()
|
||||
#sleepToNextPicture()
|
||||
else:
|
||||
os.remove(picture_path) # deleting picture because it's night!
|
||||
picture_number -= 1 # decrease picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
# uploading log file
|
||||
print('skipping picture upload!')
|
||||
print('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': logging.info('uploading todays log befor going to sleep!')
|
||||
if internetTmp == 'true':
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('[FTP] uploaded log-file successful!')
|
||||
logging.info('[FTP] uploaded log-file successful!')
|
||||
except Exception as e:
|
||||
print('[FTP] upload failed!')
|
||||
print(e)
|
||||
logging.error('[FTP] upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('[FTP] re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e8:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
try:
|
||||
print()
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('[FTP] uploaded log-file successful!')
|
||||
logging.info('[FTP] uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print('[FTP] re-connecting failed!')
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('[FTP] could not change ftp directory !')
|
||||
logging.error('[FTP] could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
if internet == 'true' and internetTmp == 'false':
|
||||
print('[Timelapse Core] Checking again Internet Connection before sleep')
|
||||
logging.info('[Timelapse Core] Checking again Internet Connection before sleep')
|
||||
checkConnectionToFTPServer()
|
||||
if internetTmp == 'false':
|
||||
rebootFlag = 'true'
|
||||
print('[Timelapse Core] Reboot Flag set')
|
||||
logging.info('[Timelapse Core] Reboot Flag set')
|
||||
if mute == "false":
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
sleep(0.5)
|
||||
|
||||
# sleep until next morning
|
||||
print('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds # seconds since midnight
|
||||
if seconds < (
|
||||
float(wakeup_Time[
|
||||
datetime.now().month - 1]) * 60 * 60): # if time between 0am and wakeup_Time
|
||||
sleep_time = (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60) - seconds
|
||||
else: # if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400 - seconds + (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60)
|
||||
print('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
logging.info('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
sleep(sleep_time - 10)
|
||||
|
||||
# wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds) + ' < ' + str(
|
||||
(wakeup_Time[datetime.now().month - 1] * 60 * 60)))
|
||||
while (datetime.now() - midnight).seconds < (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for ' + str(sleep_time) + ' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info(version)
|
||||
logging.info('slept for ' + str(sleep_time) + ' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
if rebootFlag == 'true':
|
||||
rebootSystem()
|
||||
else:
|
||||
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
|
||||
if internet == 'true' and internetTmp == 'false':
|
||||
checkConnectionToFTPServer()
|
||||
|
||||
checkCpu()
|
||||
sleepToNextPicture()
|
||||
|
||||
except Exception as loopError:
|
||||
print('[Timlapse Core] ' + str(loopError))
|
||||
try:
|
||||
logging.error('[FTP] could not change ftp directory !')
|
||||
except Exception as er:
|
||||
print('[Timlapse Core] Could not log: ' + str(er))
|
||||
|
||||
|
||||
650
Software/ZK_python/camera_v4_045.py
Normal file
650
Software/ZK_python/camera_v4_045.py
Normal file
@ -0,0 +1,650 @@
|
||||
# (c)2017-2018 Jannik Seiler & Hendrik Schutter
|
||||
|
||||
# 045
|
||||
|
||||
from picamera import PiCamera
|
||||
from time import sleep
|
||||
from ftplib import FTP
|
||||
from fractions import Fraction
|
||||
from datetime import datetime
|
||||
import ftplib
|
||||
import time
|
||||
import os
|
||||
import http.client as httplib
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
import configparser
|
||||
import subprocess
|
||||
from spidev import SpiDev
|
||||
import RPi.GPIO as GPIO
|
||||
import re
|
||||
import fcntl
|
||||
|
||||
# get cpu temperature
|
||||
def getCpuTemperature():
|
||||
tempFile = open("/sys/class/thermal/thermal_zone0/temp")
|
||||
cpu_temp = tempFile.read()
|
||||
tempFile.close()
|
||||
return float(cpu_temp) / 1000
|
||||
|
||||
|
||||
# uploading picture to ftp and make chmod 754 when done sleep until sleeping time is over
|
||||
def uploadToFTP():
|
||||
print('trying to upload file ...')
|
||||
logging.info('trying to upload file ...')
|
||||
try:
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('upload successful!')
|
||||
logging.info('[Upload] successful!')
|
||||
except Exception as e:
|
||||
print('upload failed!')
|
||||
print(e)
|
||||
logging.error('[Upload] failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP] trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP] re-connecting successful!')
|
||||
logging.info('[FTP] re-connecting successful!')
|
||||
ftp.storbinary('STOR ' + picture_name, open(picture_path, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + picture_name)
|
||||
os.remove(picture_path)
|
||||
print('[FTP] upload successful!')
|
||||
logging.info('[FTP]upload successful!')
|
||||
except Exception as e9:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e9)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e9))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
return
|
||||
|
||||
|
||||
def checkDiskSpace():
|
||||
st = os.statvfs(picture_directory)
|
||||
free = st.f_bavail * st.f_frsize
|
||||
total = st.f_blocks * st.f_frsize
|
||||
|
||||
freePercentaged = int(((st.f_bavail * st.f_frsize) / (st.f_blocks * st.f_frsize)) * 100)
|
||||
logging.info('[Disk] Free space: ' + str(freePercentaged) + ' %')
|
||||
print('Free disk space ', str(freePercentaged), ' %')
|
||||
if freePercentaged < 20 and freePercentaged > 10: logging.warning('[Disk] Storage Drive nearly full!')
|
||||
if freePercentaged < 10: logging.critical('[Disk] Storage Drive full, Backup Space in use!')
|
||||
return
|
||||
|
||||
|
||||
def checkCpu():
|
||||
try:
|
||||
if getCpuTemperature() <= -5.0:
|
||||
logging.critical('[CPU] Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() <= 7.0:
|
||||
logging.warning('[CPU] Coold: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 45.0:
|
||||
logging.warning('[CPU] Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
elif getCpuTemperature() >= 50.0:
|
||||
logging.critical('[CPU] Hot: ' + str(getCpuTemperature()) + ' C')
|
||||
else:
|
||||
logging.info('[CPU] Temperature: ' + str(getCpuTemperature()) + ' C')
|
||||
return
|
||||
except Exception as e2:
|
||||
print('[CPU] ' + str(e2))
|
||||
logging.warning('[CPU] ' + str(e2))
|
||||
|
||||
def readMPC(channel):
|
||||
adc = spi.xfer2([1, (8 + channel) << 4, 0])
|
||||
data = ((adc[1] & 3) << 8) + adc[2]
|
||||
return data
|
||||
|
||||
def sleepToNextPicture():
|
||||
time_sleep_unix = time_next_unix - time.time()
|
||||
if time_sleep_unix > 0:
|
||||
print("sleeping now", time_sleep_unix, "seconds" + '\n')
|
||||
logging.info('sleeping now ' + str(time_sleep_unix) + ' seconds' + '\n')
|
||||
sleep(time_sleep_unix)
|
||||
else:
|
||||
print('no sleep needed, behind schedule!')
|
||||
logging.warning('no sleep needed, behind schedule!')
|
||||
return
|
||||
|
||||
def checkSystemVoltage():
|
||||
systemVoltage = (((readMPC(0) / 1023.0 * 3.3) * 6.62) * 0.95)
|
||||
print("System Input Voltage: %.2f" % systemVoltage, "Volt")
|
||||
logging.info('[Voltage] ' + str("%.2f" % systemVoltage) + ' Volt')
|
||||
if systemVoltage < 11.2 and systemVoltage > 9:
|
||||
logging.warning('[Voltage] Low System Input Voltage! Maybe bad power supply or no sun.')
|
||||
if tvOut == 'auto':
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/tvservice -o ')
|
||||
print('[TV Out] Status: ' + stdoutdata)
|
||||
logging.info('[TV Out] Status: ' + stdoutdata)
|
||||
if systemVoltage < 9: logging.critical('[Voltage] Very low System Input Voltage! Bad power supply or no sun.')
|
||||
return
|
||||
|
||||
|
||||
def reconnectToInternet():
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.coptersicht.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
print('Server is maybe not online!')
|
||||
logging.info('Internet connection established')
|
||||
logging.error('Server maybe is not online!')
|
||||
global interntTmp
|
||||
interntTmp = 'true'
|
||||
#checkConnectionToFTPServer()
|
||||
return 'true'
|
||||
except Exception as e2:
|
||||
conn.close()
|
||||
print('no Internet connection')
|
||||
print('trying to reconnect to internet')
|
||||
logging.error('no Internet connection!')
|
||||
logging.info('trying to reconnect to internet')
|
||||
if enable_modem == 'true':
|
||||
print('[MODEM] no UMTS connection')
|
||||
logging.error('[MODEM] no UMTS connection')
|
||||
try:
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/modem3g/sakis3g status')
|
||||
print('[MODEM] Network Status: ' + stdoutdata)
|
||||
logging.info('[MODEM] Network Status: ' + stdoutdata)
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g disconnect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
logging.info(stdoutdata)
|
||||
logging.info('[MODEM] disconnected')
|
||||
sleep(20)
|
||||
resetModem()
|
||||
stdoutdata = subprocess.getoutput(
|
||||
"sudo /usr/bin/modem3g/sakis3g connect --console APN='" + modem_apn + "' USBINTERFACE='0' USBMODEM='12d1:1436'")
|
||||
print(stdoutdata)
|
||||
print('[MODEM] reconnection successful attempt')
|
||||
logging.info('[MODEM] reconnection successful attempt')
|
||||
logging.info(stdoutdata)
|
||||
sleep(10)
|
||||
try:
|
||||
conn = httplib.HTTPConnection("www.google.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
print('Internet connection established')
|
||||
logging.info('Internet connection established')
|
||||
return 'true'
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e5))
|
||||
logging.error(str(e5))
|
||||
return 'false'
|
||||
except Exception as e4:
|
||||
print('[MODEM] UMTS connection failed')
|
||||
logging.error('[MODEM] UMTS connection failed')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
return 'false'
|
||||
else:
|
||||
print('LAN or WLAN not connected!')
|
||||
logging.error('LAN or WLAN not connected!')
|
||||
return 'false'
|
||||
|
||||
def checkConnectionToFTPServer():
|
||||
try:
|
||||
# ping ftp url instead something else
|
||||
conn = httplib.HTTPConnection("www.coptersicht.de", timeout=5)
|
||||
conn.request("HEAD", "/")
|
||||
conn.close()
|
||||
try:
|
||||
global ftp
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('[FTP] New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('[FTP] New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
global internetTmp
|
||||
internetTmp = 'true'
|
||||
global upload_every
|
||||
upload_every = upload_only
|
||||
print('[FTP] Server connection established')
|
||||
logging.info('[FTP] Server connection established')
|
||||
except Exception as ea:
|
||||
internetTmp = 'false'
|
||||
print('[FTP] no internet or ftp connection trying to reconnect later!')
|
||||
logging.error('[FTP] no internet or ftp connection trying to reconnect later!')
|
||||
except Exception as e5:
|
||||
conn.close()
|
||||
print('[FTP] Server connection not established')
|
||||
logging.info('[FTP] Server connection not established')
|
||||
reconnectToInternet()
|
||||
|
||||
return
|
||||
|
||||
def resetModem():
|
||||
try:
|
||||
lsusb_cmd = 'lsusb | grep {}'.format('Huawei')
|
||||
lsusb_out = subprocess.check_output(lsusb_cmd, shell=True)
|
||||
parts = re.search(r'Bus (?P<bus>\d+) Device (?P<dev>\d+): ID [:\d\w]+ (?P<desc>.*)$', str(lsusb_out))
|
||||
bus = parts.group('bus')
|
||||
dev = parts.group('dev')
|
||||
desc = parts.group('desc').strip()
|
||||
print('[Modem] Found device {} on bus {} for "{}"'.format(bus, dev, desc))
|
||||
f = open('/dev/bus/usb/{}/{}'.format(bus, dev), 'w', os.O_WRONLY)
|
||||
fcntl.ioctl(f, 21780, 0)
|
||||
sleep(15)
|
||||
print('[Modem] Reset successfully attempt')
|
||||
except Exception as ea:
|
||||
print('[Modem] Reset Error: ' + str(ea))
|
||||
|
||||
def rebootSystem():
|
||||
rebootFlag = 'false'
|
||||
os.system('sudo shutdown -r now')
|
||||
print('[Timelapse Core] Reboot')
|
||||
logging.info('[Timelapse Core] Reboot')
|
||||
if mute == "false":
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(1)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
sleep(1)
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(2)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
sleep(2)
|
||||
sleep(70)
|
||||
|
||||
configParser = configparser.RawConfigParser()
|
||||
configFilePath = r'/home/pi/config.txt'
|
||||
configParser.read(configFilePath)
|
||||
|
||||
# ioBoard
|
||||
piezo = 25
|
||||
bootSwitch = 17
|
||||
|
||||
version = '045'
|
||||
print('Copyright CopterSicht - info@coptersicht.de 2015-' + str(datetime.now().year))
|
||||
print('starting camera version: ' + version)
|
||||
print('reading config...')
|
||||
ftp_url = configParser.get('config', 'ftp_url')
|
||||
ftp_picture_directory = configParser.get('config', 'ftp_picture_directory')
|
||||
ftp_log_directory = configParser.get('config', 'ftp_log_directory')
|
||||
ftp_user = configParser.get('config', 'ftp_user')
|
||||
ftp_pw = configParser.get('config', 'ftp_pw')
|
||||
picture_directory = configParser.get('config', 'picture_directory')
|
||||
log_directory = configParser.get('config', 'log_directory')
|
||||
camera_number = configParser.get('config', 'camera_number')
|
||||
enable_modem = configParser.get('config', 'enable_modem')
|
||||
picture_size = int(configParser.get('config', 'picture_size'))
|
||||
internet = configParser.get('config', 'internet')
|
||||
modem_apn = configParser.get('config', 'modem_apn')
|
||||
upload_only = int(configParser.get('config', 'upload_only'))
|
||||
interval = int(configParser.get('config', 'interval'))
|
||||
ioBoard = configParser.get('config', 'I/O_Board')
|
||||
mute = configParser.get('config', 'mute')
|
||||
wakeup_Time = str(configParser.get('config', 'wakeup_Time')).split(',')
|
||||
bed_Time = str(configParser.get('config', 'bed_Time')).split(',')
|
||||
tvOut = configParser.get('config', 'TV_Output')
|
||||
width = configParser.get('config', 'Width')
|
||||
height = configParser.get('config', 'Height')
|
||||
rebootCMD = configParser.get('config', 'Reboot')
|
||||
|
||||
print('done!')
|
||||
|
||||
print('initializing logger...')
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
try:
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
except Exception as er:
|
||||
print('[Logger] Could not create .log' + str(er))
|
||||
print('[USB] Could not find USB storage!')
|
||||
while 1:
|
||||
checkConnectionToFTPServer()
|
||||
if internet == 'true' and internetTmp == 'false':
|
||||
if internetTmp == 'false':
|
||||
rebootFlag = 'true'
|
||||
print('[Timelapse Core] Reboot Flag set')
|
||||
if rebootFlag == 'true':
|
||||
rebootSystem()
|
||||
print('[Timlapse Core] Waiting for maintenance!')
|
||||
sleep(3600)
|
||||
logging.info('starting camera version: ' + version)
|
||||
print('done')
|
||||
print('reading picture number...')
|
||||
try:
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
except Exception as ea:
|
||||
print('No picture_Number.txt found. Creating new .. ')
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(0))
|
||||
f.close()
|
||||
f = open("/home/pi/picture_Number.txt", 'r')
|
||||
picture_number = int(f.read())
|
||||
f.close()
|
||||
logging.info('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('Maybe a fatal error occourd! New picture_Number was created. Risk of redundancy!')
|
||||
print('done, picture number is:', str(picture_number))
|
||||
print('sleeping for 15 seconds until boot is finished!')
|
||||
|
||||
sleep(15)
|
||||
|
||||
camera = PiCamera()
|
||||
upload_every = upload_only
|
||||
internetTmp = internet
|
||||
rebootFlag = 'false'
|
||||
|
||||
if ioBoard == "true":
|
||||
print('Running with the nice IO board!')
|
||||
spi = SpiDev()
|
||||
spi.open(0, 0)
|
||||
spi.max_speed_hz = 5000
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setup(piezo, GPIO.OUT)
|
||||
GPIO.setup(bootSwitch, GPIO.IN)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
#camera = PiCamera()
|
||||
camera.resolution = (3280, 2464) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.awb_mode = 'auto'
|
||||
camera.start_preview()
|
||||
# camera.start_preview(fullscreen=False, window = (100, 20, 960, 720))
|
||||
print('---starting sharpness tool---')
|
||||
print('--------normal output--------')
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
sleep(5)
|
||||
if GPIO.input(bootSwitch) == 0:
|
||||
camera.stop_preview()
|
||||
print('---------zoom output---------')
|
||||
camera.crop = (0.5, 0.5, 0.3, 0.4)
|
||||
camera.start_preview()
|
||||
while GPIO.input(bootSwitch) == 0: sleep(1)
|
||||
camera.stop_preview()
|
||||
else:
|
||||
camera.stop_preview()
|
||||
camera.close()
|
||||
if mute == "false":
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(1)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
else:
|
||||
print('Running without the nice IO board!')
|
||||
|
||||
if rebootCMD == 'true':
|
||||
print('Automatic reboot is allowed while wake up!')
|
||||
logging.info('Automatic reboot is allowed while wakeup!')
|
||||
|
||||
if tvOut == 'false':
|
||||
stdoutdata = subprocess.getoutput('sudo /usr/bin/tvservice -o ')
|
||||
print('[TV Out] Status: ' + stdoutdata)
|
||||
logging.info('[TV Out] Status: ' + stdoutdata)
|
||||
|
||||
if internetTmp == 'true':
|
||||
print('Running in Online mode, internet connection is required')
|
||||
if enable_modem == 'true': reconnectToInternet()
|
||||
try:
|
||||
ftp = FTP(ftp_url, ftp_user, ftp_pw, timeout=20)
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
print('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
logging.info('New ftp connection successful! current dicertory is: ' + ftp.pwd())
|
||||
except Exception as ea:
|
||||
print('no internet or ftp connection on startup trying to reconnect later!')
|
||||
logging.error('no internet or ftp connection on startup trying to reconnect later!')
|
||||
internetTmp = 'false'
|
||||
else:
|
||||
print('Running in Offline mode, no internet connection is required')
|
||||
|
||||
# camera.framerate = 15 #Fraction(2,6) #framrate 15 bei video und 2592x1944
|
||||
# camera.shutter_speed = 500000
|
||||
|
||||
|
||||
# camera.brightness = 50 #0 bis 100; default 50
|
||||
# camera.contrast = 0 #-100 bis 100; default 0
|
||||
# camera.iso = 0 #0 bis 1600; default 0(auto)
|
||||
# camera.zoom = (0, 0, 1.0, 1.0) #0.0 bis 1.0 (x, y, w, h)
|
||||
# camera.sharpness = 0 #-100 bis 100; default 0
|
||||
|
||||
print('[Camera] Resolution: ' + width + 'x' + height)
|
||||
logging.info('[Camera] Resolution: ' + width + 'x' + height)
|
||||
|
||||
|
||||
# main programm (endless loop)
|
||||
while 1:
|
||||
try:
|
||||
time_next_unix = time.time() + interval # time for next picture
|
||||
time_name = time.asctime(time.localtime(time.time())) # get time for picture_name
|
||||
time_name = time_name.replace(" ", "_")
|
||||
time_name = time_name.replace(":", "-")
|
||||
picture_name = camera_number + '_' + str(picture_number).zfill(6) + '_' + time_name + '.jpg'
|
||||
picture_path = picture_directory + picture_name
|
||||
|
||||
print("Time:", time_name)
|
||||
#camera = PiCamera()
|
||||
camera.resolution = (int(width), int(height)) # aufloesung der bilder maximal 3280,2464s
|
||||
camera.exposure_mode = 'auto'
|
||||
camera.awb_mode = 'auto'
|
||||
camera.crop = (0, 0, 0, 0)
|
||||
try:
|
||||
camera.exif_tags['IFD0.Make'] = 'CopterSicht'
|
||||
camera.exif_tags['IFD0.Model'] = 'Long Term Timelapse Camera'
|
||||
camera.exif_tags['IFD0.ShutterSpeedValue '] = ''
|
||||
camera.exif_tags['IFD0.ISOSpeedRatings '] = ''
|
||||
camera.exif_tags['IFD0.WhiteBalance '] = ''
|
||||
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) ' + str(datetime.now().year) + ' CopterSicht'
|
||||
camera.exif_tags['IFD0.ImageDescription'] = 'interval capture'
|
||||
|
||||
if mute == "false": GPIO.output(piezo, GPIO.HIGH)
|
||||
print('Capturing image')
|
||||
logging.info('[Camera] Capturing image')
|
||||
camera.capture(picture_path) # capture image and save to picture_path (picture_directory + picture_name)
|
||||
#camera.close()
|
||||
if mute == "false": GPIO.output(piezo, GPIO.LOW)
|
||||
picture_number += 1 # increase picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
except Exception as e2:
|
||||
logging.error(str(e2))
|
||||
|
||||
print('Picture size:', os.path.getsize(picture_path), "Byte")
|
||||
logging.info('[Camera] Picture size: ' + str(os.path.getsize(picture_path)) + ' Byte')
|
||||
checkDiskSpace()
|
||||
if ioBoard == "true": checkSystemVoltage()
|
||||
if os.path.getsize(picture_path) < picture_size:
|
||||
print('it seems to be night!')
|
||||
logging.info('it seems to be night!')
|
||||
midnight1 = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds1 = (datetime.now() - midnight1).seconds # seconds since midnight
|
||||
if seconds1 > float(wakeup_Time[datetime.now().month - 1]) * 60 * 60 and seconds1 < float(bed_Time[
|
||||
datetime.now().month - 1]) * 60 * 60: # if it is before 5pm, it cann't be night -> not going to sleep
|
||||
print('cannot be night!')
|
||||
logging.warning('cannot be night!')
|
||||
print("uploadTimer", upload_every)
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
#checkCpu()
|
||||
#sleepToNextPicture()
|
||||
else:
|
||||
os.remove(picture_path) # deleting picture because it's night!
|
||||
picture_number -= 1 # decrease picture_number
|
||||
print('picture_number:', str(picture_number))
|
||||
f = open("/home/pi/picture_Number.txt", 'w')
|
||||
f.write(str(picture_number)) # save picture_number to a text file
|
||||
f.close()
|
||||
# uploading log file
|
||||
print('skipping picture upload!')
|
||||
print('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': print('uploading todays log befor going to sleep!')
|
||||
logging.info('skipping picture upload!')
|
||||
logging.info('sleeping until ' + str(wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
if internetTmp == 'true': logging.info('uploading todays log befor going to sleep!')
|
||||
if internetTmp == 'true':
|
||||
try:
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('[FTP] uploaded log-file successful!')
|
||||
logging.info('[FTP] uploaded log-file successful!')
|
||||
except Exception as e:
|
||||
print('[FTP] upload failed!')
|
||||
print(e)
|
||||
logging.error('[FTP] upload failed!')
|
||||
logging.error(str(e))
|
||||
try:
|
||||
print('[FTP] trying to reconnect ...')
|
||||
logging.info('[FTP]trying to reconnect ...')
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('[FTP] re-connecting ftp successful!')
|
||||
logging.info('[FTP]re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('uploaded log-file successful!')
|
||||
logging.info('uploaded log-file successful!')
|
||||
except Exception as e8:
|
||||
print('[FTP] re-connecting failed!')
|
||||
print(e8)
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
logging.error(str(e8))
|
||||
if reconnectToInternet() == 'true':
|
||||
print('Reconnect successful')
|
||||
logging.info('[Internet] Reconnect successful!')
|
||||
try:
|
||||
print()
|
||||
ftp.connect(ftp_url)
|
||||
ftp.login(ftp_user, ftp_pw)
|
||||
print('re-connecting ftp successful!')
|
||||
ftp.cwd(ftp_log_directory)
|
||||
ftp.storbinary('STOR ' + log_name, open(log_directory + log_name, 'rb'), 1024)
|
||||
ftp.sendcmd('SITE CHMOD 754 ' + log_name)
|
||||
print('[FTP] uploaded log-file successful!')
|
||||
logging.info('[FTP] uploaded log-file successful!')
|
||||
except Exception as e4:
|
||||
print('[FTP] re-connecting failed!')
|
||||
logging.error('[FTP] re-connecting failed!')
|
||||
print(str(e4))
|
||||
logging.error(str(e4))
|
||||
else:
|
||||
print('Reconnect failed')
|
||||
logging.error('[Internet] Reconnect failed!')
|
||||
try:
|
||||
ftp.cwd(ftp_picture_directory)
|
||||
except Exception as er:
|
||||
print('[FTP] could not change ftp directory !')
|
||||
logging.error('[FTP] could not change ftp directory !')
|
||||
print(str(er))
|
||||
logging.error(str(er))
|
||||
|
||||
if internet == 'true' and internetTmp == 'false':
|
||||
print('[Timelapse Core] Checking again Internet Connection before sleep')
|
||||
logging.info('[Timelapse Core] Checking again Internet Connection before sleep')
|
||||
checkConnectionToFTPServer()
|
||||
if internetTmp == 'false':
|
||||
rebootFlag = 'true'
|
||||
print('[Timelapse Core] Reboot Flag set')
|
||||
logging.info('[Timelapse Core] Reboot Flag set')
|
||||
if mute == "false":
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.HIGH)
|
||||
sleep(0.5)
|
||||
GPIO.output(piezo, GPIO.LOW)
|
||||
sleep(0.5)
|
||||
|
||||
# sleep until next morning
|
||||
print('going to sleep for a while ...')
|
||||
logging.info('going to sleep for a while ...')
|
||||
midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
seconds = (datetime.now() - midnight).seconds # seconds since midnight
|
||||
if seconds < (
|
||||
float(wakeup_Time[
|
||||
datetime.now().month - 1]) * 60 * 60): # if time between 0am and wakeup_Time
|
||||
sleep_time = (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60) - seconds
|
||||
else: # if time between wakeup_Time and 12pm
|
||||
sleep_time = 86400 - seconds + (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60)
|
||||
print('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
logging.info('sleeping now ' + str(sleep_time) + ' seconds or until ' + str(
|
||||
wakeup_Time[datetime.now().month - 1]) + 'am!')
|
||||
sleep(sleep_time - 10)
|
||||
|
||||
# wake up 10 seconds before we should for exact start
|
||||
print(str((datetime.now() - midnight).seconds) + ' < ' + str(
|
||||
(wakeup_Time[datetime.now().month - 1] * 60 * 60)))
|
||||
while (datetime.now() - midnight).seconds < (float(wakeup_Time[datetime.now().month - 1]) * 60 * 60):
|
||||
sleep(0.5)
|
||||
log_name = camera_number + '_' + str(datetime.now().strftime("%A %d. %B %Y")) + '.log'
|
||||
log_name = log_name.replace(" ", "-")
|
||||
logging.getLogger('').handlers = []
|
||||
logging.basicConfig(filename=log_directory + log_name, format='%(asctime)s [%(levelname)s] %(message)s',
|
||||
level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||
print('slept for ' + str(sleep_time) + ' seconds')
|
||||
print('Time to wakeup! \n')
|
||||
logging.info('Camera versiom: ' + version)
|
||||
logging.info('slept for ' + str(sleep_time) + ' seconds')
|
||||
logging.info('Time to wakeup! \n')
|
||||
if rebootFlag == 'true':
|
||||
rebootSystem()
|
||||
else:
|
||||
|
||||
if (internetTmp == 'true') and (upload_every == 1):
|
||||
uploadToFTP()
|
||||
upload_every = upload_only
|
||||
else:
|
||||
upload_every -= 1
|
||||
if upload_every < 0:
|
||||
upload_every = 0
|
||||
if upload_every == 0:
|
||||
logging.info('Skipping upload. Next picture will be uploaded')
|
||||
print('Skipping upload. Next picture will be uploaded')
|
||||
else:
|
||||
logging.info('Skipping upload. Next upload in ' + str(upload_every) + ' pictures')
|
||||
print('Skipping upload. Next upload in', (upload_every), 'pictures')
|
||||
|
||||
if internet == 'true' and internetTmp == 'false':
|
||||
checkConnectionToFTPServer()
|
||||
|
||||
checkCpu()
|
||||
sleepToNextPicture()
|
||||
|
||||
except Exception as loopError:
|
||||
print('[Timlapse Core] ' + str(loopError))
|
||||
try:
|
||||
logging.error('[FTP] could not change ftp directory !')
|
||||
except Exception as er:
|
||||
print('[Timlapse Core] Could not log: ' + str(er))
|
||||
|
||||
|
||||
23
Software/ZK_python/config.txt
Normal file
23
Software/ZK_python/config.txt
Normal file
@ -0,0 +1,23 @@
|
||||
[config]
|
||||
ftp_url = schuttercloud.com
|
||||
ftp_picture_directory = /camera03/Position02
|
||||
ftp_log_directory = /logs
|
||||
ftp_user = uploader
|
||||
ftp_pw = XXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
enable_modem = true
|
||||
picture_directory = /media/usb/pictures/
|
||||
log_directory = /media/usb/log/
|
||||
picture_size = 2300000
|
||||
camera_number = 03
|
||||
internet = true
|
||||
modem_apn = web.vodafone.de
|
||||
upload_only = 1
|
||||
interval = 300
|
||||
I/O_Board = false
|
||||
mute = true
|
||||
wakeup_Time: 8,8,7,7,6,5.5,6,6.5,7.5,7.5,8,8
|
||||
bed_Time: 17,17.5,18,20,20.5,21.5,21.5,20.5,19.5,17.5,16.5,16.5
|
||||
TV_Output: false
|
||||
Width: 3280
|
||||
Height: 2464
|
||||
Reboot: false
|
||||
49
Software/banner.txt
Normal file
49
Software/banner.txt
Normal file
@ -0,0 +1,49 @@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@(.@@@@@@@@@@@@@ .@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&&@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@ @@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@%@@@@@@@@@@@@
|
||||
@@@@@@@@@@ .@@@@@@@@% %@ @# ./. .% . & & . .@@@@@@@@@@
|
||||
@@@@@@@@@ @@@@@@@@@@@@@@@ @@@@ @@@@@@@ @@@@& @@@@@@@@@@@ % @@@@@@@@@ @@@@@@@@@@@
|
||||
@@@@@@@@@# @ .@@@ @@@ ,@ @@@@@/ @@@@ @ @@@@@@@@@@@
|
||||
@@@@@@@# *@ @@@&&&& , @@@,*@@ @@@@@@@@@
|
||||
@@@@@@@ @@@@@@@@@
|
||||
@@@@@@@@@(@@@@@@@@@@@@@@@ @@@@@@.@ /@@@@@@@ @@@@@@@@@@*@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@(@ @@@@@@ @@@@@& @@@@@@@@@ @@@@@@@@@@@@@ *@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@( @@@@@@@@@@@ @ @@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@ @@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@# @@, %.@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@ %@@ @@%@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@ @@@ @ @%@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@ @@@ @ @@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@ * *@@@@ @@@ @@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@, @@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ %@@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ /@@@( %@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@ @@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@ @@ @ ,@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@ ______ __ ______ __ __ __ @
|
||||
@ / \ / | / \ / | / | / | @
|
||||
@ /$$$$$$ | ______ ______ _$$ |_ ______ ______ /$$$$$$ |$$/ _______ $$ |____ _$$ |_ @
|
||||
@ $$ | $$/ / \ / \ / $$ | / \ / \ $$ \__$$/ / | / |$$ \ / $$ | @
|
||||
@ $$ | /$$$$$$ |/$$$$$$ |$$$$$$/ /$$$$$$ |/$$$$$$ |$$ \ $$ |/$$$$$$$/ $$$$$$$ |$$$$$$/ @
|
||||
@ $$ | __ $$ | $$ |$$ | $$ | $$ | __ $$ $$ |$$ | $$/ $$$$$$ |$$ |$$ | $$ | $$ | $$ | __ @
|
||||
@ $$ \__/ |$$ \__$$ |$$ |__$$ | $$ |/ |$$$$$$$$/ $$ | / \__$$ |$$ |$$ \_____ $$ | $$ | $$ |/ | @
|
||||
@ $$ $$/ $$ $$/ $$ $$/ $$ $$/ $$ |$$ | $$ $$/ $$ |$$ |$$ | $$ | $$ $$/ @
|
||||
@ $$$$$$/ $$$$$$/ $$$$$$$/ $$$$/ $$$$$$$/ $$/ $$$$$$/ $$/ $$$$$$$/ $$/ $$/ $$$$/ @
|
||||
@ $$ | @
|
||||
@ $$ | https://coptersicht.de @
|
||||
@ $$/ @
|
||||
X-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-X
|
||||
@ @
|
||||
@ Basic Image: basic04.img Camera: TLCXX Creation date: XX.XX.20XX @
|
||||
@ @
|
||||
X-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-X
|
||||
20
Software/createMonthFolder.sh
Normal file
20
Software/createMonthFolder.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
for D in `find . -type d`
|
||||
do
|
||||
echo $D
|
||||
mkdir $D/01_January
|
||||
mkdir $D/02_February
|
||||
mkdir $D/03_March
|
||||
mkdir $D/04_April
|
||||
mkdir $D/05_May
|
||||
mkdir $D/06_June
|
||||
mkdir $D/07_July
|
||||
mkdir $D/08_August
|
||||
mkdir $D/09_September
|
||||
mkdir $D/10_October
|
||||
mkdir $D/11_November
|
||||
mkdir $D/12_December
|
||||
|
||||
|
||||
done
|
||||
Reference in New Issue
Block a user