Meanwhile...
My pumpkin population exploded a bit, my whole balcony is now a pumpkin jungle! How to supervise them and check if they broken out and try to take over the world? Digitus IP cam to the rescue!


Hmm.. ok I need to get a fisheye lens, else it is not possible to see the whole picture... (already ordered, crappy 5 eur toy for smartphones :D)
No, I won't let you access my private CCTV pumpkin cam ;) But here is PHP code to build one yourself...
<?
function get_one_jpeg()
{
$addr = gethostbyname("INSERT HOSTNAME OR IP HERE");
$client = stream_socket_client("tcp://$addr:4321", $errno, $errorMessage);
stream_set_timeout($client,0,50000);
fwrite($client,"0110\n");
$header = fread($client,4);
$payload_size = unpack("n*",$header)[1];
$bytes_to_go = $payload_size;
$readmore = true;
$partsize = 512;
$payload = "";
#header('Content-Type: image/jpeg');
while($readmore)
{
usleep(1000);
$rcvdata=fread($client,$partsize);
$payload.=$rcvdata;
$bytes_to_go-=strlen($rcvdata);
if($bytes_to_go <= 0)
{
$readmore = False;
}
}
fclose($client);
return $payload;
}
# Used to separate multipart
$boundary = "my_mjpeg";
# We start with the standard headers. PHP allows us this much
header("Cache-Control: no-cache");
header("Cache-Control: private");
header("Pragma: no-cache");
header("Content-type: multipart/x-mixed-replace; boundary=$boundary");
# From here out, we no longer expect to be able to use the header() function
print "--$boundary\n";
# Set this so PHP doesn't timeout during a long stream
set_time_limit(0);
# Disable Apache and PHP's compression of output to the client
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
# Set implicit flush, and flush all current buffers
@ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++)
ob_end_flush();
ob_implicit_flush(1);
# The loop, producing one jpeg frame per iteration
while (true) {
# Per-image header, note the two new-lines
print "Content-type: image/jpeg\n\n";
# Your function to get one jpeg image
print get_one_jpeg();
# The separator
print "--$boundary\n";
usleep(100000);
}
?>
MJPEG code taken from http://ben-collins.blogspot.de/2010/06/php-sending-motion-jpeg.html , thank you Ben!
rawe
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.