Webcam project

This project is mostly based on what i had laying around, And is not a model of what to do, but maybe some inspiration.

Items used

Step 1 - Enable anonymus Snapshot - on the camera

To do this with a unify camera you need to login directly to the camera. anecdoctialy if you have not adopted the camera into Unifi Protect. the username/pass should be ubnt/ubnt. if the camera is addopted you have to login to protect go to system and find the field called Recovery Code here you can reviel the code. use a browser and open the IP of the camera where you will be prompted for credentielas the username is ubnt and the password is the recovery code.

After you login you can tick the box Enable Anonomus Snapshot and click save.


enablesnap


http://[cameraIP]/snap.jpeg will now be directly avalable.

Step 2 - make it public.

This could probably be done a thoundsands ways, but for me it was solved by a Raspberry pi acting as a middle man.

  1. cd to the folder you want.
  2. Downloading picture.
  3. Resize picture using https://imagemagick.org.
  4. Upload picture to webserver.
  5. cleanup.
# snap.sh
cd /path/to/folder/
wget http://[cameraIP]/snap.jpeg
convert -resize 1200x snap.jpeg snap.jpeg
scp -i keypair.pem snap.jpeg [user]@[host]:htdocs/img/snaps/snap.jpeg
rm snap.jpeg

Step 3 - Run it on a schedule

use crontab -e to add the line:

*/2 * * * * /Path/to/folder/snap.sh

This will call the script every 2 minuts.

Step 4 Create a gif of the last months weather

On the webserver create the following shell script

# Go to folder
cd /path/to/view/

# create a filename of the pic of the day
day=$(date +%d)
month=$(date +%m)
year=$(date +%y)
name="$year-$month-$day.jpeg"

# copy the current snap to the pic of the day
a="cp /path/to/snap.jpeg /path/to/view/$name"
eval $a

# move images older than 30 days to backup folder
find /path/to/view/ -type f -mtime +30 -name '*.jpeg' -exec mv {} /path/to/oldSnaps/ \;

# create gif of all remaining jpegs
convert -delay 100 -loop 0 *.jpeg snaps.gif

And adding it to run daly on the web server.

again use crontab -e to add the line:

5 12 * * * /Path/to/folder/createDailySnap.sh

Result

view