WUK Pickup Locker

by Jens Dumortier in Circuits > Raspberry Pi

310 Views, 3 Favorites, 0 Comments

WUK Pickup Locker

20210612_144930 (1).jpg
20210612_152115.jpg
20210612_152318.jpg
20210612_152402.jpg

For my school project at MCT Howest (Kortrijk), I made a pickup locker for beer crates.

The idea is that you pick up paid orders without anyone being present. You will have to enter an order number and a code through a touchscreen display, to open a locker that has been assigned to that order number.

You will be able to control the pickup locker through a local running website on the Raspberry Pi. Here you will be able to manage the orders and set the code of a locker. But also detect if someone passes in front of the locker and keep track of the temperature in the locker.

All the code and files for making my project you can find on my Github.

Supplies

Main controller:

  • Raspberry Pi 4
  • Raspberry Pi case
  • SD card 16 GB

Electronics:

  • USB-C charger
  • Set of resistors
  • 2x Mosfet (IRF3205)
  • 2x Diode (1N4007)
  • AC power connector (C14)
  • AC power cord (C14)
  • GPIO 40 pin connector
  • Jumper wires
  • 5x 2 pin screw terminal
  • 1x 3 pin screw terminal
  • Breadboard
  • Prototyping PCB or a breadboard if you don't want to solder
  • 0.2 mm wire
  • 1.4 mm wire

Sensors and modules:

  • 1x Nextion Enhanced 3.5" TFT display (NX4832K035)
  • 2x Electromagnetic lock 12 V
  • 1x Waterproof 1-wire temperature sensor
  • 1x Detector (AM312)
  • 1x LCD (LCD1602) (optional)

Wooden locker materials:

  • 40 x 60 mm impregnated den bar
  • 15 x 110 mm impregnated den planchettes
  • 6x stainless steel hinge
  • 6x plastic furniture leg
  • Screws and nails

Tools:

  • Soldering iron
  • Radial arm saw
  • Jigsaw
  • Hamer
  • Drill/Screw machine
  • Ruler

Hardware

20210602_151055.jpg
Breadboard.png
Schema.png
20210602_152206.jpg

If you got all the components, you can connect them according to the fritzing scheme. Make sure before you power up the Raspberry Pi, that there are no shorts.

Solder the MOSFET circuit on a prototyping PCB (optional)

If you want you can solder the MOSFET circuit on a prototyping PCB. It isn't needed but it will later be easier to connect the locks. To make this circuit you can use the same schematic. On this PCB is a 12 V input, 2 MOSFET circuits and a connector with a resistor for the temperature sensor.

Set Up the Raspberry Pi

vishnu-mohanan-rZKdS0wI8Ks-unsplash.jpg

The first thing we're going to do, is set up the Raspberry Pi. This will run the frontend, backend, and database. To use the Raspberry Pi, you will need to follow the following steps:

1. Download the custom image

The image contains the following items:

  • Apache
  • MariaDB
  • The code for the project
  • Custom settings

The custom image can be downloaded on my OneDrive.

2. Write the image to the SD card

We will use win32diskimager to write the image to the SD card

If you installed the program, you can select the custom image and the drive of your SD card. After that, you can click on write. Don't click on format after the SD card is written!

3. Connect through ssh

Once the SQ card is written, we can insert it into the Raspberry Pi and power it on. Also, connect a network cable between your pc and Raspberry Pi.

Now we can use the putty client to connect with the Raspberry Pi over SSH with these settings:

Ip: 192.168.168.168
Port: 22
Connection type: SSH

4. Login

To log in to the Raspberry Pi, use the username student and password W8w00rd.

5. Connect to wifi

After you logged in to the pi, you can connect to your local wifi network. For this step, you will need the login details of your wifi network and follow these lines of code:

> sudo -i
> wpa_passphrase "your_SSID" "your_wifi-password" >> /etc/wpa_supplicant/wpa_supplicant.conf
> wpa_cli -i wlan0
> reconfigure wlan0

6. Update the Raspberry Pi

Now the Raspberry Pi is connected with the internet, you can update it with these commands:

> sudo update
> sudo upgrade
> sudo reboot

Setup the Database

Database.png

To save the history data of the sensors and store the information about the lockers and users, we will save that data in a MariaDB database. This database is already installed on the custom image, with the EER diagram that is shown in the image above.

The database has 3 main tables

1. History table

In this table, we will store the history data of the sensors or actuators. Each history item has a timestamp, a device (this is a sensor or an actuator), a value and an action.

2. Locker table

In this table, we will store the information of each locker. This is the id of the device (lock), the order details, the code and the locker's status.

3. User table

In the last table, we will store the accounts to enter the site. Each user has a unique username, a hashed password and a salt (this is a random string used by hashing the password).

Log in into the database

To log in to the database we will use MySQL Workbench. This is a MySQL client to visualize the database. If the application is installed, you can set up a new connection with the following details:

Connection method: Standard (TCP/IP) over SSH
SSH Hostname: ip of the raspberry pi
SSH Username: student
SSH Password: W8w00rd
Username database: student
Password database: W8w00rd
Note: If you changed the password of the Raspberry Pi or MariaDB server, you will need to do it also here.

Backend

The code for the backend you can find on my Github, but is already included on the custom image. This folder contains classes for the sensors and actuators in the directory /helpers. In this directory, you can also find a class for sending emails through SMTP. Under /repositories, you can find the classes to communicate with the database. And the app.py file is the main script of the backend.

Configuration of the backend

In the file named config.py, you can configure the settings of the database and SMTP server. The settings of the database are already set. For sending an email if the temperature is too high or too low, you can configure the SMTP settings. For changing the email address from the receiver of the alert or the interval between alerts, you can set these settings in the main application app.py.

Also, there are 2 secret keys you need to change in the app.py file. These are default "Secret!". But if you want to make your project secure, you will need to change these.

Add a user

To protect the web application, we will use JWT tokens to protect the site on your network. If you login into the webserver with a user account, you will receive a token with an expiration date. To add a user to your project, you can set the username and password in the addUser.py file and run it. For deleting the account, you can delete it from the database (see step 3 for connecting to the database).

Run app.py on boot

For running app.py on boot, we will need to make a service. This is already done in the image. Create a file with the name mijnproject.service.

[Unit]
Description=ProjectOne Project
After=network.target

[Service]
ExecStart=/usr/bin/python3 -u /home/student/WUK-afhaalautomaat/Code/Backend/app.py
WorkingDirectory=/home/student/WUK-afhaalautomaat/Code/Backend<br>StandardOutput=inherit
StandardError=inherit
Restart=always
User=student

[Install]
WantedBy=multi-user.target<br>

Now we will copy this file to the system directory.

> sudo cp mijnproject.service /etc/systemd/system/mijnproject.service

To start the service:

> sudo systemctl stop mijnproject.service

To stop the service:

> sudo systemctl stop mijnproject.service

To enable starting the service on boot:

> sudo systemctl enable mijnproject.service

To disable starting the service on boot:

> sudo systemctl disable mijnproject.service

Frontend

Screenshot 2021-06-11 104020.png
Screenshot 2021-06-11 104055.png

The code for the backend you can find on my Github, but is already included in the custom image. This folder contains the website's HTML pages, CSS styling and scripts to communicate between the web interface and the backend.

The frontend will be run on an apache server on the Raspberry Pi, so the IP of the website will be the IP of the Raspberry Pi.

Change the frontend directory of the apache server

For changing the frontend directory of the Apache server, you will need to edit /etc/apache2/apache2.conf.

> sudo nano /etc/apache2/sites-available/000-default.conf

Now change the DocumentRoot to the new frontend folder. Now you only need to save the file and restart the server.

> sudo service apache2 restart

Nextion Display

Screenshot 2021-06-09 165841.png

To design and program the touchscreen display, we will use the Nextion Editor and Adobe XD. The final version can you find on my Github.

Design the pages

To design a new page, we will use Adobe XD. In this application, we can easily design a page and export it to an image. This image can be set as a background of the page in the Nextion Editor.

Nextion Editor

By using the Nextion Editor, we can create pages, place interactive elements and program them. More information over the editor and commands you can find in the documentation.

Copy the project to the display

1. Export the project to a .tft file

Go to file > TFT FILE OUTPUT and export the file to an empty SD card.

2. Copy the file to the display

Turn off the display. After inserting the SD card, you can turn the display on. Now the .tft file will be copied to the display. And you can do it again to eject the SD card.



Create the Locker

20210612_152402 (1).jpg
20210417_153125.jpg
20210612_093205.jpg

If the full project works you can create the locker. For this locker, you can use a premade storage cabinet or you can make your own like me. For each part of my locker, you can find the dimensions in the Sketchup file below.

The frame

For my locker, you need to make a frame of 4 x 6 cm impregnated den bars. These bars you need to saw at length and connected them with screws to each other.

The wooden cladding

To clad the frame can you use impregnated den planchettes with a thickness of 15 mm. These planchettes can you saw at length and connect with nails to the frame. Leave the back of and top open until the electronics are installed.

The doors

For each door, you need to make a frame with planchettes attached on top of it. Each door has 3 hinges, these will connect the frame of the locker with the frame of the door. To install the hinges you can first connect one of the hinges with one screw to try if the door can fully open. If it is as wanted, you can connect the rest of them.

The locks

Now the locker is almost ready, you can install the electronics. The first thing we need to do is installing the locks. The lock you can mount on the frame in the center of the locker, and the metal piece you can mount on the door. After installing them you can test the locks and adjust them if necessary. The wire of the locks you will need to extend. This you can do by soldering a wire to each connection of the locker. Don't forget to put heat shrink over the solder joint to prevent shorts.

The touchscreen display

For the display, we will saw a hole in the front of the locker with a jigsaw. Then you can use a file to make it fit. Use some small screws to mount it from the inside.

The detector

For the detector, we will drill a hole with a diameter of 10 mm and it should fit perfectly.

Final

For the other electronics, we will mound them in the top compartment. Then we can finish the top and back by nailing the rest of the planchettes. Make sure that you can open some part of the back with screws to maintain the electronics in the future.

Downloads