Code for midterm in Internet of Things course, Spring '14