Categories
Development

Blowing new life into an old Chinese cloud camera without cloud

I had this cheap old ip camera laying in the house gathering dust because the company selling the camera does not exist anymore. Now i was only able to access it from within the house using the P2PCamViewer app.

Not very useful as a security, or any camera if you ask me. There was a reason for this camera being so cheap, the only way to access it was via the app. No RSTP, no web interface. only their proprietary P2P protocol.

A couple of months after i installed Home Assistant i thought “I can use this to proxy this now, local only camera to the outside world”. Sadly, only an Android and Windows app was available to view this device. And the Windows app didn’t even work…

Time to do some research

So i set out to search how this camera worked. After a bit of googling i stumbled on a blog post accompanied by this git repository. Jackpot! This gave me a huge headstart, since he already captured all of the packets needed to communicate, figured out how the image is sent. And apart from one small issue it worked!

However this only records a few seconds of video when it detects motion. I want to view a live camera feed from the outside so saving a couple of seconds of video isn’t going to help with that. So i started editing the code so it saves a picture every time it receives enough data. That’s a good start, but i wanted it more flexible.

Turning it into a class

I knew for it to be of wide use i had to turn this into a class. So i started reading the code, separating it into different parts. Translated it from Python 2 to Python 3. And turned it into a class so i can use it in external scripts (As well as upload it to PyPi)
I also uploaded it to Github

This is a great step forward since now, instead of having to edit the whole file to fit your needs. You can just include the class, configure the camera, and request an image whenever you need.

Which is the base of what a Home Assistant Camera component needs, so i started creating the integration which was really straight forward now. since i only had to configure the IP of the camera and the IP of the host. And Home Assistant can fetch a shot of the camera whenever it needs.