All PiWebcam files **reside in the boot partition** of the SD card, in a directory called PiWebcam. This includes a single bash file, `PiWebcam.sh` and the PHP pages for the admin panel. During the installation process, a very **basic system configuration** is performed, an **initramfs image is created** and the **PiWebcam.sh** script is added to */etc/rc.local* so to be **executed at startup** with the "*configure*" parameter. At the first reboot, the initramfs image will **shrink the root partition** (previously expanded to fill the entire SD card by the Raspbian installer) and **create a data partition** just after. Both the boot and root filesystems are mounted read-only and an overlay filesystem is created by the initram image upon the root filesystem so that any change to the system is stored in memory only and get lost at the next reboot. In this way the device will be more **robust to misconfigurations**, can be easily **restored to factory defaults** and can **survive to any power outage** since no system file is ever written to the SD card during normal operations. The **data filesystem** is instead formatted with **F2FS** (*Flash-Friendly File System*) which takes into account the characteristics of flash memory-based storage devices. During startup, PiWebcam **reads its configuration file** stored at `/boot/PiWebcam/PiWebcam.conf`, **configure the system, the camera, the network and the notifications** based on the settings found there (details can be found in the "*API*" section) and **deploy the web interface** from `/boot/PiWebcam/web` into the web root location. Just after the installation or after a factory reset a default empty configuration file is created. Since the root filesystem is volatile and any change lost at the next reboot, all the relevant settings are stored in this configuration file. The **configuration can be exported and imported** through the web interface or altered / copied out by mounting the SD card to any other system and accessing the FAT32 boot partition. When a device is reset to factory defaults, the configuration is simply deleted and the data partition formatted. For the initial configuration, there is **no need to install any mobile app or desktop software**: when no configuration is found, the device **acts as an access point** (by leveraging *hostapd* and *dnsmasq*) so the user can connect to it and customize the network settings. PiWebcam comes with a **responsive, mobile-friendly web interface** based on the Bootstrap SB Admin 2 template (, **without the need to configure any NAT or UPnP** in your router. The device name is used as hostname and both the web and ssh services are exposed. Autossh is used to keep the connection always alive. Motion detection is based on the excellent **Motion Project software** () which, among the others, is capable of generating a single notification when consecutive motions are detected so you will **not be overloaded with notifications**. **Only relevant settings are exposed** to the user while reasonable defaults are set during the device startup. Both **pictures and movies are stored into the data filesystem** and grouped in folders by year/month/day/hour so to allow an easier access. All the recordings can be reviewed through the web interface with h5ai (), a **modern file indexer** which allows files and directories to be displayed in a appealing way and providing picture and video previews without the need to download the content beforehand. When a motion is detected, PiWebcam.sh is invoked with the "*notify*" parameter through the *on_picture_save*/*on_movie_end* motion's event. If object detection is enabled for further analyzing the image, the picture is sent to Clarifai () to **recognize all the objects** within the image. This would work great to lower down false positives e.g. if you are interested to know if there is somebody stealing in your house and not just a sudden light change. **For the security camera use case, Clarifai seems to fit best** since pretty accurate to identify objects and people whereas other services could be integrated in the future (Google Vision works great with landscapes but poorly to identify a person, Amazon Rekognition is accurate but prone to false negatives when identifying persons and its authentication schema is complex to integrate in a bash script). If the AI service cannot be reached, the analysis is queue for when the connection is restored. In case of a false positive (e.g. there are no people in the motion picture), by default both the motion picture and video are deleted and no notification is sent. After that, PiWebcam check if an Internet connection is available and if so, sends out the notification. In addition to traditional e-mail notifications, sent out with *ssmtp*, with the detected motion picture attached, PiWebcam can also upload the same picture to a **Slack channel**. If you don't know Slack, check it out (); it is a great collaboration tool but can also be used to create a group dedicated to your family, grant access to your family members, chat with them and allow PiWebcam or Home Automation utilities (like e.g. https://www.egeoffrey.com) to post updates over there. If there is **no Internet connection, the notification does not get lost** but it is **queued and sent out when the connection is restored**. Periodically, through cron, PiWebcam.sh is called with the "*checkup*" parameter which will **perform routine tasks to ensure the system is running smoothly**. It will reboot the device if the overlayed root filesystem is almost full (even if this shouldn't happen), **remove oldest pictures and movies** from the data directory when the data filesystem fills up, process the notification queue, **restart core services** if no more running and try reconnecting to the network when disconnected. PiWebcam logs any activity in data filesystem so they survive a device reboot. Logs can be accessed and reviewed through the web interface as well. An **upgrade functionality** is provided through the web interface as well. A zip file is expected to be uploaded containing a PiWebcam directory and the files of the new version of the software under it (the same package used during the installation). The device can also check for new updates, download and install them automatically. During an upgrade, all the files are extracted into a temporary directory the the PiWebcam.sh script of the new version is run with the "*upgrade*" parameter so to execute the version-specific upgrade routine. A basic upgrade will just replace the files in /boot/PiWebcam with the new one and the same can be done even manually and install additional software if needed. When building an outdoor webcam, you might want to add to your project an external IR led board and a mechanical IR Cut filter and PiWebcam can handle all of those on your behalf. Night mode manually or automatically and for the latter a pin of the board (21 BCM) is monitored for changes; when turning HIGH, night mode is entered, when turning LOW is left. Entering night mode means turning on the IR leds (if connected) by setting HIGH a pin (26), toggling the IR CUT filter by sending a pulse to a pin (16 for OFF, 20 for ON) and adjusting camera settings for a better representation of the night scene. Keep in mind the GPIO pins cannot drive directly the IR Cut filter or the IR Leds; you would need a H-Bridge or a transistor in between to provide adequate current. Upon installation, the system and web password as well as the Access Point passphrase are all set to the default device name. Always keep in mind in PiWebcam usability has been preferred over security in most of the cases (no HTTPS, passwords stored in log files, etc.) so consider further protecting the device from a security standpoint.