|
|
# simple web-cam server
|
|
|
|
|
|
## research the camera hardware
|
|
|
|
|
|
### camera
|
|
|
|
|
|
the camera unit you are considering must be able
|
|
|
to connect to wifi and/or lan
|
|
|
|
|
|
determine the following for the camera unit:
|
|
|
* the "snapshot url"
|
|
|
* the "default ip"
|
|
|
* the default username and password
|
|
|
|
|
|
most of the above is brand/model-dependent, so
|
|
|
you need to use some "google fu" to search for
|
|
|
them.
|
|
|
|
|
|
#### what is a "snapshot url"?
|
|
|
|
|
|
a "snapshot url" is a hidden ability on
|
|
|
some cameras that allows you to directly
|
|
|
download pictures from the camera without
|
|
|
having to use any app
|
|
|
|
|
|
here is an example for the **tp-link nc200**:
|
|
|
|
|
|
original source:
|
|
|
https://community.netcamstudio.com/t/tp-link-nc200-vlc-ok-but-not-in-netcam-studio/853/9
|
|
|
|
|
|
the link is actually:
|
|
|
http://admin:YWRtaW4%3D@my_lan_ip:8080/snapshot.jpg
|
|
|
|
|
|
#### default ip, default username, default password
|
|
|
|
|
|
this is the default ip address that the
|
|
|
camera will use if there is no internet
|
|
|
connection e.g. when it is connected
|
|
|
directly to a desktop/laptop
|
|
|
|
|
|
for the **tp-link nc200**, when the camera
|
|
|
fresh out of the box and connected directly
|
|
|
to a computer, the following is applicable:
|
|
|
|
|
|
* default ip: 192.168.0.10
|
|
|
* username: admin
|
|
|
* password: admin
|
|
|
|
|
|
## initial camera setup
|
|
|
|
|
|
### ensure that you connect to the camera
|
|
|
|
|
|
* plug the camera network directly into a computer
|
|
|
* switch everything on, give everything time to start up
|
|
|
* give the computer a temporary static ip address in the
|
|
|
same range as the camera default ip e.g. if the default
|
|
|
ip is 192.168.0.10, then give the computer any ip from
|
|
|
192.168.0.1 to 192.168.0.254 (EXCEPT the same ip as the
|
|
|
camera)
|
|
|
* open a browser, and in the address bar provide the
|
|
|
default camera ip and hit ENTER
|
|
|
* login into the camera using the default username/password
|
|
|
|
|
|
### perform any additional setup
|
|
|
|
|
|
note: do any of these as required by your local environment
|
|
|
|
|
|
* test the snapshot url
|
|
|
* change camera username/password (for better security)
|
|
|
* setup a connection to your wireless lan
|
|
|
* setup the actual fixed ip
|
|
|
|
|
|
IMPORTANT: changing the username and password may break
|
|
|
the snapshot url temporarily - this is because some types
|
|
|
of cameras encode the username and password as part of
|
|
|
the link. in the case of the tplink nc200, the username
|
|
|
is in plaintext ("admin") but the password is base64-encoded
|
|
|
("YWRtaW4" base64 decoded is "admin"). therefore, if you
|
|
|
change the password, then you must base64 encode the new
|
|
|
password using a script or an online service like
|
|
|
https://www.base64encode.org/ - when in doubt, research
|
|
|
the brand/model snapshot url with google
|
|
|
|
|
|
EXAMPLE: with the **tplink nc200** - if the username is
|
|
|
"admin" and the password changed to "abc123" and the ip
|
|
|
changed to 192.168.0.87:
|
|
|
|
|
|
http://admin:YWJjMTIz@192.168.0.87:8080/snapshot.jpg
|
|
|
|
|
|
once everything is setup, connect the camera to the LAN
|
|
|
wia wifi or cable, and ensure the ip is setup properly.
|
|
|
finally, test the snapshot url AGAIN on the actual network
|
|
|
|
|
|
### test the camera from the raspberry pi
|
|
|
|
|
|
to test the URL on the raspberry pi:
|
|
|
|
|
|
1. open the terminal
|
|
|
2. type `wget <full snapshot url> -O now.jpg`, hit ENTER
|
|
|
3. a picture should be downloaded as `now.jpg`
|
|
|
|
|
|
note: running step 2 over and over again, will fetch a new
|
|
|
image from the camera and overwrite any existing now.jpg
|
|
|
|
|
|
## raspberry pi
|
|
|
|
|
|
### create the automatic snapshot download script
|
|
|
|
|
|
1. open the terminal
|
|
|
2. `mkdir camera` - make a new directory for the camera project
|
|
|
3. `cd camera` - (change directory)/enter into the camera folder
|
|
|
4. `nano camera.sh` - create/edit a file called 'camera.sh'
|
|
|
5. enter the following "shell code":
|
|
|
```
|
|
|
wget <full snapshot url, as before> -O now.jpg
|
|
|
sleep 3 # in seconds, between frames
|
|
|
./camera.sh
|
|
|
```
|
|
|
6. to save the file, press CTRL-O (output), then confirm the
|
|
|
filename with enter
|
|
|
7. to exit, press CTRL-X
|
|
|
8. back to terminal, type 'chmod +x camera.sh' - this makes the
|
|
|
file "runnable"
|
|
|
9. run the file with './camera.sh'
|
|
|
|
|
|
note: do not close the terminal window, let it run endlessly
|
|
|
|
|
|
advanced: if you have more cameras, repeat these steps, and open
|
|
|
more terminal windows (one per camera) fetching the unique camera
|
|
|
snapshot url. don't forget to change the "-O" option so that each
|
|
|
camera will be written to a different snapshot file e.g.
|
|
|
"wget ... -O cam1.jpg", "wget ... -O cam2.jpg", etc
|
|
|
|
|
|
just in case the window gets closed, just do step 1, 3, 9
|
|
|
|
|
|
### camera server - part 1: preparing the environment
|
|
|
|
|
|
we must install php on the raspberry pi so we can make a simple
|
|
|
server - we only have to do this once per pi
|
|
|
|
|
|
1. open a terminal
|
|
|
2. run `sudo apt update`
|
|
|
3. run `sudo apt install php-cli`
|
|
|
4. confirm install with "Y"
|
|
|
5. wait until installation is complete
|
|
|
|
|
|
close the terminal when done OR use it for part 2...
|
|
|
|
|
|
### camera server - part 2: run a test server
|
|
|
|
|
|
1. open a terminal (or reuse the part 1 terminal)
|
|
|
2. run `hostname -I` to get the ip address of the pi,
|
|
|
take note of it
|
|
|
3. run `cd /home/pi/camera/` - we use the full directory
|
|
|
structure for convenience
|
|
|
4. run `php -S 0.0.0.0:8010`
|
|
|
5. on a separate computer/mobile, use a browser and access:
|
|
|
`http://<ip address of pi>:8010/now.jpg`
|
|
|
6. refresh the browser to refresh the picture
|
|
|
|
|
|
note: do not close the terminal window, let it run endlessly
|
|
|
|
|
|
just in case the window gets closed, just do step 1, 2, 3, 4
|
|
|
|
|
|
### camera server - part 3: make a web page
|
|
|
|
|
|
1. open a NEW terminal
|
|
|
2. run `hostname -I` to get the ip address of the pi,
|
|
|
take note of it
|
|
|
3. run `cd /home/pi/camera/`
|
|
|
4. run `nano index.html`
|
|
|
5. type the following simple web page...
|
|
|
```
|
|
|
<html>
|
|
|
<head>
|
|
|
<meta http-equiv="refresh" content="5">
|
|
|
</head>
|
|
|
<body>
|
|
|
<h1>camera server</h1>
|
|
|
<img src="now.jpg" />
|
|
|
</body>
|
|
|
</html>
|
|
|
```
|
|
|
6. to save the file in `nano`, CTRL-O, enter to confirm name
|
|
|
7. to exit `nano`, CTRL-X
|
|
|
8. on a separate computer/mobile, use a browser and access:
|
|
|
`http://<ip address of pi>`:8010` - you no longer have to
|
|
|
have `/now.jpg` at the end
|
|
|
|
|
|
notes:
|
|
|
* the meta tag in the code at step 4 will make the page refresh
|
|
|
every 5 seconds automatically.
|
|
|
* you can close this terminal when done
|
|
|
|
|
|
advanced: for multiple cameras, just add more `img` tags with
|
|
|
the `src` attribute pointing at the correct snapshot filename
|
|
|
e.g. `<img src="cam1.jpg">` `<img src="cam2.jpg">` etc
|
|
|
|
|
|
## you're done... for now
|
|
|
|
|
|
congratulations, you have created your first camera server
|
|
|
|
|
|
suggestion for improvements:
|
|
|
* add more cameras, use only one pi
|
|
|
* change the camera server from PHP to a python mini-server
|
|
|
with `python3 -m http.server`
|
|
|
* make the page look better!
|
|
|
* ...and much much more! |
|
|
\ No newline at end of file |