uOttaHack is Ottawa’s largest hackathon that takes place every year at Ottawa University. This year’s event welcomed over 400 students from a variety of backgrounds to collaborate, participate, and innovate! As a prime sponsor of the uOttaHack3 event, Solace challenged students to leverage the PubSub+ Event Broker: Cloud technology to create something truly unique.

A group of three students from Concordia University worked together to build a smart delivery system to deter people from stealing packages and enable real-time delivery notifications.

Jay Wreh, Derek Yu, and Zach Bys describe their project in detail below:

The Solace Challenge Winner – SmartBox Delivery System

At uOttaHack 3, a student hackathon hosted at uOttawa, we built the SmartBox Delivery System. Our project won the Solace Challenge for the best use of Solace PubSub+ Event Broker: Cloud.

SmartBox Delivery is an end-to-end system that allows independent couriers to easily and securely deliver their parcels and packages, making porch pirates and missed delivery notices a thing of the past!

How It Works

UOttaHack 3 Solace Challenge

Scanning a package in the app.

At the sorting facility, a delivery agent scans a customer’s package through the SmartBox Delivery app. This will automatically reserve an available SmartBox that is the nearest to the customer. When it comes time for the delivery, the package is placed inside the allocated box, after which it will automatically close and lock once the delivery person marks the items as delivered.

When the customer is ready for pickup, they simply scan the SmartBox containing their package and the box will automatically unlock and open for them to retrieve their order. Customers can also choose to subscribe to notifications through various channels, including smart assistants like Alexa!

Under the Hood

The system is comprised of three main components: the mobile application, the backend service, and the external clients (which includes the SmartBoxes themselves).

UOttaHack 3 Solace Challenge

By leveraging Solace PubSub+ Platform as a messaging service, the backend and external clients are able to instantly communicate through an event-driven architecture. More specifically, Solace PubSub+ Platform was used to publish events for the SmartBoxes to listen and react to. For instance, a ‘PO_BOX_RESERVE_REQUEST_EVENT’ is published by the backend service once a delivery agent is ready to start a delivery of one or more packages:

/*
 * Starting a delivery agent's trip
 */
const addTrip = async (request, h) => {
    try {
        let succesful = [];
        let failed = [];
        let poBoxes = [];
        for (const orderId of orderIds) {
            try {
                const order = await getCustomerOrder(orderId);
                const box = await reservePOBox(order);
                
                // Publish event for target box to
                messagingClient.publish(PO_BOX_RESERVE_REQUEST_EVENT, JSON.stringify({ boxId: box.id }));

               // Record reserved SmartBoxes
               poBoxes = [...poBoxes, box];

              // Record orders that were successfully assigned a SmartBox
              succesful = [...succesful, order];
           } catch (error) {
             // Record any orders that the system was unable to assign a SmartBox
             failed = [...failed, order];
           }
        }
        const id = await addTrip({ userId, succesful });
        return h.response({ id, failed, poBoxes }).code(200);
     } catch (error) {
        return  h.response({  message: error.message  }).code(500);
     }
}

The SmartBox, which is subscribed to that event, will then glow red and mark itself as reserved once the event is received.

SmartBox Delivery System

Here is an example of a code snippet for the SmartBox controller listening for the event:

RESERVE = "PO_BOX_RESERVE_REQUEST_EVENT"
...

# Subscribe to events
def on_connect(client, userdata, flags, rc):
    ...
    client.subscribe(RESERVE)
    ...
...

# When an event is received via Solace
def on_message(client, userdata, msg):
    payload = json.loads(msg.payload.decode())
    if (payload['boxId'] == PO_BOX_ID):
       if msg.topic == RESERVE:
          # The value '1' indicates the reserved state
          arduino_message = 1
       ...
    ...

    # Send the command to the microcontroller
    arduinoOut.write(str(arduino_message).encode())
    ...

Once the delivery agent deposits the package into its respective SmartBox and confirms its delivery, a `PACKAGE_DELIVERED_EVENT`event is published:

const deliverOrder = async (request, h) => {
    try {
        const { boxId } = request.params;
        const box = await getPOBox(boxId);

        // Update order status to delivered
        let { order } = box;
       order.status = 'DELIVERED';
       await updateOrder(order);

       // Publish delivery event for corresponding box to close
       messagingClient.publish(PACKAGE_DELIVERED_EVENT, JSON.stringify({ boxId }));
       return h.response({ message: `Order with id=<${order.id}> was successfully delivered` }).code(200);
   } catch(error) {
       return h.response({ message: error.message }).code(500);
   }
}

On reception of the event, the SmartBox reserved for the specific customer order closes and locks. A similar sequence of events occurs at the final step, when the customer goes to retrieve their package.

Inside the SmartBox

The delivery system was based on a wonderful proof of concept of the SmartBox hardware, built out of a used, resilient, and durable cardboard box. The “Smart” in the SmartBox is an Arduino Uno, connected to a computer using a serial communication channel. This allows commands to be sent to the box upon reception of events.

Two micro servos, along with an extension connected to a pivot system on the latches served to open and close the box on demand. Another micro servo was used to raise a flag attached to the box; this one being activated when an object broke an IR beam installed inside. These sensors were sensitive and accurate and allowed for instantaneous feedback when the package was placed in the SmartBox.

Finally, we had a digital RBG LED strip attached to the front to display the state of the system tothe user. An example of this would be to glow green when the box is available for reservation.

What we learned

We learned so much during our time at uOttaHack 3 including how easy it is to configure a message broker within Solace PubSub+ Platform. Integrating our backend with the cloud message broker was really simple thanks to Solace’s Node.js and Python starter examples. Through discussions with Solace representatives, we were also able to solidify our understanding of event-driven architecture and why it is so useful. In our case, we found that communication between various IoT devices was a perfect use case for Solace PubSub+ Platform.

Final Thoughts

Solace’s PubSub+ Event Broker is an amazing way to integrate real-time scalable messaging to any project. For us, it helped to abstract and simplify the communication of our backend service to IoT devices such as the SmartBox we built and Amazon Alexa.

Thank you to the Solace team at uOttaHack 3 for taking interest in our project and helping us bring our ideas from our heads into the real world!

You can explore more of the SmartBox Delivery System code on GitHub.

Authors

Jay Wre

Jay Wreh is a Software Engineering student in his final year of studies at Concordia University. He’s a hackathon enthusiast, having participated in seven over the course of his undergrad.

Derek Yu

Derek Yu is a 4th-year Software Engineering student at Concordia University in Montreal, Canada. Having worked on numerous projects, previous internships, and various hackathons, he has developed a passion for backend development and the technical challenges that come with it.

Zachary Bys

Zachary Bys is a 4th year Software Engineering student at Concordia. He loves to participate in Hackathons because they allow him to bring his wildest ideas to life!

Logo Solace Community Solly
Solace Community

The Solace Developer Community is the technical community for Solace PubSub+. It is the place where community members from all backgrounds and experiences socialize, share resources, organize projects together, and help each other. If you haven't already signed up for it, we encourage you to do so now and get involved in the action!

Join Our Developer Community

Join the Solace Developer Community to discuss and share PubSub+ API hints, new features, useful integrations, demos, and sample code!

JOIN THE DISCUSSION