Summary
You accomplished a lot in this example. We started with the diagram below and configured all the components. We made some choices along the way to keep the example as simple as possible but hopefully still interesting enough.
We started with the Particle device and wrote a simple program that publishes a Particle event with a random value to the Particle Cloud. The IoT Hub integration of Particle Cloud forwards the data to an Azure IoT Hub. We created the IoT Hub with the Azure CLI 2.0 and used the free tier that is limited in the amount of messages it can receive.
To get the data into an intermediate pub/sub server, we wrote an Azure Function that uses an Event Hub trigger to pick up the values sent to the IoT Hub. Note that we did not deploy a separate Event Hub here. An IoT Hub uses an Event Hub as a way to make incoming values available to applications and we made use of that Event Hub. The Azure Function uses the Consumption plan that is billed per use and has a monthly free grant of 1 million requests and 400000 GB-s of resource consumption.
The Azure Function writes the values it picks up as JSON text to a Redis channel. We deployed a simple Redis instance using Azure Redis Cache and used the pub/sub functionality of Redis.
Then we wrote a service to send realtime data to browsers. We used Node.js with socket.io to do just that. The Node.js application also hosts a simple website that uses the socket.io client and a bit of jQuery to update the website with the Particle device values as they come into Redis.
The Node.js application was packaged in a container and its image was stored in an Azure Container Registy. We then used the Azure App Service and its ability to run an application in a container to host the realtime service in the cloud. You were able to test the functionality of your realtime service on your local computer before deploying the application to the cloud.
This example is quite functional but it can use some changes:
- use of real sensors like temperature and humidity sensors
- send multiple values at once (e.g. both temperature and humidity every 10 seconds)
- change the Azure Function to automatically send measurements of a device to a channel with the device's name
- change the socket.io client to be able to select a device
- make the socket.io client look nicer
- store the values we received from the devices in persistent storage (raw data on disk and/or a database like SQL Server or DocumentDB)
- ability to query the historical data
- and much more...
Many things to do so let's get to it!