For school related purposes, I have been working on an IoT doorbell that takes pictures/records video of people who come stand near your front door. It has been a fun little project albeit not completely finished, this instructable will teach you how to set up to the point I've reached given the time limit.
First and foremost, you will need a couple of components in order to recreate the circuit:
(You are free to choose a different model, but you will need Bluetooth and Wi-Fi functionality in order for this to work)
Note: while preparing this build I was utilizing a T-Cobbler Plus and a speaker. To make your build more compact, I advise connecting the cables to the pins directly and using a buzzer instead of speaker in order to save space. Note 2: ideally you want to use a PCB while finalizing the doorbell. If you want, you can keep the breadboard connections, but you will have to solder the button and LED light as it's hard to connect them properly by simpler means.
For this build, we are a voltage of 5V. The camera will be connected directly to the Pi with the camera port. In order to connect the Pi camera properly, I recommend watching the video above if you want to safely connect the camera to your Raspberry Pi without causing damage to the cable/tin connectors. A short summary of the video:
In order to start installing everything, you first need to have the proper software installed. An IDE (Integrated Development Environment) will make your life a lot easier while editing code.
The Python installer can be downloaded directly from their website.
You are free to utilize any IDE you want. This instructable will cover how to install necessary packages and how to make database connections in Pycharm.
You will need to install an operating system on the Raspberry Pi (and be able to connect to it with SSH). In this instructable, we will be working with Raspbian Jessie (note: to establish the SSH connection with Raspbian Jessie, either download a version released before November 2016 or read this article in order to enable SSH on startup). To make the SSH connection, we will use PuTTY.
WinSCP is not a necessity, but will come in handy if you want to view the camera footage directly from the Pi rather than the website.
sudo pip install python3-dev
sudo pip install pybluez
sudo pip install bluetooth
sudo apt-get install libbluetooth-dev
sudo pip install pygame
sudo apt-get install python-picamera
The title says it all, we need to make the Bluetooth speaker connect with the Raspberry Pi on startup. In order to do this, we must first acquire the MAC-address of your speaker. Be sure to note it down somewhere for future reference as you will need this to edit the appropriate sound card and device for audio in the programming code. I'm assuming you have already installed the bluetooth tools and libraries listed in the previous step.
sudo apt-get install pulseaudio -y
pulseaudio --start
bluetoothctl -a
mkdir -p ~/scripts
nano ~/scripts/autopair
(enter the code below into the nano file and save it with CTRL + X)
#!/bin/bash
bluetoothctl << EOF
connect [enter your MAC add]
EOF
chmod +x ~/scripts/autopair
nano ~/.bashrc
(go to the bottom and add this line of code)
pulseaudio --start
To download the code, go to Github and download as .zip. Paste the necessary code in your project (docam.py is redundant and only for manual testing purposes).
Open PIRCamera.py and make sure all the Python libraries are installed. To install these, navigate to Settings → Deployment and press the green + button. Type in the packages listed in the various imports if you are missing a few.
Navigate to __bluetoothScan() and edit the last line to match your MAC address.
call('pacmd set-default-sink bluez_sink.', shell=True)
Check if the mentioned paths in takePicture(), recordVideo() and knop_callback are correct and edit accordingly depending on your deployment path.
Open docam_examen.py and adapt the UPLOAD_FOLDER path accordingly.
Edit the pin numbers of the PIRCamera object if needed according to the following format: pir, led, button, speaker
GRANT ALL PRIVILEGES ON *.* TO 'finley' @ '%' WITH GRANT OPTION;
We can now make our database.
CREATE DATABASE docam;
To quit the MySQL connection, type:
quit
sudo apt-get install python3-mysql.connector
Open a data source in Pycharm. Fill in your made credentials (use the pictures as a reference).
Add the tables in Pycharm's editor (use the ERD as a reference on how to make them).
Open DbClass.py and edit the credentials located in the init if necessary.
Your database should be connected to your project now.
The way you make the case is up to you, just make sure the case is big enough. The material can be anything as long as it's non-conductive. I personally opted for multiplex due to its simplicity since I was running out of time.
Things to consider while making the case:
Now you have set up everything, it's time to test how it works.
Type the IP address and the corresponding port number in your browser of choice (Chrome recommended for optimal results).
Once you have connected to the website, fill in the login form. You can find/edit the credentials in 'def do_admin_login():'
if request.form['password'] == '<b>password</b>' and request.form['username'] == '<b>admin</b>':<br>
When you have successfully logged in, you will be referred to the homepage.
If everything is working fine, make a script so it executes the Python script on boot.