[PYTHON] Create a visitor notification system using Raspberry Pi

Overview

68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f3730313434352f33396532336332612d363136662d633330372d313464632d3764663438653266633531312e6a706567.jpg

68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f3730313434352f39663263613062342d333739302d666431362d396238622d6431386363616437343038372e6a706567.jpg

What to prepare

Environment

assembly

Connect the Raspberry Pi, optical sensor (GY-30), and camera as follows スクリーンショット 2020-09-15 9.39.49.png

programming

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

Try using

Recommended Posts

Create a visitor notification system using Raspberry Pi
Create a color sensor using a Raspberry Pi and a camera
Using a webcam with Raspberry Pi
Create a car meter with raspberry pi
Try using a QR code on a Raspberry Pi
Raspberry Pi system monitoring
Indoor monitoring using Raspberry Pi
Create a web surveillance camera with Raspberry Pi and OpenCV
Detect "temperature (using A / D converter)" using python on Raspberry Pi 3!
Create a partition and then install the Raspberry Pi OS
I tried to automate [a certain task] using Raspberry Pi
USB over ethernet using Raspberry pi
Create a python GUI using tkinter
Create a nested dictionary using defaultdict
Try using ArUco on Raspberry Pi
Create a CRUD API using FastAPI
Create a C wrapper using Boost.Python
Make a simple CO2 incubator using Raspberry PI and CO2 sensor (MH-Z14A)
Create your own IoT platform using raspberry pi and ESP32 (Part 1)
[Note] Using 16x2-digit character LCD (1602A) from Python with Raspberry Pi
"Honwaka Notification Lamp" on Raspberry Pi Part 2
[Raspberry Pi] Add a thermometer and a hygrometer
Detect "brightness" using python on Raspberry Pi 3!
Detect analog signals with A / D converter using python on Raspberry Pi 3!
"Honwaka Notification Lamp" on Raspberry Pi Part 1
Build a Tensorflow environment with Raspberry Pi [2020]
Make Raspberry Pi speak Japanese using OpenJtalk
Create a graph using the Sympy module
[Python] Create a Batch environment using AWS-CDK
Create a star system with Blender 2.80 script
Create a socket with an Ethernet interface (eth0, eth1) (Linux, C, Raspberry Pi)
Run servomotor on Raspberry Pi 3 using python
Make a wash-drying timer with a Raspberry Pi
Operate an oscilloscope with a Raspberry Pi
Detect temperature using python on Raspberry Pi 3!
Create a dataframe from excel using pandas
Creating a temperature control system with Raspberry Pi and ESP32 (3) Recipient Python file
I tried to create a button for Slack with Raspberry Pi + Tact Switch
Using the 1-Wire Digital Temperature Sensor DS18B20 from Python on a Raspberry Pi
Create a beauty pageant support app using PyLearn2
Detect slide switches using python on Raspberry Pi 3!
Build a Django environment on Raspberry Pi (MySQL)
Let's create a REST API using SpringBoot + MongoDB
Create a phylogenetic tree from Biopyton using ClustalW2
Detect magnet switches using python on Raspberry Pi 3!
Automatic launch of Raspberry Pi programs using Systemd
Send data from Raspberry Pi using AWS IOT
Create a binary data parser using Kaitai Struct
Create a web map using Python and GDAL
Sound the buzzer using python on Raspberry Pi 3!
Create a Mac app using py2app and Python3! !!
Connect your Raspberry Pi to your smartphone using Blynk
Create a MIDI file in Python using pretty_midi
Build a Python development environment on Raspberry Pi
Create a GUI on the terminal using curses
Raspberry Pi backup
Create your own IoT platform using raspberry pi and ESP32 (Part 2) ~ ESP32 setting L Chika
Create a data collection bot in Python using Selenium
Build an OpenCV4 environment on Raspberry Pi using Poetry
Using the digital illuminance sensor TSL2561 with Raspberry Pi
Using Akizuki Denshi's 4WD car FT-MC-004 with Raspberry Pi