Smart Box

Amir Amer (305310534), Sleman Abu Rashed (205673668), Muhammed Mahajna (311465967).


Our project is a web application, intended to be used by people to pick up their mail, and online shoppings.
Using our application, it becomes easier to collect your mail. On the one hand, users won't have to wait inline at the post
office to pick their mail up. We make sure to send our customers an email regarding their package, so they can pick it up in the nearest
Iot Workshop service. On the other hand, users will only be able to access our services if they have a mail or package waiting for them.
Using this feature, we save our customers alot of time, since the application will let them know, that they don't have anything waiting for them,
and thus, customers won't come to get their mail just to know that they don't have one.

Screen and features:

User Mode

Main page

This is the main page of our web application. In this page, users who have already signed up, can log in, and enjoy our services provided to them. Also, customers who still haven't signed up, can create a new account. If a user tries to log in, using an email that isn't in the system, a pop up message will apear telling them that the email isn't found, and they need to
to create a new account if they wish to use our services.

Sign up:

Customers who still haven't signed up, can do that using the above page. If a user tries to sign up using an email, that already exists in the
system, a message will apear, notifying them to try another email. We also added a feature regarding the password length, i.e. the password must be of at least 6 characters.
After the customer signs up, an email is sent, notifying them to confirm their email by entering their email and code.

The email that the user receives is as such:

And the page that the user enters his email and code:

The user is then redirected to the main page to log in. In case the user didn't confirm his email, he'll see a message pop up asking him to verify his email, and then redirected to confirm his email. Once the user logs in, he is redirected to a page, where he has to verify his network connectivity. In this page, what we did is we saved the ip address of the network the raspberry pi is using, and whenever a customer logs in, if he's using a network that is different than the raspberry's network, he is asked to connect to the same network as the raspberry's, or to contact support if needed.
In either case, a message will apear letting him know if he has a mail waiting or not.

If the user is using the same network as the raspberry, and has a package waiting, we send him an email containing a code. This code is used by the user to open the box and take his mail. Once the user opens the box, his code expires and never used again.

The user is redirected to the main page of his service, i.e. the user page. In this page the user enters his code, to open the box and take his belongings. When the customer enters a wrong code, he is notified. If the code is correct, the box is opened, and he can then take his mail. Also, we ask him to close the box after use. The unlock/lock buttons, connect to the iot hub in azure, and send a cloud to device message. Such message, is then read by the raspberry pi. The device listens to messages coming from azure iot hub, and performs accordingly.

Admin Mode
We created an email to be used by the admin/mail man, so he can open and lock the box as he sees fit. Also, to send cutomers email letting them know they have a package waiting for them. The email and password are given to the mail man in advance.
Uppon logging in, we created a feature that listens to messages coming from the raspberry pi, regarding the box's status. The raspberry pi, using a timer, keeps on listening whether the box is full or empty. This is done using a digital distance sensor. We added a led connected to the sensor's output. So if the box is full, the led will light, otherwise, it will be off. We added the led, in case of failure regarding the network connection between the iot hub and the raspberry pi.

As said before, if the user tries to enter, when he still hasn't received the email above, he'll be notified that he has no item waiting. Only in the case he receives the email, he can then enter and continue as explained in the user mode. The mail man, as said before, knows if the box is empty or not. If its empty, he unlocks it, and then types the email of the customer, so he can come and pick his mail, and locks the box after he is done.

Of course, if the package's email address does not exist in the system, a message will pop up, notifying the mail man to contact the post office.


We used azure services to build our web application.

As seen above, we used a web app service to deploy and publish our website.
For storing the user's information, we used MySQL database. Here we created 4 tables:
1) Users: In this table we stored the user's email, and personal information. Regarding the password, we created a class, to encode and decode our input password. Using this class, we stored the encrypted password. And when the user logs in, we decrypt the password from the database, and compare it with the input password.
2) Confirmation: This table is used to check the user's status when logging in. If his email is confirmed or not.
3) box: The box table contains the users email and a feild called isPurchase. This feild is either 1 or 0. When the mail main sends and email to the user, isPurchase is updated to 1, which means, he has a package. Otherwise, the value is 0.
4) Code: When the user clicks on verify to check his network connectivity, an email is sent to him if he's using the same network as the raspberry pi, containing a code. This code is stored in the Code table, and used to check the users code upon unlocking the box. The code is initialized to -1 after the user opens the box, to prevent him from using the same code again.

For sending emails, we used the services of SendGrid. This service allows to send smtp protocols, and we saw fit to use one of azure services, rather than other smtp services.

And the iot hub is used for communication, between the web application, and the raspberry pi. This service is used in both directions. Meaning, the raspberry pi sends and listens to azure iot hub, and the web application does the same.

Video and pictures:


The code is divided into two sections. Once is for the web application and the other is for the raspberry pi code(UWP).
Web application: In the web application we have 6 web forms:
1) Main page: As said before, in this page the cusomer/mail man logs in, and uses our services.
2)Sign up page: As any sign up page, this is for storing the customers information, to be used later on.
3)Verify page: This page was added to make sure that the customer is using his/her own email, and not someone elses. For that, we added a verify your email page. We send the customer an email containing a verification code, to verify their email.
4)ClientConnectivity page: For the user to use our services, we added this page, that checks the user's internet ip address. If the address is the same address that the raspberry pi is using, then he is redirected to the user page, otherwise, for him/her to user our services, they must use the same internet connection as the raspberry's.
5)User page: After the user has verified his connection, he enters the user page, where he/she can open the box and collect their items.
6)Admin page: The admin has his own page. The page control the opening and closing of the box. As well, notifying the admin if the box is empty or full. The admin opens the box if it's empty, places the item he wants to deliver, and then after closing the box, sends an email to the customer letting them know there's a package waiting for them.
UWP application:
As for the raspberry pi, what we did is connect it to azure's iot hub, and it sends and listens to messages.
As for the messages received, it receives an action, which is open or close the box. The box is connected to the gpio, and according to the messages, the raspberry behaves.
The messages sent, are messages of the box's status. We placed a digital sensor in the box, and using a timer, we send to the iot hub messages about the box's status, i.e. empty or full.

The backend of the code is written in c#, and the frontend was written in, using css.

For locking and unlocking the box, we initially wanted to use a solenoid, but after connecting the solenoid to the raspberry pi, it spoiled the SD card used in the raspberry pi, and therefore, we replaced it with a led and a resistor, to indicate whether the box has been opened or closed.
To check whether the box is empty or not, we used a digital distance sensor. The sensor is very sensitive, it detects objects from 0.2 cm to 5 cm, so it was a bit of a challenge adjusting it in the right angle and distance. We put a stand, 3 cm above the sensor, to detect whether the box is empty or not.
The sensor comes with an output pin. To this pin we attached a resistor and a led, so that when the sensor detects an object, the led will light up.