Smart Parcel Letterbox (Packr)

1,124

12

1

Introduction: Smart Parcel Letterbox (Packr)

About: Student MCT @ Howest Kortrijk, Belgium

Some people don't often receive letters or packages. They have to go to their mailbox every day to check whether there is new mail, both when it rains and when the sun shines. To use this time better in their life, here's this smart mailbox. This mailbox will let you know when there is new mail and can also secure your packages (whenever you want) with a motor that closes the door. Sensors also measure the physical values from inside the letter bus. Does this seem interesting to you? Then make it yourself!

Supplies

Step 1: Install LAMP on the Raspberry Pi - Linux

Download Raspberry Pi OS (previously called Raspbian) from the official Raspberry Pi site.

Insert the SD-card into your SD-card adapter or SD-card slot if you have one. Note the drive letter in the left hand column of Windows Explorer, for example G:.

Download Win32DiskImager as an installer file, and run it to install the software. Run it and select the image file. In the device box, select the SD-card (pic 1). Click 'Write' and wait for the write to complete.

When it's done, open the "boot"-folder on the SD-card and add and empty file called "ssh". That's right, without extension (pic 2)! After that, you will need to edit cmdline.txt in an IDE (don't use notepad). Once you opened the file you just add "ip=169.254.10.1" at the end of the first line and save.

If you've done that, eject the SD card-and insert it into the Raspberry Pi.

Step 2: Install LAMP on the Raspberry Pi - Apache

When Raspbian is installed and you powered on the Raspberry Pi, use Putty to connect to the command line via SSH to execute the next commands. The basic username is "pi" with password "raspberry".

Before we can start, you have to connect your WiFi with the Raspberry Pi.

  • wpa_passphrase "NAMEOFYOURNETWORK"
  • Typ the password and press Enter
  • Copy the result
  • sudo nano /etc/wpa_supplicant/wpa_supplicant.conf (pic 1)
  • Paste the result here and close with ctrl+X, Y and Enter
  • sudo reboot

You have to restart the Putty-connection. Before starting the installation of everything, run the following commands to update your Pi.

  • sudo apt update
  • sudo apt upgrade -y

We are also gonna change the hostname of the Raspberry Pi and enable SPI with raspi-config.

  • sudo raspi-config
  • Select 2) Network Options (pic 2)
  • Select N1) Hostname (pic 3)
  • Typ "Packr" (pic 4)
  • Select 4) Interfacing Options (pic 5)
  • Select P4) SPI (pic 6)
  • Select Yes (pic 7)
  • Exit raspi-config
  • Reboot

You have to log in again. To install Apache2 on your Raspberry Pi, run the next command.

  • sudo apt install apache2 -y

Apache is now installed! To test your installation, change to the /var/www/html directory and list the files.

  • cd /var/www/html
  • ls -al

You should have an index.html file in that folder.

Step 3: Install LAMP on the Raspberry Pi - PHP

To install PHP on Raspberry Pi, run the following command.

  • sudo apt install php -y

Restart Apache2.

  • sudo service apache2 restart

Step 4: Install LAMP on the Raspberry Pi - MySQL (MariaDB Server)

Install the MySQL Server (MariaDB Server) using this commands

  • sudo apt install mariadb-server php-mysql -y
  • sudo service apache2 restart

After installing this, it’s recommend to secure your installation.

  • sudo mysql_secure_installation
  • You will be asked Enter current password for root (type a secure password): press Enter
  • Type Y and press Enter to Set root password
  • Type a password at the New password: prompt, and press Enter.
  • Type Y to Remove anonymous users
  • Type Y to Disallow root login remotely
  • Type Y to Remove test database and access to it
  • Type Y to Reload privilege tables now

Now we will create the mysql-user for our database.

  • sudo mysql --user=root --password
  • create user mysql@localhost identified by 'Packr2001';
  • grant all privileges on *.* to mysql@localhost;
  • FLUSH PRIVILEGES;
  • exit;

Step 5: Install LAMP on the Raspberry Pi - PhpMyAdmin

To install phpMyAdmin on a Raspberry Pi, type the following command into the terminal.

  • sudo apt install phpmyadmin -y
  • Select Apache2 when prompted and press the Enter key
  • Configuring phpmyadmin? OK
  • Configure database for phpmyadmin with dbconfig-common? Yes
  • Type your password and press OK

We will now enable the PHP MySQLi extension and restart Apache2.

  • sudo phpenmod mysqli
  • sudo service apache2 restart

Now, you’ll have to move the phpmyadmin folder to /var/www/html.

  • sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

That’s it! Your Raspberry Pi is prepared with LAMP!

Step 6: Configurate MySQL

Download MySQL Workbench and install it on your computer.

Create a new connection with this data, but replace the SSH Hostname by 169.254.10.1. The SSH's password is "raspberry" and the mysql's password is "Packr2001" (pic 1).

If you see an error, you can just click on "Continue Anyway (pic 2). Than click on "Ok" and connect by clicking the new connection!

Step 7: Configurate the Database

Download the model of the Packr-database from GitHub.

Open this model (pic 1) and click on Database => Forward Engineer (pic 2).

Click 5 times on "Next" (pic 3), but delete the 2 "VISIBLE"'s from the code at "Review SQL Script" (pic 4), and open the database.

If you can see the database "Packr" with his 2 tables (pic 5), everything is fine!

Step 8: Connect the Code-editor to the Raspberry Pi

Download and install Visual Studio Code on your computer.

When installed, you can open it and install the "Remote Development"-extension (pic 1).

Press on F1 and typ "ssh", choose for "Remote-SSH: Add New SSH Host..." (pic 2).

Typ "ssh 169.254.10.1 -A" and press Enter to confirm (pic 3).

Just press Enter at the next step (pic 4).

Open the connection by pressing again on F1 and click on "Remote-SSH: Connect to Host..." after typing "SSH".

Select "169.254.10.1" (pic 5), typ in your password ("raspberry") and press Enter. If you get a warning, just Continue.

Now install the "Python"-extension by doing the same as installing the previous extension (pic 6).

Step 9: Import the Code

Open the terminal or use Putty to excecute the following command.

  • mkdir Packr

Open the new "Packr"-folder in Visual Studio code (pic 1), as well the "html"-folder that you can find at /var/www/ (pic 2).

To use the "html"-folder, you need to give yourself the permission to. Typ the following command in the terminal or in Putty.

  • sudo chmod 777 /var/www/html/

Download the Backend and Frontend folder and drag the files and folders from Backend into the "Packr"-folder in Visual Studio Code, and everthing from Frontend into the "html"-folder (pic 3).

Open Google Chrome (or simular) and go to your Raspberry Pi's IP. Do you see the Packr-site? Good job! It's normal that nothing is working yet, you don't have any connected devices or running code at this moment.

Step 10: Install Extra Tools

In order for the code to work correctly, we need to install a few extra things. For example, we need to install the MySQL-connector by executing the line below.

  • pip3 install mysql-connector-python

We also need to install flask-socketio, flask-cors and gevent (pic 1).

  • pip3 install flask-socketio
  • pip3 install flask-cors
  • pip3 install gevent
  • pip3 install gevent-websocket

Step 11: Let the Code Run Automatically

Create a new service by running following command in Putty.

  • sudo nano /lib/systemd/system/Packr.service

In the empty file that opens, write the code that can be found in Packr.service on GitHub (pic 1). If you're done, save the file by pressing ctrl+X, Y and Enter.

Reload the services with the following command.

  • sudo systemctl daemon-reload

Step 12: Connect the Hardware

Now that all the code is ready and the software for the project has been completed, we are going to connect the hardware. For this you will need all parts of the hardware and you can use the Fritzing-files as help. Download the breadboard view or the electronics view and start connecting! When done, power it on and restart the Raspberry Pi to start the code automatically!

Step 13: Make a Case

In order to use all the hardware for which it is intended, you need to make a case. This can be made out of wood, which is not waterproof, but also out of plastic, which is waterproof. For this you can draw and lasercut a design with your own creation, or you can use mine. Download plate 1 and plate 2 from GitHub. These designs are made for a small sized mailbox that certainly doesn't fit a decent package, so use your own measurements and edit mine in (for example) Inkscape!

After making the case Packr is ready for use! Enjoy and share your experiences!

Be the First to Share

    Recommendations

    • Maps Challenge

      Maps Challenge
    • Water Speed Challenge

      Water Speed Challenge
    • Make it Fly Challenge

      Make it Fly Challenge

    Comments