Skip to content

mongodb-partners/Azure-IIoT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoDB <> Azure IIOT Solution

MongoDB Atlas and Azure IIOT solution for building a smart factory architecture.

Intro

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

Architecture

image

Steps to replicate

1. Failure detection ML model

  • 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.

2. Azure IoT

  • 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.

3. Web Service data simulator

  • Clone the github 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.

image

4. Stream Analytics

  • 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)

5. Azure functions

  • This setup requires 2 Azure functions;
    • To push data to MongoDB Atlas from Stream Analytics. Function available here.

    • Running Machine Learning model to get failure inferences. Function available here.

      Follow this guide to set-up both the functions.

6. Realm - Device Sync Mobile Application

  • 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.

7. Charts

  • 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.

image

Conclusion

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 partners@mongodb.com

About

This repo defines different modules which can help build a robust Smart Factory with a combined effort from MongoDB and Azure.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published