Sunday, 6 January 2013

Webcam over 3G with Raspberry PI

Description
This project was about a personal challenge that my Dad asked me to do it.
Everything started more than one year ago when I was trying to do it with Arduino but I lost a lot of time because I couldn't make everything works as fast as Raspberry does.
I decided to move on Raspberry PI and everything became easy and fast, in a few days I had made 70% of the project.

Let's talk about the project, my idea was to create a remote webcam that I could control it over the 3G network, because I wanted to install it on my mountain's house and I don't have an internet connection.
The camera have to be equipped with:
  • 2 servos: move left/right and up/down from a web interface
  • one temperature sensor: getting information and store them in a file
  • one motion sensor: something like a little CCTV that will send me message and picture when someone is close to it
Obviously everything have to be very well thought for any little problems,  and in case that something goes wrong, I had to make sure that I can access to the camera and fix it.





Raspberry : http://amzn.to/2pQXDUw
Battery: http://amzn.to/2qeENrz
Camera: http://amzn.to/2pRgkr5

Simple Schema
Schema



Web Interface
I made a little website to communicate with the camera, I can move it LEFT/RIGHT and UP/DOWN by pressing 4 buttons.
I can get the current temperature, start live streaming, change motion alerts and manager all files about camera pictures and some other files.
I'd like to improve everything with a proper client side using another Raspberry Pi, small screen and a few buttons.




3G Modem
I was looking for a good and cheap 3G modem that could work with Raspberry PI and read/send message, what I found was the HUAWEI E3131 that had a web interface and a simple API to control it.
I made a little wrapper library that I could send commands from my Python code, something like: connect to 3G network, send message, read message, etc..
I really recommender this modem because it was cheap, unlocked and easy to use!

Python library for HUAWEI E3131





Servo Pan and Tilt
I had to build my own Pan and Tilt system because the position that I have chosen is not simple one.
I came up with a solution to put everything in a PVC tube and attached one servo on the top to move the whole structure and the second to move the camera up and down.

First prototype:



Webcam
I have used fswebcam to capture snapshot from the webcam and I made a little wrapper in Python to execute this command with specific parameters.


Temperature sensor
I have chosen the DHT22 as temperature sensor, because it was easy to hook up with Raspberry and I have used this sensor on my previous projects with good results.
What I thought was to implement this sensor to store different temperatures through the whole year and have a little chart about the weather on my mountain.

Motion sensor
The motion sensor was attached to my Raspberry via one digital pin, there was a thread that was checking every 4 seconds if someone was there and send me two kind of alert: SMS and upload the picture.
I have implemented some functions to remove any kind of alert in case that the motion sensor will be trigger for stupid reasons.

AutoSSH
This was my special army to access on my Raspberry even if I was connected to a 3G network, because you know that you can't open any port as you can do on your own modem.
Basically I had to setup a ssh key to connect to my server without insert the password and create a system to active and de-active the session.
I came up with an external service with Python that will start the service if the internal service was crashing. You never know if the main script will working properly or your thread will stop to work, so this was my second security system to access and fix it.

External Power
Raspberry has only one micro usb port to give power to the whole system, so I had to solder 2 wires directly to the board.
I found the instruction on this website: http://www2.pmb.co.nz/blog/computers/raspberry-pi-direct-5v-power-wiring-modification/ to understand which pins were the 5+ and GND.
I suggest to mount  a fuse between the battery and the Raspberry, in case that something goes wrong and you don't burn your board.


Solar panel
The power source was a little problem because at 2'000 meters over the sea you don't have a normal power socket to plug your devices, so I bought a solar panel from EBay and a car battery.
I have chosen the car battery because you have 2 years of warranty and I was looking for something very high capacity and I found one with 55mAh at 12V.






Conclusion
I am testing this configuration at home before move everything at 2'000 meters, so I can be sure that at least for a month I can connect to it, get some pictures and fix any crashes that will came up.


19 comments:

Kelvin said...

This is awesome! I've been thinking about doing the same thing. Do you have schematics of how you put the whole thing together?

d9frre09ds0ds said...

Thanks Kelvin, I can try to make it :)

Unknown said...

whats the run time with the car battery at full charge, also does the camera have any optical/ digital zoom functionality?

d9frre09ds0ds said...

I don't know yet, I measured that Raspberry + devices consume 0.060 Amper.
The webcam is a normal logitech without Zoom, you can check the programm fswebcam that I am using.

Unknown said...

I want to make one of these, too! In addition to schematics, a basic tutorial would be great, and helpful to those of us who are learning how to assemble things like this.

d9frre09ds0ds said...

Tutorial will take longer than this article, I can even have a chat with the person who needs help.
There isn't so much stuff here,
Temperature sensor is connected with the digital input, sensor motion as well, the servo driver via I2C and everything else via USB.
I promise that I will create a little schema of everything

Unknown said...

I am looking to do something similar for a school project with a webcam a some servos, but I am not quite sure where to start. I haven't worked with python or php(assuming that is what the webpage is written in) before and I only just got the raspberry pi this week. Any help would be appreciated. My email is lambedr08@juniata.edu. Hope to hear from you soon. Thanks!

Randall Wright said...

Would you be able to make an image of the SD card and put it up somewhere where we can download it?

Randall Wright said...

Would you be able to make an image of the SD card and put it up somewhere where we can download it?

Anonymous said...

Hi ! Could you tell me about the prices for developing all project, if you can the cost of each device :)

d9frre09ds0ds said...

@Randal: nope I can help where you are blocked or what you looking for but I can't share all the source, there are sensible information that I can't share.

@Sofia: Price of developing I have no idea, it took me about 2 months ( maybe more ) and it's about 100-150 pounds for the hardware

Kasthuri Wijerathna said...

hi
can you send me the details please

Kasthuri Wijerathna said...

hi im amilakasthuri@gmail.com
can you pls send me the details

Unknown said...

Hi Christian,

Excellent work. I am developing a simillar thing for my mountain hut.

I am using the raspi cam and pipeing the raspivid trough the ffmpeg via crtmp protocol. I can even livestream in 1080p that way.


Did you tried any good motion detection and tracking software?

I ve tried a couple (motion,opencv,...) and realised that the pi is not capable to process the algorithms in a decent time when resolution goes above 320x240 at 25 fps.

Unknown said...

so for motion I will just use the one or two pir sensors and snap the pictures just like you did...

But for a live stream i will need some upload Does this huawei support an external antenna? Did you need it?

What is with the reliability of the huawei? I will also solar power it. At the time I am developing also IR lightning for nightly survailance. Can you suggest which solar panel did you bought ? I will update you with the IR backlihgtning if you want and if somenone else is interested... Unfortunatelly i dont have the time for a blog :)))

Andy said...

Hello,
Well done!
Any chance you could provide a hyperlink, or more details about the battery and the solar panel selected. Also, how long has it kept running, did it power down after a number of weeks? Thanks.

mdfs said...

Hi Christian,

You never said whether your camera ever worked remotely. Did you manage to get any pictures/video from the device streaming 3G?

d9frre09ds0ds said...

@Andy:
The solar panel is a 24v at 2A, it doesnt really charge very well because is not giving enough ampers but it does the job.
I bought a new battery , Exide Premium EA1000 12 V, 100 Ah and it should run for about 30 days without any chargining.

@Mdfs
I managed to get snapshot and upload them to my server via FTP, I wanted to use mjpeg server but the 3g situation made it very difficult to open up a public ip.
I had to re-write the code due to very bad starting and now I am more focus on the power saving and stability of the whole system.

Unknown said...

Very cool project. I want to build one for our ranch hopefully.