I tried to find a PHP class to control the new camera, and I couldn’t find one… so a little packet sniffing later, I was able to figure out how it’s little Java applet communicates with the camera. Anyway, I spent a few minutes to make a PHP class to control the camera, so if you need one, here you go (it hasn’t been extensively tested, so it probably has problems… if it does, leave a comment)…
So here’s a basic PHP script that uses the class to take control of the camera, set the pan/tilt/zoom to a certain position, capture the image and save it to a file… handy for uhm… I dunno… a cron job to take time lapse photography. π
[code=php]connect(‘your.camera.ip.address’);
$cam->get_control();
$cam->goto( -7463, -548, 4126);
sleep(5); // Wait for movement to finish and lens to focus
$handle = fopen(‘images/’ . time() . ‘.jpg’, ‘w’);
fwrite ($handle, $cam->image());
fclose ($handle);
$cam->disconnect();
?>[/code]
class_camera.php:[code=php]host = $host;
return $this->connection_id = substr(file_get_contents (‘//’ . $host . ‘/-wvhttp-01-/OpenCameraServer?client_version=LiveApplet_4125&image_size=640×480’), 14, 9);
}
/**
* Disconnects from the camera
*
* @return none
*/
function disconnect()
{
file_get_contents (‘//’ . $this->host . ‘/-wvhttp-01-/CloseCameraServer?connection_id=’ . $this->connection_id);
}
/**
* Attempts to get control of camera
*
* @return none
*/
function get_control()
{
file_get_contents (‘//’ . $this->host . ‘/-wvhttp-01-/GetCameraControl?connection_id=’ . $this->connection_id);
}
/**
* Get camera info
*
* @return array of camera info variables
*/
function get_info()
{
preg_match_all (‘#(.*?)=(.*)#’, file_get_contents (‘//’ . $this->host . ‘/-wvhttp-01-/GetCameraInfo?connection_id=’ . $this->connection_id), $matches);
foreach ($matches[1] as $key => $value) {
$this->camera_info[$value] = $matches[2][$key];
}
return($this->camera_info);
}
/**
* Move camera
*
* @param string Movement type (pan | tilt | zoom)
* @param number Position to move to
*
* @return none
*/
function move($operation, $position = 0)
{
file_get_contents (‘//’ . $this->host . ‘/-wvhttp-01-/OperateCamera?’ . $operation . ‘=’ . $position . ‘&connection_id=’ . $this->connection_id);
}
/**
* Set pan/tilt/zoom on camera with one call
*
* @param number pan position
* @param number tilt position
* @param number zoom position
*
* @return none
*/
function goto($pan, $tilt, $zoom)
{
$this->move(‘pan’, $pan);
$this->move(’tilt’, $tilt);
$this->move(‘zoom’, $zoom);
}
/**
* Set parameter
*
* @param string paramter to set
* @param string value
*
* @return none
*/
function set_value($parameter, $value)
{
$mapping = array (
‘back_light’ => ‘B’,
);
$parameter = $mapping[$parameter];
file_get_contents (‘//’ . $this->host . ‘/-wvhttp-01-/OperateCamera?’ . $parameter . ‘=’ . $value . ‘&connection_id=’ . $this->connection_id);
}
/**
* Get current image
*
* @return none
*/
function image()
{
return file_get_contents (‘//’ . $this->host . ‘/-wvhttp-01-/GetOneShot?image_size=640×480’);
}
}
?>[/code]