Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

IoT Domain Analyst

Lab Task – 2
Name: Suhas Siriprole Reg.No: 18BEC0327 Slot: L15+L16

Question:
Design an IoT application that controls the lights, household appliances present
in a home. The application should control and decide the course of relevant
action across the following rooms:
a. Level of illumination (Energy Efficient Lighting - EEL) in Kitchen,
Living and Bedrooms.
b. Airflow in kitchen and rest rooms
c. Humidity and temperature-based operation of Air Conditioners (AC) in
the aforesaid rooms. Also, manual or automatic mode of AC operation.
d. Also, the Television set present in living room must be monitored.
The above functionality must be realized in IoTiFY platform with the template
(Smart Home) coded in C language.

Solution:
Codes are written is JavaScript
Initialize:
{
state.rooms = {
living: { id: 1, name: "Living Room", occupancy: true, temperature:
55, lights: true, tv: true, aircondition: true},
bedroom: { id: 2, name: "Bed Room", occupancy: false, temperature: 60,
lights: false, aircondition: false},
kitchen: { id: 3, name: "Kitchen", occupancy: false, temperature: 58,
lights: false, airflow: false},
restroom: { id: 4, name:"Restroom", occupancy: false, lights: false,
airflow: false}
};
}
Message Generator:
{
// Generate Random Hour of the Day in 24Hr Format
let currentHour = chance.integer({min: 0, max: 23});
console.log("The Hour of the Day is: " + currentHour);

// Check if it is Night or Early Morning Hour


if (20 < currentHour || currentHour < 7)
{
// Kitchen is OFF
state.rooms.kitchen.occupancy = false;
state.rooms.kitchen.temperature = 31;
state.rooms.kitchen.lights = false;
state.rooms.kitchen.airflow = false;

// Restroom is OFF
state.rooms.restroom.occupancy = false;
state.rooms.restroom.lights = false;
state.rooms.restroom.airflow = false;

// Living Room is OFF


state.rooms.living.occupancy = false;
state.rooms.living.temperature = 28;
state.rooms.living.lights = false;
state.rooms.living.tv = false;
state.rooms.living.aircondition = false;

// Occupant present, AC = ON, Lights = OFF


state.rooms.bedroom.occupancy = true;
state.rooms.bedroom.temperature = 23;
state.rooms.bedroom.lights = false;
state.rooms.bedroom.aircondition = true;
}
else // Normal Day
{
// Lights and AC will mostly be dependent upon occupancy.

// Kitchen depends upon Occupancy & Temperature


state.rooms.kitchen.occupancy = chance.bool();
state.rooms.kitchen.temperature = chance.integer({min:25, max:40});
state.rooms.kitchen.lights = state.rooms.kitchen.occupancy? true: false;
state.rooms.kitchen.airflow = (state.rooms.kitchen.occupancy ||
(state.rooms.kitchen.temperature > 28)) ? true: false;

// Restroom depends upon Occupancy


state.rooms.restroom.occupancy = chance.bool();
state.rooms.restroom.lights = state.rooms.restroom.occupancy? true: false;
state.rooms.restroom.airflow = state.rooms.restroom.occupancy? true: false;

// Living Room depends upon Occupancy


state.rooms.living.occupancy = chance.bool();
state.rooms.living.temperature = chance.integer({min:23, max:35});
state.rooms.living.lights = state.rooms.living.occupancy ? true: false;
state.rooms.living.tv = state.rooms.living.occupancy ? true: false;
state.rooms.living.aircondition = state.rooms.living.occupancy ? true: false;
// Bedroom generally OFF
state.rooms.bedroom.occupancy = false;
state.rooms.bedroom.temperature = chance.integer({min:23, max:35});
state.rooms.bedroom.lights = false;
state.rooms.bedroom.aircondition = false;
}

//return a string value which will be sent as the message payload


return JSON.stringify(state, null, 2);
}

Response Handler:
{
try {
let cmd = JSON.parse(response);
if (cmd)
{
state = Object.assign(state, cmd);
}
}
catch(e){
console.log(e.message)
}
}

Finish is left Default(untouched).

Simulation:
Simulation is done with –
• Number of Clients: 5
• Repeat Message: 1
• Rest as Default
Simulation State Results: CSV

Simulation ScreenShot from IoTiFy:

Result:
Successfully designed an IoT application that controls the lights,
household appliances present in a home with given specifications. Functionality
has been realized in IoTify Platform with template (Smart Home) coded in
JavaScript Language.
----------------------------------------------X------------------------------------------------

You might also like