Just last week I wrote a quick blog on my Company’s portal on the integration of Sitecore Experience Platform 9 with IoT devices. I wanted to convey a message of the importance of IoT to Commence. Even though Amazon just pulled a plug on their IoT Dush button in lieu of Amazon Alexa, I am a strong believer that Commerce IoT is here to stay. The Button may not be the best solution for ordering Cats Food, but a small business may benefit greatly and even save money by using an automated inventory replenishment process as an example.

My goal is to demonstrate that connecting IoT Device with Commerce platform is no longer the privilege of companies like Amazon but can be done even by the smallest commerce provider. In my solution, I want to follow the latest and greatest design principals, based on microservice and event-driven architecture. These principals are an evolution of OOP, with even greater support for decoupling. I selected Sitecore XC 9, which is written in .NET Core and designed using Microservice principles. I selected Azure to handle IoT logic as it has all core components I need to make smooth integration with Sitecore XC9. Now, I’ll use Serverless architecture of Azure to tie my Commerce Server with IoT as shown on this diagram:

So, let’s get started. First, I’ll create a Sitecore Microservice Plugin to allow placing orders over a single endpoint. Please note, I did not follow Sitecore best practice of creating blocks, entities for persistence and interfaces for reusability nor I did address federated payment logic. My goal was to create secure order orchestration endpoint using Sitecore Commerce Engine.

Now, we are done with Sitecore development, and we will create IoT Logic. To do so, we will use IoT DevKit – an Arduino based device certified for Azure. In this example, we will use button events to place an order. To build code for this device, I am using Visual Studio Code with Azure IoT Device Workbench extension. The complexity of connecting your IoT Device with Azure cloud is abstracted by DevKitMQTTClient_SendEvent method. This method sends machine-to-machine, extremely lightweight messages(MQTT), to Azure IoT Hub. The DevKitMQTTClient_Check monitor response pipeline and updates IoT Device screen with an order ID.

And lastly, we will create a ‘glue’ – integration logic to connect or IoT device with Sitecore. Thanks to Azure Serverless platform, we would not need to write a lot of code, introduce bugs or write Unit Tests. The only code we need to write is to process messages, generated by our IoT device and route requests to our Sitecore Commerce Engine. The Azure Function is an excellent choice for processing IoT Hub messages and performing necessary actions(see code below).

I hope I convinced you that doing IoT with XC9 is easy! What took me a weekend to develop now, could’ve taken me months just a few years back. Thanks to Microsoft Azure and Modular Sitecore XC9 I can deliver world-class scalable commerce applications with a minimal effort.