Some background:I have been using CHDK before, mostly to shoot HDR, and take timelapse series on my old PowerShot SD600. I am currently building a more advanced timelapse rig that consists of a PowerShot A800 with CHDK on, a raspberry pi, an external drive to store photos on, and an old Linksys WAP54G running DD-WRT. The basic idea is to use PTP to control the camera from the raspberry pi, and download the photos from the camera to the external drive for storage. Then to download the photos over WLAN from time to time.
Setup:The Powershot A800 is running version "a800-100c-1.1.0-2669-full_BETA" of CHDK. Connected to the raspberry pi via USB.
The raspberry pi runs Raspbian wheezy, and connects to the camera with chdkptp r311.
I have the following two scripts:
chdkptp.sh:
#!/bin/sh
CHDKPTP_DIR=/path/to/chdkptp
export LD_LIBRARY_PATH=/path/to/iup:/path/to/cd
export LUA_PATH="$CHDKPTP_DIR/lua/?.lua"
"$CHDKPTP_DIR/chdkptp" "$@"
getPhotos.php:
<?php
function execCommand($command) {
$result = shell_exec($command." 2>&1");
if (stripos(strtolower($result), "error") !== false) {
die($result);
}
}
$initCommand = "./chdkptp.sh -c -e\"luar switch_mode_usb(1)\" -e\"exec os.execute(\\\"sleep 3\\\")\" -e\"luar set_aflock(1)\"";
$photoCommand = "./chdkptp.sh -c -e\"shoot\"";
$downloadCommand = "./chdkptp.sh -c -e\"mdownload -overwrite=n DCIM temp\"";
$deleteCommand = "./chdkptp.sh -c -e\"rm DCIM\"";
echo("Initializing camera ... ");
execCommand($initCommand);
echo("Done\n");
usleep(500000);
$nextPhoto = microtime(true);
while (true) {
echo(date("Y-m-d H:i:s")." Taking photo ... ");
$startTime = microtime(true);
execCommand($photoCommand);
$elapsedTime = microtime(true) - $startTime;
echo("done in $elapsedTime seconds.\t\t");
usleep(500000);
shell_exec($downloadCommand);
usleep(500000);
shell_exec($deleteCommand);
$nextPhoto += 15;
if ($nextPhoto > microtime(true)) {
echo("Sleeping for ".($nextPhoto - microtime(true))." seconds.\n");
time_sleep_until($nextPhoto);
} else {
echo("Not sleeping.\n");
}
}
?>
The problem:When i run the script getPhotos.php it works as intended at first. But after a while (1-100 images or so) the camera seems to crash. After that the camera does not respond to any interaction (PTP, pressing buttons - even the power button), and the only solution seems to be to cycle the power to the camera. This has happend after seemingly random number of images in the interval 1-100, and it seems that the downloading of the photos is the command that triggers this behavior (since, when i comment out that row "shell_exec($downloadCommand);", it works).
I have tried replacing the camera (to a PowerShot SD940) with the same result.
I have tried to use gphoto2 for downloading and deleting the photos from the camera with similar result (not the same error message, but it crashes during download and/or delete). This leads me to believe that the error is somewhere in CHDK.
Here is some output from running the getPhotos.php script:
pi@raspberrypi ~/timelapse $ php -f getPhotos.php
Initializing camera ... Done
2013-04-07 13:30:40 Taking photo ... done in 5.063178062439 seconds. Sleeping for 6.0421028137207 seconds.
2013-04-07 13:30:55 Taking photo ... done in 5.2359209060669 seconds. Sleeping for 5.6417889595032 seconds.
2013-04-07 13:31:10 Taking photo ... done in 5.6660900115967 seconds. Sleeping for 5.2321989536285 seconds.
[Had to cut away some rows here to make the post less than 7500 characters, but you get the idea...]
2013-04-07 13:40:40 Taking photo ... done in 5.225909948349 seconds. Sleeping for 5.9199287891388 seconds.
2013-04-07 13:40:55 Taking photo ... done in 5.2258448600769 seconds. unexpected return code 0x2fd
ERROR: ptp error
ERROR: Could not close session!
ERROR: no matching devices found
ERROR: not connected
Sleeping for 7.1426119804382 seconds.
2013-04-07 13:41:10 Taking photo ... ERROR: no matching devices found
ERROR: not connected
pi@raspberrypi ~/timelapse $ php -f getPhotos.php
Initializing camera ... ERROR: no matching devices found
ERROR: not connected
ERROR: not connected
And a similar run using gphoto2 to download the images:
pi@raspberrypi ~/timelapse $ php -f getPhotos.php
Initializing camera ... Done
2013-04-07 13:48:59 Taking photo ... done in 5.1752691268921 seconds. Downloading 'IMG_0541.JPG' from folder '/store_00010001/DCIM/100___04'...
*** Error ***
PTP I/O error
*** Error ***
An error occurred in the io-library ('Unspecified error'): The supplied vendor or product id (0x0,0x0) is not valid.
*** Error (-1: 'Unspecified error') ***
The change to the getPhotos.php script to use gphoto2 is to use the following definitions instead of the original ones:
$downloadCommand = "cd temp && gphoto2 -P";
$deleteCommand = "gphoto2 -DR";
So, for my final questions:Am I doing something wrong, that can cause this error?
Or is this indeed a bug in CHDK? (Is it known, and is there a plan to fix it?)