[{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003ch2\u003eIntroduction\u003c/h2\u003e\n\u003cp\u003eEven though we live in a quiet neighborhood I wanted to have a few cameras around the property. I'm sure it will provide hours of watching mongoose, the occasional wild pig, feral cats, chickens, and turkeys in our neighborhood.\u003c/p\u003e\n\u003cp\u003eThe first camera project is for our driveway. It will be paired with \u003ca href=\"https://adafruit-playground.com/u/ntynen/pages/home-hub-motion-detector\"\u003ea motion detector\u003c/a\u003e.\u003c/p\u003e\n\u003ch2\u003eDesign\u003c/h2\u003e\n\u003cp\u003eThe camera is coded in Python.\u003c/p\u003e\n\u003cp\u003eYou will need an MQTT broker for all of this to work together. You can use \u003ca href=\"https://io.adafruit.com/\"\u003eAdafruit IO\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003eIn my implementation I set up a Mosquitto MQTT broker on a RaspberryPi 4 Model B running Debian Bookworm and Mosquitto v2.022.\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eFor image and clip storage this project supports both writing to a local file server as well as to Dropbox. For local file storage I have a another Raspberry Pi running Openmediavault.\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003ch2\u003eParts List\u003c/h2\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"parts","content":"\n  \u003cdiv class=\"parts-details\"\u003e\n    \u003cdiv\u003e\n      \u003cspan class=\"parts-quantity\"\u003e1\u003c/span\u003e\u003cspan\u003e x \u003c/span\u003e\n        \u003ca href=\"https://www.raspberrypi.com/products/raspberry-pi-4-model-b/\" class=\"parts-name\" target=\"_blank\"\u003eRaspberryPi 4\u003c/a\u003e\n      \u003cdiv class=\"parts-description\"\u003eRaspberryPi 4 Model B\u003c/div\u003e\n    \u003c/div\u003e\n  \u003c/div\u003e\n  \u003cdiv class=\"parts-action\"\u003e\n  \u003cdiv\u003e\n      \u003ca href=\"https://www.raspberrypi.com/products/raspberry-pi-4-model-b/\" class=\"parts-url btn-primary\" target=\"_blank\"\u003eBuy Now\u003c/a\u003e\n\n  \u003c/div\u003e\n\u003c/div\u003e\n\n  \u003cdiv class=\"clearfix\"\u003e\u003c/div\u003e\n","metadata":{"name":"RaspberryPi 4","url":"https://www.raspberrypi.com/products/raspberry-pi-4-model-b/","description":"RaspberryPi 4 Model B","quantity":"1"}},{"element_type":"parts","content":"\n  \u003cdiv class=\"parts-details\"\u003e\n    \u003cdiv\u003e\n      \u003cspan class=\"parts-quantity\"\u003e1\u003c/span\u003e\u003cspan\u003e x \u003c/span\u003e\n        \u003ca href=\"https://www.arducam.com/arducam-m12-night-vision-ir-cut-raspberry-pi-camera.html\" class=\"parts-name\" target=\"_blank\"\u003eCamera With Night Vision\u003c/a\u003e\n      \u003cdiv class=\"parts-description\"\u003eArducam 5MP OV5647 Camera Module\u003c/div\u003e\n    \u003c/div\u003e\n  \u003c/div\u003e\n  \u003cdiv class=\"parts-action\"\u003e\n  \u003cdiv\u003e\n      \u003ca href=\"https://www.arducam.com/arducam-m12-night-vision-ir-cut-raspberry-pi-camera.html\" class=\"parts-url btn-primary\" target=\"_blank\"\u003eBuy Now\u003c/a\u003e\n\n  \u003c/div\u003e\n\u003c/div\u003e\n\n  \u003cdiv class=\"clearfix\"\u003e\u003c/div\u003e\n","metadata":{"name":"Camera With Night Vision","url":"https://www.arducam.com/arducam-m12-night-vision-ir-cut-raspberry-pi-camera.html","description":"Arducam 5MP OV5647 Camera Module","quantity":"1"}},{"element_type":"markdown","content":"\u003ch2\u003eCode\u003c/h2\u003e\n\n\u003ch4\u003eDriveway Camera\u003c/h4\u003e\n\n\u003cp\u003e\u003ca href=\"https://github.com/niccit/disturbance-in-force/blob/main/driveway_camera.py\"\u003eThe code\u003c/a\u003e for this project can be found on Github.\u003c/p\u003e\n\n\u003cp\u003eIt is one part of the larger \u003ca href=\"https://github.com/niccit/disturbance-in-force\"\u003ehome monitoring project\u003c/a\u003e.\u003c/p\u003e\n\n\u003ch4\u003eLibraries Required\u003c/h4\u003e\n\n\u003cul\u003e\n\u003cli\u003ebase64\u003c/li\u003e\n\u003cli\u003etime\u003c/li\u003e\n\u003cli\u003eos\u003c/li\u003e\n\u003cli\u003eparamiko (ssh)\u003c/li\u003e\n\u003cli\u003escp\u003c/li\u003e\n\u003cli\u003euuid\u003c/li\u003e\n\u003cli\u003edatetime\u003c/li\u003e\n\u003cli\u003edotenv\u003c/li\u003e\n\u003cli\u003epaho.mqtt.client\u003c/li\u003e\n\u003cli\u003elogging\u003c/li\u003e\n\u003cli\u003elibcamera\u003c/li\u003e\n\u003cli\u003epicamera2\u003c/li\u003e\n\u003cli\u003edropbox\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ch4\u003eFeature Highlights\u003c/h4\u003e\n\n\u003cul\u003e\n\u003cli\u003eLoads all configurations from .env file.\u003c/li\u003e\n\u003cli\u003eStreams a live feed of the camera locally using PyavOutput\u003c/li\u003e\n\u003cli\u003eHas a still camera configuration to snap an image as soon as motion is detected\u003c/li\u003e\n\u003cli\u003eUtilizes two encoders; H264Encoder for the live feed and MJPEGEncoder for the 30 second capture when motion is detected\u003c/li\u003e\n\u003cli\u003eUtilizes ssh/scp to move files to the local file server\u003c/li\u003e\n\u003cli\u003eUtilizes encrypted transport for all MQTT traffic\u003c/li\u003e\n\u003cli\u003eConfigurable via MQTT, camera will send image and capture video to local file storage, Dropbox, or both\u003c/li\u003e\n\u003cli\u003eUtilizes separate publish and subscribe MQTT clients\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ch5\u003eThe TL;DR nuts and bolts\u003c/h5\u003e\n\n\u003cp\u003eMediaMTX is launched with the camera start up to display the rtsp live stream in a web page. The URL will look like \u003ccode class=\"inline\"\u003ehttp://\u0026lt;IP of your camera\u0026gt;:8889/cam\u003c/code\u003e\u003c/p\u003e\n\n\u003ch4\u003eThe camera will subscribe to:\u003c/h4\u003e\n\n\u003cul\u003e\n\u003cli\u003emonitoring.motion-detect\u003c/li\u003e\n\u003cli\u003emonitoring.storage\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ch4\u003eThe camera will publish to:\u003c/h4\u003e\n\n\u003cul\u003e\n\u003cli\u003emonitoring.recording\u003c/li\u003e\n\u003cli\u003emonitoring.picamera\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ch4\u003eWhen the camera receives a message on monitoring.motion-detect, it will do the following:\u003c/h4\u003e\n\n\u003cul\u003e\n\u003cli\u003eTake a still image and publish it to monitoring.picamea\u003c/li\u003e\n\u003cli\u003ePublish that recording has started to monitoring.recording\u003c/li\u003e\n\u003cli\u003eCapture a 30 second mp4 clip\u003c/li\u003e\n\u003cli\u003eCopy the image and 30 second clip to local storage, remote storage, or both\u003c/li\u003e\n\u003cli\u003ePublish that recording has completed to monitoring.recording\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ch5\u003eCase\u003c/h5\u003e\n\n\u003cp\u003eI used OpenSCAD and the YAPP Box (Yet Another Parametric Project Box Generator) library from mrWheel. This library is well documented and has a lot of features.\u003c/p\u003e\n\n\u003ch5\u003eNode-Red Dashboard\u003c/h5\u003e\n\n\u003cp\u003eNode-Red Dashboard will \u003ca href=\"https://cdn-learn.adafruit.com/user_assets/assets/000/002/227/large1024/camera_live_stilla.png?1768858957\"\u003edisplay\u003c/a\u003e the following:\u003c/p\u003e\n\n\u003cul\u003e\n\u003cli\u003eLive camera feed\u003c/li\u003e\n\u003cli\u003eLast still shot taken when motion was detected\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003cp\u003eThis is what the  \u003ca href=\"https://cdn-learn.adafruit.com/user_assets/assets/000/002/226/large1024/cameras_in_node_red.png?1768794526\"\u003ecamera flow\u003c/a\u003e in Node-Red looks like.\u003c/p\u003e\n\n\u003ch4\u003eLive camera feed in Node-Red\u003c/h4\u003e\n\n\u003cp\u003eThe easiest way to get the live feed in Node-Red is to use the template node and embed the URL for the stream in an iframe.\u003c/p\u003e\n\u003ccode class=\"\"\u003e\u003cpre\u003e\u0026lt;iframe src=\"http://192.168.68.70:8889/cam\" width=\"856\" height=\"480\" frameborder=\"0\"\u0026gt;\u0026lt;/iframe\u0026gt;\n\u003c/pre\u003e\u003c/code\u003e\n\u003ch4\u003eStill shot in Node-Red\u003c/h4\u003e\n\n\u003cp\u003eWhen motion is detected the code will base64 encode the image and send it to the MQTT feed \u003ccode class=\"inline\"\u003emonitoring.picamera\u003c/code\u003e.\u003c/p\u003e\n\n\u003cp\u003eAn MQTT in node in the Camera flow susbscribes to the feed and when a message is received will update the dashboard page with the image.\u003c/p\u003e\n\n\u003cp\u003eThe easiest way to display the image in Node-Red is to use the template node and embed the image.\u003c/p\u003e\n\u003ccode class=\"\"\u003e\u003cpre\u003e  \u0026lt;img style = \"width:854px; height:480px;\" :src=\"`data:image/jpg;base64,${msg.payload}`\" /\u0026gt;\n\u003c/pre\u003e\u003c/code\u003e\n\u003cp\u003eI know both of these seem deceptively simple, but they work!\u003c/p\u003e\n","metadata":{"markdown":"## Code\n\n#### Driveway Camera\n\n[The code](https://github.com/niccit/disturbance-in-force/blob/main/driveway_camera.py) for this project can be found on Github.\n\nIt is one part of the larger [home monitoring project](https://github.com/niccit/disturbance-in-force).\n\n#### Libraries Required\n* base64\n* time\n* os\n* paramiko (ssh)\n* scp\n* uuid\n* datetime\n* dotenv\n* paho.mqtt.client\n* logging\n* libcamera\n* picamera2\n* dropbox\n\n#### Feature Highlights\n* Loads all configurations from .env file.\n* Streams a live feed of the camera locally using PyavOutput\n* Has a still camera configuration to snap an image as soon as motion is detected\n* Utilizes two encoders; H264Encoder for the live feed and MJPEGEncoder for the 30 second capture when motion is detected\n* Utilizes ssh/scp to move files to the local file server\n* Utilizes encrypted transport for all MQTT traffic\n* Configurable via MQTT, camera will send image and capture video to local file storage, Dropbox, or both\n* Utilizes separate publish and subscribe MQTT clients\n\n##### The TL;DR nuts and bolts\n\nMediaMTX is launched with the camera start up to display the rtsp live stream in a web page. The URL will look like `http://\u0026lt;IP of your camera\u0026gt;:8889/cam`\n\n#### The camera will subscribe to:\n* monitoring.motion-detect\n* monitoring.storage\n\n#### The camera will publish to:\n* monitoring.recording\n* monitoring.picamera\n\n#### When the camera receives a message on monitoring.motion-detect, it will do the following:\n* Take a still image and publish it to monitoring.picamea\n* Publish that recording has started to monitoring.recording\n* Capture a 30 second mp4 clip\n* Copy the image and 30 second clip to local storage, remote storage, or both\n* Publish that recording has completed to monitoring.recording\n\n##### Case\nI used OpenSCAD and the YAPP Box (Yet Another Parametric Project Box Generator) library from mrWheel. This library is well documented and has a lot of features.\n\n##### Node-Red Dashboard\nNode-Red Dashboard will [display](https://cdn-learn.adafruit.com/user_assets/assets/000/002/227/large1024/camera_live_stilla.png?1768858957) the following:\n\n* Live camera feed\n* Last still shot taken when motion was detected\n\nThis is what the  [camera flow](https://cdn-learn.adafruit.com/user_assets/assets/000/002/226/large1024/cameras_in_node_red.png?1768794526) in Node-Red looks like.\n\n#### Live camera feed in Node-Red\n\nThe easiest way to get the live feed in Node-Red is to use the template node and embed the URL for the stream in an iframe.\n```\n\u0026lt;iframe src=\"http://192.168.68.70:8889/cam\" width=\"856\" height=\"480\" frameborder=\"0\"\u0026gt;\u0026lt;/iframe\u0026gt;\n```\n\n#### Still shot in Node-Red \n When motion is detected the code will base64 encode the image and send it to the MQTT feed `monitoring.picamera`.\n\nAn MQTT in node in the Camera flow susbscribes to the feed and when a message is received will update the dashboard page with the image.\n\nThe easiest way to display the image in Node-Red is to use the template node and embed the image.\n ```\n  \u0026lt;img style = \"width:854px; height:480px;\" :src=\"`data:image/jpg;base64,${msg.payload}`\" /\u0026gt;\n  ```  \n  I know both of these seem deceptively simple, but they work!"}},{"element_type":"markdown","content":"\u003ch3\u003eProject Construction\u003c/h3\u003e\n\n\u003ch5\u003eThe Camera\u003c/h5\u003e\n\n\u003cp\u003eInsert the Raspberry Pi 4 into the case and \u003ca href=\"https://cdn-learn.adafruit.com/user_assets/assets/000/002/228/large1024/picam-base.png?1769046577\"\u003esecure\u003c/a\u003e to the 4 self-threading standoffs. Use M2 screws.\u003c/p\u003e\n\n\u003cp\u003eAttach the cable for the \u003ca href=\"https://cdn-learn.adafruit.com/user_assets/assets/000/002/229/large1024/picam-base-camera.png?1769046664\"\u003ecamera\u003c/a\u003e to the Raspberry Pi 4.\u003c/p\u003e\n\n\u003cp\u003eAttach the camera to the lid by \u003ca href=\"https://cdn-learn.adafruit.com/user_assets/assets/000/002/230/large1024/picam-lid-camera.png?1769046713\"\u003esecuring\u003c/a\u003e with the 4 self-threading standoffs. Use M2 screws.\u003c/p\u003e\n\n\u003cp\u003e\u003ca href=\"https://cdn-learn.adafruit.com/user_assets/assets/000/002/231/large1024/picam-complete.png?1769046863\"\u003eThe Camera\u003c/a\u003e fully assembled.\u003c/p\u003e\n\n\u003ch5\u003eThe Case\u003c/h5\u003e\n\n\u003cp\u003eThe case is printed using Polymaker PolyLite ASA filament. This is a weather resistent filament which makes it perfect for the camera on the house under an eave.\u003c/p\u003e\n\n\u003ch4\u003e3D Printing Settings\u003c/h4\u003e\n\n\u003cul\u003e\n\u003cli\u003eExtruder temperature: 250\u003c/li\u003e\n\u003cli\u003ePlatform temperature: 85\u003c/li\u003e\n\u003cli\u003eBase print speed: 40mm/s\u003c/li\u003e\n\u003cli\u003eInfill: Hexagon 15%\u003c/li\u003e\n\u003cli\u003eSupports: No\u003c/li\u003e\n\u003cli\u003eRaft: No\u003c/li\u003e\n\u003cli\u003eBrim: Yes, fully enabled, no brim generated in holes\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003cp\u003eLike the motion detector and all other outdoor projects, I will use waterproof silicone and electrical tape to seal cases and protect the circuit boards.\u003c/p\u003e\n","metadata":{"markdown":"### Project Construction\n\n##### The Camera\n\nInsert the Raspberry Pi 4 into the case and [secure](https://cdn-learn.adafruit.com/user_assets/assets/000/002/228/large1024/picam-base.png?1769046577) to the 4 self-threading standoffs. Use M2 screws.\n\nAttach the cable for the [camera](https://cdn-learn.adafruit.com/user_assets/assets/000/002/229/large1024/picam-base-camera.png?1769046664) to the Raspberry Pi 4.\n\nAttach the camera to the lid by [securing](https://cdn-learn.adafruit.com/user_assets/assets/000/002/230/large1024/picam-lid-camera.png?1769046713) with the 4 self-threading standoffs. Use M2 screws.\n\n[The Camera](https://cdn-learn.adafruit.com/user_assets/assets/000/002/231/large1024/picam-complete.png?1769046863) fully assembled.\n\n##### The Case\n\nThe case is printed using Polymaker PolyLite ASA filament. This is a weather resistent filament which makes it perfect for the camera on the house under an eave.\n\n#### 3D Printing Settings\n* Extruder temperature: 250\n* Platform temperature: 85\n* Base print speed: 40mm/s\n* Infill: Hexagon 15%\n* Supports: No\n* Raft: No\n* Brim: Yes, fully enabled, no brim generated in holes\n\nLike the motion detector and all other outdoor projects, I will use waterproof silicone and electrical tape to seal cases and protect the circuit boards."}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/002/226/original/cameras_in_node_red.png?1768794526","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/002/227/original/camera_live_stilla.png?1768858957","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/002/228/original/picam-base.png?1769046577","metadata":{}},{"element_type":"markdown","content":"\u003cp\u003eThis project is part of the larger \u003ca href=\"https://adafruit-playground.com/u/ntynen/pages/home-hub-project-with-node-red-dashboard\"\u003eHome Hub Project with Node-Red\u003c/a\u003e\u003c/p\u003e\n","metadata":{"markdown":"This project is part of the larger [Home Hub Project with Node-Red](https://adafruit-playground.com/u/ntynen/pages/home-hub-project-with-node-red-dashboard)"}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/002/229/original/picam-base-camera.png?1769046664","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/002/230/original/picam-lid-camera.png?1769046713","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/002/231/original/picam-complete.png?1769046863","metadata":{}}]