- 
Simulated PLC
- Generates sensor reading data and sends it to IoT Hub
 
 - 
Function App
- Triggers when IoT Hub receives a new message
 - Sends the message to Anomaly Detector API (Cognitive Services)
 - If Anomaly is detected, calls a Logic App
 
 - 
Logic App
- Fetches the email content from query string
 - Sends the email using Send Grid
 
 - 
(Optional) Real time Dashboard
 
- Create a new IoT Hub Device and copy the connection string.
 
- Create a new Send Grid Account.
 - Create a logic app using 
logicapp\template.jsonas guidance 
- Create the Anomaly Detector cognitive service resource in Azure.
 - Copy the key and endpoint from the Quick Start section.
 
- Create a NodeJS Function App.
 - Add following Application Settings:
- Name: 
anomalydetector_endpoint| Value:<Anomaly Detector API key> - Name: 
anomalydetector_key| Value:<Anomaly Detector API endpoint> 
 - Name: 
 - Create a new Function with IoT Hub as trigger and connect it to the IoT Hub created above.
 - Use the function 
Consoleto install following npm packages inD:\home\site\wwwrootdirectory:npm install @azure/cognitiveservices-anomalydetectornpm install @azure/ms-rest-js
 - Update the index.js file code with 
function\index.js - Update the 
logicAppWorkflowPathvariable insendEmailmethod with the logic app workflow path 
- Clone the repo
 - Install Nodejs
 - Goto 
simulated-plcfolder in command line - Run 
npm install - Create 
.envfile and add following variables:deviceConnectionString='<Your IoT Hub Device Connection String>'
 - Run 
node . 
