0% found this document useful (0 votes)
21 views8 pages

21mis1035 Iot Lab Exercise 6

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views8 pages

21mis1035 Iot Lab Exercise 6

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

21MIS1162 IOT LAB EXERCISE 6

Aim: Message notification – Mention the subject as “Drug consumption level


reg”. – Message as HR:80, SpO2:85, BP:100, consumption level: Medium

Components: Node Red

Procedure:
1. Configure the Inject Node
 The Inject node simulates patient data (HR, SpO2, and BP).
 Click on the Inject node and check the following settings:
o Payload Type: Ensure it is set to JSON.
o Payload: The data is set to:
Json
{
"HR": 80,
"SpO2": 85,
"BP": 100
}
o Topic: Leave empty or use a descriptive label like "Patient Data
Simulation."
 This node can be triggered manually or set to inject data periodically by
adjusting the Repeat interval.
2. Configure the Function Node
 The Function node processes the patient data and determines the
consumption level (High, Medium, Low) based on the thresholds for HR,
SpO2, and BP.
 Click on the Function node and review the code to ensure it's calculating
the consumption level correctly:
o The thresholds are defined as:
 HR: Low (60), High (90)
 SpO2: Low (80), High (90)
 BP: Low (90), High (120)
o The logic checks the input values and categorizes the consumption
level:
 High: If HR > 90, SpO2 > 90, and BP > 120.
 Low: If HR < 60, SpO2 < 80, and BP < 90.
 Medium: Otherwise.
 The function node then formats the output message:
o msg.payload will include the HR, SpO2, BP, and the corresponding
consumption level.
o msg.topic is set to "Drug consumption level reg" for reference.
3. Configure the Email Node
 The Email node sends an email notification with the results of the
analysis.
 Click on the Email node and configure the following settings:
o Server: Replace smtp.your-email-provider.com with the SMTP
server of your email provider (e.g., smtp.gmail.com for Gmail).
o Port: For SSL, use 465; for TLS, use 587.
o Secure: Ensure this is set to true if using SSL/TLS.
o TLS: Set to true for secure email sending.
o Authentication: Enter the sender's email address and password (or
app-specific password, if needed).
o Recipient: Set the To address to the recipient’s email.
o Subject: You can leave the subject as it is or customize it (e.g.,
"Patient Consumption Level Notification").
o Message Body: This is automatically set from the msg.payload
generated by the previous function node, which will contain the
patient data and consumption level.
4. Deploy the Flow
 After configuring all the nodes, click the Deploy button in the top-right
corner of the Node-RED editor to save and run the flow.
 The flow will now be active, and the Inject node will trigger the data
simulation.

Flow screen shots:


Output screen shots:

JSON flow:
[
{
"id": "de5bf86c4c7b242e",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "inject-node-id",
"type": "inject",
"z": "de5bf86c4c7b242e",
"name": "Simulate Patient Data",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": "0.1",
"topic": "",
"payload": "{\"HR\":80,\"SpO2\":85,\"BP\":100}",
"payloadType": "json",
"x": 180,
"y": 260,
"wires": [
[
"function-node-id"
]
]
},
{
"id": "function-node-id",
"type": "function",
"z": "de5bf86c4c7b242e",
"name": "Determine Drug Consumption Level",
"func": "let HR = msg.payload.HR;\nlet SpO2 = msg.payload.SpO2;\
nlet BP = msg.payload.BP;\n\n// Determine the drug consumption level\nif
(HR > 90 && SpO2 > 90 && BP > 120) {\n msg.payload = \"High\";\n}
else if (HR < 60 && SpO2 < 80 && BP < 90) {\n msg.payload = \"Low\";\
n} else {\n msg.payload = \"Medium\";\n}\n\n// Set the email subject and
message\nmsg.topic = \"Drug consumption level reg\";\nmsg.payload =
`HR:${HR}, SpO2:${SpO2}, BP:${BP}, consumption level: $
{msg.payload}`;\n\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 500,
"y": 260,
"wires": [
[
"email-node-id"
]
]
},
{
"id": "email-node-id",
"type": "e-mail",
"z": "de5bf86c4c7b242e",
"server": "smtp.gmail.com",
"port": "465",
"authtype": "BASIC",
"saslformat": false,
"token": "oauth2Response.access_token",
"secure": true,
"tls": false,
"name": "[email protected]",
"dname": "Send Email Notification",
"x": 830,
"y": 260,
"wires": []
}
]

You might also like