Open Source security camera on Raspberry Pi

(github.com)

286 points | by Sean-Der 121 days ago

17 comments

  • bityard 121 days ago
    A while back, I had the need to remotely monitor a house while it was under renovation. A few friends of mine recommended a particular brand of highly-advertised security system. It was not cheap. As I was setting it up, I found out that most of the features that I wanted required broadband internet. This was not disclosed in ANY of the marketing materials. This house didn't have Internet and I wasn't going to purchase it because it would have been $60 minimum on top of the $40 or so the security system was going to cost.

    What I did instead: I bought a Raspberry Pi camera, hooked it up to a RPi Zero 2W that I already had, bought an LTE hotspot and a $5/mo prepaid SIM from T-Mobile. On the software side, I used imgcomp (https://github.com/Matthias-Wandel/imgcomp) to take a photo every second and save it to a RAM disk. If the two pictures differed (modulo noise), the Pi would upload the changed picture to a directory on my VPS, which would then trigger a notification to my phone via Gotify containing the link to the picture.

    It was all very Rube Goldbergian but it worked quite flawlessly for a couple of years.

    • stavros 120 days ago
      I'm having trouble squaring "the security system was not cheap" with "the $40 the system was going to cost". How cheap were you looking for a security system to be?
      • adrian_b 120 days ago
        I assume that this was a monthly subscription cost, not an acquisition cost, in which case it is indeed not cheap for most people.
        • bityard 120 days ago
          Yes, I inadvertently omitted "monthly." $~100 would have been the minimum monthly cost.

          The one-time purchase price of all the hardware was north of $200 with all the sensors and things.

    • ptero 121 days ago
      Very cool! This is, IMO, perfectly in the spirit of all tinkerers and hackers, building their own solutions when they need from what they have. There is nothing Rube Goldbergian about this. My 2c.
    • Topgamer7 121 days ago
      Is not all tech basically rube goldbergy XD
    • bongodongobob 120 days ago
      Were you expecting to monitor the cameras over the Internet without an Internet connection? This reads like you were expecting the cameras to have built in LTE without some kind of subscription.
      • stavros 120 days ago
        Yeah, this post is bizarre. Between "I bought an expensive $40 security system" and "it needed the internet, so I got rid of it and built my own, which also required the internet", I don't know what to think.
        • adrian_b 120 days ago
          The post said that the commercial security system required "broadband Internet", which had a much higher monthly cost than the existing lower-speed Internet connection.

          According to the post, the commercial system demanded a $100 monthly cost for the security services and broadband Internet, vs. $5 monthly cost for a lower-speed Internet access that was enough for the custom solution.

          Therefore the reduction in the monthly expenses was worthwhile.

          • stavros 120 days ago
            Was it monthly? I took it to mean a $40 one-off. Also, they don't say it requires broadband, for all we know LTE was fine for it...
    • zeagle 121 days ago
      That's pretty nifty. Now a days I'd say you could probably then run it through codeproject.ai's GPU or TPU based coral module after.
  • atum47 121 days ago
    I was working on a similar think a while back [1]

    I was living in an apartment while building my house. My idea was to have a camera making a time lapse video with the secondary effect of being able to be accessed by me from the internet so I can take a look at how the crew was doing. Unfortunately every single ideia that I have is already had and developed by anybody else. In this case, china. Ali express have some pretty good cameras that does that and more; with a better finish then a 3D print shitty case...

    1 https://youtube.com/watch?v=5E7_40PWqiQ

    • marcodiego 121 days ago
      Some (maybe most or all) of these devices require an external service to be used. That means it will work as longs as the service exists. You are in the hands of the vendor. My dream is to make devices like this and make them remotely accessible through Tor; that way it can be fully local but remotely accessible from anywhere in the world.
      • amluto 121 days ago
        A lot of cheap Chinese cameras work just fine without ever being connected to the Internet. Look for ONVIF.
      • atum47 121 days ago
        I have a 6 dollars month VPS on digital ocean that I use for everything. Host my website, send server events to my devices, socket connections...
      • stavros 120 days ago
        I bought a few Reolink cameras (around $50 each) and they have pan/tilt and don't require the internet. In fact, I didn't even connect them to it, I connect to them via my Tailscale VPN and they support this mode explicitly, and work perfectly (obviously real-time notifications don't work).
      • idunnoman1222 121 days ago
        Why did you throw Tor in there?
        • roywashere 121 days ago
          Exposing a service to tor is actually useful as a way to circumvent NAT issues
        • marcodiego 121 days ago
          Because that gives me independence with a decentralized service.
        • fimdomeio 121 days ago
          The other option would probably be a vpn.
  • jchoksi 121 days ago
    An alternative project I was looking to use with my Raspberry Pi Zero WH's was mediamtx.

    https://github.com/bluenviron/mediamtx?tab=readme-ov-file#ra...

  • gz5 121 days ago
    nice use of WebRTC, which somehow is still underutilized.

    >If you're self-hosting and you want to access the signaling server remotely via mobile data, you may need to set up DDNS and port forwarding if your ISP provides a dynamic IP.

    this also exposes your server to the internet. instead you can use one of the open source solutions which creates a private connection between your Pi and server (so there is no network access to the server - make it unreachable), and doesn't require static IPs or port forwarding.

    • Sean-Der 121 days ago
      It’s my passion in life to see WebRTC utilized to its full potential! When I learned about P2P/NAT Traversal I could never go back :)

      Why do you think it’s had trouble? Poor software, educational materials etc… always looking for new projects

      • IgorPartola 121 days ago
        We need wider IPv6 deployment now. If only someone like Zoom put their foot down and said “our shit doesn’t work without IPv6” we would see 90% deployment virtually overnight.
        • hnuser123456 121 days ago
          Of course, the catch being zoom would not become the most popular tool if it didn't support ipv4...
      • gz5 121 days ago
        i believe the p2p strengths should play better with other in-progress tech transitions - e.g. transition of all thick apps to the browser, decentralized identity, micropayments, distributed IoT and IIoT devices. what do you think?
    • tzuhuantai 121 days ago
      If you build the mqtt server on the pi, the problem is solved :)
  • nubinetwork 121 days ago
    > Raspberry Pi 5 [...] do not support v4l2 hardware encoding

    I'm not sure I get the point of that... they go through the effort for video decoding, but why doesn't it have an encoder?

    • Sean-Der 121 days ago
      My assumption is the amount of people encoding is much smaller then decoding.

      overlap exist in encode/decode. When working on a Opus codec I did have a fair amount of code distinct to one path still.

    • bmh 121 days ago
      They decided to use the silicon space for other things. The Pi5 CPU is powerful enough to decode most h264 streams in software. The Pi5 has an h265 hardware decoder.
      • hcfman 121 days ago
        Shame. Cause h265 is problematic wrt licensing etc. I would have preferred that they kick out h265 and used the silicon for h264.

        And maybe the pi5 has enough cpu to do the decoding. But how much would be left over for more interesting AI tasks ?

        • moffkalast 121 days ago
          Well it's not fast enough for most AI tasks as it is, you'd need to offload that bit to a pcie accelerator.
          • hcfman 118 days ago
            Not true actually. If by offloading you mean to a device that uses a really small model with 8-bit quantized weights you are not actually solving anything.
        • bmh 121 days ago
          I agree 100%
      • knowitnone 121 days ago
        sure it's powerful enough but I'd rather it built into the hardware for energy efficiency. But I guess we can't have our cake.
  • yu3zhou4 121 days ago
    Neat, I was looking for exactly something like this to run person detection! I'm using yolov3-tiny, not quite a new but very lightweight computer vision ML model, and just right now I'm trying to maximize performance of inference with C++, to perform real-time person detection around my house (I want to know when someone enters the parcel at night so a siren and lights can turn on automatically to deter the intruder) - https://github.com/jmaczan/yolov3-tiny-openvino
    • 6510 120 days ago
      Made me think of alarms randomly going of in the middle of the night.

      Then had this thought, imagine triggering lights and siren gradually as one approaches. That way it can trigger much earlier and give a could-be intruder enough signal to stay away. I suspect gradual adrenaline in a feedback loop is more effective too. A sudden effect only needs to be considered once.

      • yu3zhou4 120 days ago
        This is interesting approach! I'd be worried that they would manage to hide in some camera dead zones if I don't react with all-in (siren, all lights etc) quickly enough
  • aa-jv 120 days ago
    I recently built an always-on recording device, primarily for recording audio consistently and constantly - this is not for surveillance purposes, but rather for musicians and creatives who don't want to have to remember to press the Record button in the middle of a great performance. I used the Zero-W and some tricky shell scripts pushing arecord/aplay around, with a turboLua front-end, and .. it works pretty well!

    I set it up to record continuously, deleting audio content only once it gets 'stale' as per the users preferences, with options ranging from 1 minute - 5 minutes - 15 minutes - 30 minutes - 1 hour - 3 hours - 5 hours - 24 hours .. and built a front-end to allow the user to Keep the time-period they feel they might have captured something great. This heuristic is somewhat similar to the deadman-switch/security-camera mechanism used in a lot of surveillance products.

    It works so well, I kind of wonder why its not really a standard already. I guess there is still a kind of 'economy preference' where folks don't really want to fill up their storage space, but these days 128Gigs can go a long way.

    I'm pretty sure this heuristic should become a norm, one of these days. Its so inspiring to set up, forget, and then - after a few hours of jamming - come back and find the stuff you want to keep, having all the rest of the house-keeping done for you.

  • rzr999 119 days ago
    Let's not forget the old RPi Cam web interface project. It's a really old one but it's still running on my Pis. It's running in a perinneal environment so it doesn't ruin the SD card it's on, while saving to a server. The interface is also neat. https://elinux.org/RPi-Cam-Web-Interface
  • ezst 120 days ago
    I've been using https://github.com/TinkerTurtle/Sentry-Picam for a similar purpose with great success. The recorded images/videos folder is syncing up with 3 other machines for redundancy using syncthing, and I hooked-up a push notifications script based on sendxmpp to have alerts on all my devices in real-time if something happens.
  • codelion 121 days ago
    This is very cool, I had worked on something similar back at https://securade.ai using a Nvidia Jetson as the edge device. I am now excited about reCamera - https://www.seeedstudio.com/blog/recamera/
  • rubicks 121 days ago
    I'm interested in doing something similar, except using a board with open-source firmware. What kind of options do I have (if any)?
  • Dowwie 120 days ago
    If I just want to record sound, is webrtc a good solution for that?
  • hcfman 121 days ago
    very small amount of code to make a functional webrtc implementation.
    • Sean-Der 121 days ago
      I love that WebRTC re-uses existing IETF standards. Makes it easy to plug existing pieces together.

      I tried to capture that with webrtcforthecurious.com breaking it down by subsystem.

      I should do a companion piece ‘Build yourself a WebRTC’ that shows how to build WebRTC yourself in Python or other popular language.

      • hcfman 118 days ago
        Nice work! I’ll be reading this
  • hcfman 121 days ago
    Very nice to be able to see how to do this C.
  • Abismith 121 days ago
    [dead]
  • OhNoNotAgain_99 121 days ago
    [dead]