OpenWrt webcam

Install in OpenWrt:
kmod-video-uvc
mjpg-streamer
luci-app-mjpg-streamer
//refresh
//Go to: services/mpg-streamer
//Set it to: enabled
//That will be all
//Optional: Setup security and other parameters

A still image will be available on:
http://192.168.130.1:8080/?action=stream
The stream will be available on:
http://192.168.130.1:8080/?action=snapshot

//—————————-
//Optional:
//If you wanna go further and send a still image directly from the router to some site:

//download it with:

curl -o /www/webcam/images/image.jpg http://192.168.130.1:8080/?action=snapshot
//upload it to your server with:
curl -F "upimage=@/www/webcam/images/image.jpg" http://yourserver.com/upload.php

//to get the code executed each x seconds, set a cron job, or run a command like this:

while true; do date ; curl -o /www/webcam/images/image.jpg http://192.168.130.1:8080/?action=snapshot ; curl -F "upimage=@/www/webcam/images/image.jpg" http://yourserver.com/upload.php ; sleep 10; done

The server PHP code to save the images:

$source = $_FILES["upimage"]["tmp_name"];
$destination = "image.jpg";
echo move_uploaded_file($source, $destination) ? "OK" : "ERROR";

//To see the image you go to url below
http://yourserver.com/image.jpg
//Refresh to get a new one

//Or you can add a simple html/javascript code that does the trick for you:

function refreshIt(element) {
setTimeout(function() {
element.src = element.src.split('?')[0] + '?' + new Date().getTime();
refreshIt(element);
}, 10000); // refresh every 10 seg
}

<img=”” src=”/image.jpg” name=”myCam” onload=”refreshIt(this)”>

References:

https://openwrt.org/docs/guide-user/hardware/video/usb.video
https://www.you tube.com/watch?v=KlfS-oO_2Sw
https://stackoverflow.com/questions/8459896/auto-update-image/8459978

AC.


This entry was posted in Linux and tagged , . Bookmark the permalink.

Comments are closed.