MongoDB Atlas and Azure IIOT solution for building a smart factory architecture.
Imagine a manufacturing facility that has sensors installed in their CNC machines measuring parameters such as temperature, torque, rotational speed and tool wear via vibration. These sensors are sending data to a sensor gateway which is connected to Azure IoT Edge and sending sensor data through MQTT protocol. This data is then transmitted to Azure IoT Hub where the IoT Edge is registered as an end device.
Once we have the data in the IoT Hub, we can utilize Azure Stream Analytics to filter the data so that only relevant information flows into the MongoDB Atlas Cluster. The connection between Stream Analytics and MongoDB is done via an Azure Function.
This filtered sensor data inside MongoDB is used for following purposes: To provide data for machine learning model that will predict the root cause of machine failure based on sensor data To act as a data store for prediction results that are utilized by Azure Synapse Analytics and Power BI for analytical queries To store the trained machine learning model as a JSON document in a collection
The overall architecture is shown below
- An ML model can be trained using MongoDB as a feature store to train other ML models as well, in order to detect if a failure occurs and predict its type. This can help in reducing the time to diagnose the machine and finding its root cause. Data for training the model can be found here.
- Refer this notebook to train your ML model.
- Once the model is trained, you can use
pickle
module to convert the model as binary and store it in MongoDB.
from bson import Binary
import pickle
model_out = {"tag":"DecisionTree", "model_ckpt":Binary(pickle.dumps(decision))}
model_coll = db['models']
res = model_coll.insert_one(model_out)
print(res.acknowledged)
- This model can then be used (as shown here) to make predictions using a simple Azure function.
Setup IoT Hub in your Azure account, following this link.
Register a new device
Once the device is registered successfully, copy its primary connection string.
Clone the repo in your local, and go to web-app folder.
Install dependencies using
npm install
.Start the service using
node app.js
, and input the primary connection string copied in previous step to establish connection.
Once the data reaches IoT Hub, it can then be served to Stream Analytics for filtering and pushing to MongoDB Atlas.
Follow this step for setting up a Stream Analytics job.
Add IoT Hub as input for the job.
For output select Azure functions. (See Step 4 below for setting up azure function)
- This setup requires 2 Azure functions;
- Android application helps in keeping the user notified about any failures that may happen in the factory.
Follow this guide to setup the mobile application.
- Once running, the application can pull failure notifications captured by ML Model.
The real time data can be analysed using various charts available under MongoDB Charts.
Refer this link for setting up one for yourself and you can build awesome charts like this.
This gives a working template to setup an end-to-end flow for smart factory, to analyse its telemetric data using MongoDB Atlas and Azure IoT Services.
For any further information, please contact [email protected]