Spring 2015
Programming Assignment 1: Internet of Things and Smart Homes
Due: 5pm, Friday March 6, 2015
We will assume three classes of IoT objects:
The goal of the assignment is to build a distributed system with two sensors, two smart devices, and one central gateway that controls these sensors and devices. We will use this system to implement two automation tasks in the smart home.
Assume two types of sensors: a temperature sensor that reports the current temperature, and a motion sensor that reports whether it senses motion in the surrounding environment. The temperature sensor is a pull-based sensor, where the gateway must send it a query and it responds by sending the current temperature. The motion sensor is a push-based sensor where it pushes a notification to the gateway whenever it senses motion and does nothing when there is no motion.
Assume two types of smart devices: a smart light bulb and a smart outlet. Both smart devices have remote control capabilities, which means that in addition to being turned on or off normall by users, they can be remotely controlled by the gateway and turned on or off through commands sent by the gateway. Both smart devices need to support query capabilities where they are queried by the gateway about their current state and they respond whether they are currently on or off. Both also support control capabilities where the gateway can send a command to change the state from on to off, or off to on, and they perform the action and send an acknowledgement.
The gateway, sensors and devices the following interfaces:
Task 1: Preventing water pipe bursts: The winter has seen many snow storms and artic colds and you are worried that the cold temperature may cause the water pipes to freeze and burst causing your home to flood. In order to prevent water pipe from freezing, you decide to buy a pipe heater, which is simply a small heater that you plug into a power outlet and it keeps the area near water pipes warm and avoid freezing of water pipes. However, rather than keeping the heater on all winter, which is a waste of electricity, you deploy a temperature sensor near the pipes and plug the heater into a smart outlet. When the sensed temperature drops below a certain value, the heater is turned on by the gateway actuating the smart outlet. When the temperature rises above a second threshold, it is turned off. Assume that the heater needs to turn on whenever the temperature drops below 1 celsius and is turned off when the temperature rises above 2 celsius. This way, the heater is on only during nights when the temperatures drop below zero and is turned off during day hours when the temperature rises a little above zero.
Task 2: Preparing for spring break: Your home also has a motion sensor and a smart bulb. Both are deployed in living room and you have configured the gateway to receive push notifications from the motion sensor each time it sees motion or stops seeing motion. Upon seeing motion, the gteway turns on the light bulb and when it no motion is reported for more than 5 minutes, the bulb is turned off automatically. In this case, whenever you walk into the living room, the light turns on and once you leave the room, the light turns off after five minutes.
Since you are tired of the long winter, you decide to visit a friend in a warmer location for spring break. Since you are worried about the security of your home, you decide to extend this setup to implement a simple security system. In this case, whenever you are away from the home, if motion is sensed in your living room, an alert is sent to the user indicating a possible intruder (lights are not turned or off when you are away). When you are home, the presence of motion is used to turn the light on or off and no alerts are sent. In this case, the gateway supports an additional command change_mode(mode) where the mode can be HOME or AWAY. The user process can set the mode to AWAY when leaving for spring break or anytime when they leave their home for any purpose (causing the security system to be activated). The user process sets the mode to HOME when entering the home, causing the security system to be disabled and motion-actived lighting to be activated instead. The user process can also receive a text_message(string) which is used to send notifications or security messages.
Implement each sensor, device, gateway and the user as separate processes that are capable on running on different machines. All entities communicate with one another via the above interfaces. This is essential a distributed client-server application where the gateway is the central server entity. The gateway process should support concurrency where it should be capable or interacting with multiple sensors or devices at the same time.