MakeUofT is Canada’s largest makeathon. Similar to a hackathon, it’s a place where projects come to life; a makeathon focuses on hardware-based projects where students build something from scratch through hardware and software integration.

The theme for MakeUofT 2020 was connectivity and machine learning. As a prime sponsor of the event, Solace challenged participants to make the best use of Solace PubSub+ Event Broker to stream events and information across cloud, on-premises, and IoT environments.

Joshua, a Mechatronics Engineering student at the University of Waterloo, participated with his group members in the MakeUofT 2020 hackathon and chose Solace’s technology to make their project. Below, he shares how he and his group designed and developed their project.

Inspiration for the Project

I have always been interested in the Internet of Things (IoT). In a nutshell, IoT boils down to having multiple devices (or “things”) connected together over a network to create automated process. Besides, the theme for MakeUofT 2020 was connectivity. So, it is quite natural for us to have an IoT project.

Home automation is an up and rising trend gaining more interest these days, anything from automatically controlling lighting, climate, entertainment systems to controlling appliances, home security and access control alarm systems in the house falls under the umbrella of a smart home. After thorough research and consideration, we decided to build a smart home prototype where we could create custom automated processes within the house.

What It Does

For our smart home implementation, we wanted to have a synchronized interaction between a web application and the IoT device in our smart home. This was achieved by having users click a button on a website which in return triggered an automated smart home process that would run on the hardware side of our smart home. Due to the time limitation of the hackathon, we decided to automate the following processes:

  1. Playing music (we a chose a Star Wars theme song!)
  2. Opening and closing a door
  3. Turning on a fan
  4. Ringing the alarm
  5. Turning on lights that changed color

We also included a party mode which simultaneously ran all these processes at once.

Our Design and Implementation

AWS API to Lambda to Solace to Arduino

Our design implementation included interactions between

  1. AWS API Gateway
  2. A Lambda function on AWS
  3. Solace PubSub+ Event Broker
  4. Arduino

Publisher

The workflow starts with the user clicking a button on the web application. This interaction triggers a GET request through the API gateway based on the button clicked.

k815wcmr99.execute-api.us-east-1.amazonaws.com/test/publictosolace?topic=openDoor

The API gateway triggered an AWS lambda function written in Python. This function’s sole purpose was to publish to a specific Solace topic based on the message body in the GET request. For example, if the message from the GET body request was “openDoor”, then the openDoor topic is published to the Solace PubSub+ Event Broker. This is synonymous to saying the web application is the “Publisher” of events.

Message = event[‘queryStringParameters’][‘topic’]
if message == “openDoor”:
	solace_topic = “openDoor”

# Publishes message to the MQTT bridge
publish(client, solace_topic)  

For more details on how the web page interaction was mapped to topics, check out this github repository

Subscriber

Our NodeMCU, programmed using the Arduino IDE, subscribed to various Solace topics. Based on the topic subscription, the NodeMCU performed a specific callback function that in return executed a certain behavior.

On the hardware side of our smart home, we used a NodeMCU (ESP8266). A NodeMCU works like typical Arduino UNO board, but what makes it different is that it has WiFi access which enabled us to connect to the Solace message broker. The NodeMCU was also used to connect to the different hardware components that performed various smart home functions. This included motors for our fan and door, a multicolor LED for our color-changing lights, a piezo buzzer for the music and alarm system, and an OLED display.

The Solace PubSub+ Event Broker has support for MQTT as a messaging protocol and it acted as a bridge that helped us easily connect our web services components to the hardware components of our project. From a web services standpoint, using an AWS lambda makes it very simple to publish to a topic as the Solace PubSub+ Event Broker took care of sending that data to subscribers. The publish/subscribe (pub/sub) pattern made it easy to get the NodeMCU to subscribe to different Solace topics and the Solace PubSub+ Event Broker took care of sending data to the NodeMCU whenever data was published to one of those topics from the web application.

Note that following this pub/sub pattern, we were also able to set up our architecture to easily expand on our smart home in the future. It allows us to send one command to multiple devices and take an action on it (this is how we easily implemented the party mode!). This architectural approach can also easily allow us to capture events and perform analytics to make recommendations for smart home users in the future.

Below is the code of our callback function that was set for the MQTT client. Note how easy it was for us to perform a specific smart home task based on the topic that was published.

//MQTT Callback
void callback(char* topic, byte* payload, unsigned int length) {

	//Make a copy of the payload
	byte message[length + 10];
	memcpy (message, payload, length);
	message[length] = “\0”;

	//Make a copy of the topic
	char t[sizeof(topic)* 4];
	strncpy(I, topic, sizeof(topic)* 4);

	String topicString(t);
	//function call based on topic string
	if (topicString.equals(“light”)) {lightDisplay(); }
	else if (topicString.equals(“fan”)) {turnOnFan(1000); }
	else if (topicString.equals(“music”)) {firstSection(); }
	else if (topicString.equals(“openDoor”)) {openDoor(); } 
 	else if (topicString.equals(“closeDoor”)) {closeDoor(); } 
	else if (topicString.equals(“alarm”)) {alarmMode(); } 
	else if (topicString.equals(“party”)) {partyMode(); } 
	else {}
}

What’s Next

To further expand on this project, we would like to create custom Alexa skills where when users say a specific phrase, it triggers automated processes within the house. This would allow us to simulate a real-life example of how custom smart home commands could be implemented. For this design, the Alexa skill would trigger the AWS lambda which would publish to Solace PubSub+ Event Broker.

What I Learned

Through this project, I finally got hands-on experience with IoT and learned about the complexity and detail required for the various components of an IoT system to work correctly. I have also developed an understanding of the importance of a message broker like Solace PubSub+ Event Broker as it simplifies the connectivity between hardware and software along with allowing an easy expansion of our architecture through the decoupling of different components by following the pub/sub pattern. Furthermore, I learned about the various platforms that Solace PubSub+ Event Broker can be used with and about its many IoT applications that I look forward to exploring in the future.

You can watch a video of the project in action, and see our code in GitHub here.

Joshua Kurien is a first-year Mechatronics Engineering student at the University of Waterloo. He is passionate about the fields of IoT, robotics and machine learning and is interested in using these technologies to develop solutions to real-world problems.

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

PubSub+ Event Portal is now GA! Learn More