Donnerstag, 28. August 2014

DSLR freeze - cam reset implemented

In some rare cases the DSLR freezes.
In this situation a power reset of the DSLR was the only way, to get it back to normal operation.
Due to the fact that the cam will be mounted on the roof of a house, the option of a remote-power-reset is desirable.
The idea was to switch a relay by one of the GPIO-ports of Raspi, remotely controlled via web-frontend.
Bash script 'camera_reset.sh':
#!/bin/bash
gpio mode 7 out
sleep 2
gpio write 7 1
sleep 3
gpio write 7 0
sleep 2
gpio mode 7 in
The "sleep" delays between the commands were necessary, to create a stable situation during command execution.
If the commands were executed without the delays, in some cases the commands were not executed properly or the RASPI freezes.
It was necessary, to use GPIO7 instead of GPIO16 or GPIO15, because GPIO16 and GPIO15 were immediately active during reboot of the raspi, and remained active - so the cam was not powered after a reboot of the raspi.
GPIO7 remains inactive (0) after reboot - so the cam is directly powered after reboot.
Also GPIO's 15 and 16 were not really stable.
In some cases the RASPI was freezed after switching GPIO15 or 16 as an OUT to 1 or 0.
Since I use GPIO7, I never experienced any freeze of the RASPI.
GPIO numbering:
WiringPi GPIO7 = Raspi GPIO4 = Raspi Pin7
see here:
http://wiringpi.com/wp-content/uploads/2013/03/gpio1.png
(howto's for script execution from a website, and the realized electrical circuit see earlier posts)

electrical part: raspi, poe splitter, camera, cam reset circuit (gpio)

as followed a few pictures, which show the electrical part of the outdoor timelapse cam

the wiring of the parts
(red cable is data and power input, white cable 7,5V for DSLR, black cable 5V for RaspberryPi)

circuit drawing, 7,5V output for DSLR with RaspberryPi controlled power reset, stabilized 5V output for RaspberryPi power




Sonntag, 24. August 2014

shell script automatic captures limited to specified daytime

if the shell script, which controls the automatic captures, shall be executed from 5:00h to 21:59h, do like this:
(daytime greater or equal 5:00h lower or equal 21:00h)

#!/bin/bash
host='YOURHOSTNAME'
USER='YOURUSERNAME'
PASS='YOURPASSWORD'
hour=`date +"%H"`
while [ $hour -ge 5 ] && [ $hour -le 21 ]
do
/usr/bin/gphoto2 --capture-image-and-download --filename
ftp -n -v $host <<EOT
ascii
user $USER $PASS
prompt
cd /array1/EigeneD/EigeneCaptures/
put *.JPG
bye
EOT
cp *.JPG /var/www/minigal/photos/last.JPG
rm *.JPG
echo warte 20 sek
sleep 20
done

Freitag, 15. August 2014

start shell script daily at 5:00am

edit /etc/crontab:

# sudo nano /etc/crontab

add line:
0 5    * * *   root    /home/YOUR_USER/YOUR_SCRIPT

REMARK:
if you change anything in crontab, you have to restart cron:
# sudo /etc/init.d/cron restart


Donnerstag, 14. August 2014

allow 'sudo' from browser for script

if you want to execute a script by browser input, you need to allow the webserver-user 'www-data' to use 'sudo' without the need to use sudo-password.

Therefore you use 'visudo' to edit /etc/sudoers, and add the follwing line at the end of the file:

www-data ALL=NOPASSWD: /home/YOUR_USER/YOUR_SCRIPT.sh



stop linux process from website with php

content for html-file:

<html>
<body>
<?php
if ($_GET['run']) {
  # This code will run if ?run=true is set.
  exec("sudo /home/pi/kill.sh", $output2);
}
?>
<!-- This link will add ?run=true to your URL, myfilename.php?run=true -->
<a href="?run=true"><img src="stop-button.png" width="200" 0height="160" border="0" alt="stop"></a>
</body>
</html>


content for shell script:

sudo killall capture_endless

start linux shell script from website with php

html code:

<html>
<body>
<?php
if ($_GET['run']) {
  # This code will run if ?run=true is set.
  exec("/home/YOUR_USER/YOUR_SCRIPT.sh", $output);
}
?>
<a href="?run=true">START</a>
</body>
</html>

show linux process status on a website with php

html code:

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<center>
<?php
  exec("ps ax | grep PROCESS_NAME | grep -v grep 2>&1", $output, $ret);
?>
<table>
<tr>
<td align="undefined" valign="undefined">
<h2>
<?php if ($ret == "0") { echo "PROCESS IS RUNNING..."; } else {echo "PROCESS IS STOPPED"; } ?> </td>
</h2>
</tr>
</table>
</body>
</html>

linux shell script for endless photo capture with gphoto2 and automatic ftp-upload

linux shell script sourcecode:

#!/bin/bash
host='YOUR_HOSTNAME'
USER='YOUR_USERNAME'
PASS='YOUR_PASSWORD'
counter=1
while true
do
/usr/bin/gphoto2 --capture-image-and-download --filename
ftp -n -v $host <<EOT
ascii
user $USER $PASS
prompt
cd /YOUR_FOLDER_ON_FTP_SERVER_WHERE_PHOTOS_SHALL_PLACED/
put *.JPG
bye
EOT
cp *.JPG /var/www/YOUR_WEBSERVER_FOLDER_WHERE_A_COPY_SHALL_PLACED/last.JPG
rm *.JPG
echo waiting 20 sec
sleep 20
done

show datetime from JPG exif data with php

php-code:


<?php
$exif = exif_read_data('IMAGE.JPG', 'IFD0', 0);
$edate = $exif['DateTime'];
if (strlen($edate) > 0) echo "<h2>Date/Time $edate</h2>";
?>



read complete exif data from JPG with php

php-code:


<?php
echo "IMAGE.JPG:<br />\n";
$exif = exif_read_data('IMAGE.JPG', 'IFD0');
echo $exif===false ? "Keine Headerdaten gefunden.<br />\n" : "Bild beinhaltet Header<br />\n";

$exif = exif_read_data('IMAGE.JPG', 0, true);
echo "IMAGE.JPG:<br />\n";
foreach ($exif as $key => $section) {
    foreach ($section as $name => $val) {
        echo "$key.$name: $val<br />\n";
    }
}
?>