Spring 2017
Programming Assignment 2: Internet of Things - Smart Home Edition
Due: 23:55, March 2017
We will assume three classes of IoT objects:
The goal of the assignment is to build a distributed system with three sensors, two smart devices, and a multi-tier central gateway that controls these sensors and devices. We will use this system to implement a simple security system in the smart home.
Assume three 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.
The third type of sensor called the door sensor. The door sensor has two states: open and closed, which indicates whether the entry door is open or closed. While the door sensor can be polled to check its current state, it is primarily a push-based sensor that pushes a notification wheever there is a state chage (e.g., the door is opened or when the door is closed).
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:
The central IoT gateway should be implemented as a multi-tier architecture and we will also use clock syncronization and logical clocks to reason about ordering of sensor events.
Assume that the gateway a multi-tier application with two tiers: the front tier is the application tier that interacts with sensors and smart devices. The backend tier is a database tier that maintains a database of sensors and their current states as well as the history of prior state changes / events seen by sensors and devices. For simplicity, we will not use an actual relational database. Instead implement the database tier as a separare process from the front-end gateway process. The database process should interact with the frontend tier and maintain its state on a disk file (the file contains data for the "database" and each record is a single line with text entries). You can be creative about the schema for your database and how you store and retrieve data from your file. Be sure not to maintain the entire file in memory since it is important for the data in the database to be persistent. The front-end tier should record state changes into the database history "table" and also update the current state of each sensor in the database when it changes. The front-end tier can also query for data from the history or check the current state from the database. The front-end and back-end processes should interact with one another using RPCs, RMIs or network sockets and the two tiers should be capable of running on different machines.
You should also implement a user process to simulate arrival and departure from the smart home as well as turning on devices or triggering sensor such as motion sensor based on user movement inside the home.
Further, while the API exposed by front-end servers as as specified above, you should implement your own internal interface to handle interactions between the front-end and back-end processes (you can deisgn it any way you wish and this interface should be documented in your README file).
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 essentially 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.
Of course, your algorithm should determine which event happened before the other event using two methods: physical clock timestamps that syncronized using clock syncronization and logical/vector timestamps to determine event ordering. Log each inferred activity saying "user came home" or "user left home" in addition to logging raw events.
Based on this reasoning, we can automate the process of turning the home's security system on or off automatically. If the user leaves the home, turn the system from HOME to AWAY and turn on the system. If the user enters the home, turn the system to HOME mode and turn off the security system. Like before, when the user is home, motion detection is used to turn on lights.
While the system can not automatically distinguish between the user process entering the home from the burglar process (and whether to raise an alarm or not), this issue can be addrresed by adding a "presence sensor" which is simply a beacon attached to the user's keychain. When someone enters the home, the presence or absence of such a push events from such sensor can be used to distinguish between the user and an intruder. Raise an alarm if an intruder is detected.
You are free to develop your solution on any platform, but please ensure that your programs compile and run on the edlab machines (See note below).
Make necessary timeline plots or figures to support your conclusions.