[PYTHON] Create a visitor notification system using Raspberry Pi
        
      
      
   
      
Overview
- As an intercom for detached houses, there is a product that sends a visitor notification by e-mail.
 
- In rental housing, only the equipment provided can be used and cannot be modified.
 
- Create a system that takes camera images and sends emails in response to intercom calls
 


What to prepare
- Raspberry Pi3 Model B (4 is probably okay)
 
- Case for Raspberry Pi
 
- Heat sink for Raspberry Pi
 
- Raspberry Pi3 Model B B + compatible power supply set (5V 3.0A)
 
- GY-30 Digital Light Intensity Sensor Module I2C
 
- Camera Module for Sainsmart Raspberry Pi Camera Module for Raspberry Pi
 
- Jumper wire female-female
 
- Heat shrink tubing
 
- Book stand (100-yen shop)
 
Environment
- Set up the OS of Raspberry Pi and enable I2C
https://www.raspberrypi.org/downloads/
https://www.indoorcorgielec.com/resources/raspberry-pi/raspberry-pi-i2c/ 
- Be able to send Gmail with mutt
http://www.tapun.net/raspi/raspberry-pi-ssmtp-mutt
 
assembly
Connect the Raspberry Pi, optical sensor (GY-30), and camera as follows

- The pin layout of Raspberry Pi is omitted.
 
- Install an optical sensor on the screen of the intercom (use the fact that the screen becomes brighter when calling)

 
programming
- Loop with a while statement in Python, and when the value from the optical sensor reaches 200 Lux or more,
Take a picture with the camera and save it in jpg format (overwrite each time you take a picture)
 
- Temporarily write (overwrite) the date of shooting to a text file 
body.txt 
- Use mutt and Gmail to send an email with the date of shooting in the body 
guest.sh 
- Set a sleep time of 5 minutes (considering calling with the intercom in the room after calling with auto lock)
 
- Make 
guest.py start automatically when Raspberry Pi starts 
Main program
/home/pi/guest/guest.py
import smbus
import picamera
import time
import subprocess
bus = smbus.SMBus(1)
addr = 0x23
camera = picamera.PiCamera()
while True:
    luxRead = bus.read_i2c_block_data(addr,0x11)
    print("Lux: "+str(luxRead[1]* 10))
    if int(luxRead[1]* 10) > 200:
        camera.capture('/home/pi/guest/image.jpg')
        res = subprocess.call("sh /home/pi/guest/guest.sh",shell=True)
        time.sleep(300)
    time.sleep(1)
Shell script for sending emails
/home/pi/guest/guest.sh
sudo date > /home/pi/guest/body.txt
sudo mutt -s "guest arrived!" [email protected] -a /home/pi/guest/image
.jpg < /home/pi/guest/body.txt
Auto start settings
/etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
sudo python3 /home/pi/guest/guest.py &
exit 0
important point
- The light intensity (Lux) to be detected differs depending on the intercom, so adjust it.
For types that brighten the screen with a touch panel, check with that function
 
- Sleep time is adjusted by the distance of the room from the entrance of the auto lock.

 
Try using
- Because I use online shopping a lot, it is convenient to be notified when there is a visitor when I am absent
 
- I have been using it for over a year and a half, but it is operating stably.