Nest Model

From ESE205 Wiki
Jump to: navigation, search


Our project is to create a smart outlet consisting of a raspberry pi zero, a relay, and a container that works between an AC outlet and a device. We'd like to be able to communicate between a web interface and the outlet to be able to turn the device on and off. We would also like to add timing control features through the web interface. If we are successful with the initial project, we will add additional modules to the web interface to be able to control multiple devices.

Team Members

Amanda Hua
Tricia Brown
TA: Keith Kamons
Professor: James Feher


[View Project Log]
[View Github]
[View Preliminary Presentation]

Objectives and Goals

Build a module that can relay between an AC outlet and device that we want to control
Build a web interface that successfully communicates with the built module in at least a binary fashion
Set up a server to host the web interface


  • A majority of our programming expertise is in Java, and learning more about web development languages, especially Python, will be time consuming.
  • We have minimal background in hardware and circuitry, so a big challenge will be ensuring that we will account for all of the details necessary for our module.
  • We have no background in web security, so we need to be very careful in allowing access to the devices and files that we will be using.
  • We have never worked with Raspberry Pi before.
  • Linux is an unfamiliar operating system.


Total: -----needs to be updated ----

Useful Resources

RasPi Resources

GPIO Diagram
Blink Code

Temp Sensor Resources

132 Assignment (More Context)
Spec Sheet

DevOps and Server Side Resources

Websockets Tutorial

Project Results

Gantt Chart

Design and Solution


The website uses websockets to communicate with the raspberry pi hardware. The html buttons on the website will run a script on the pi to turn on/off the smart outlet.
Communicationflow.png Figure 1. Communication depicted between the AWS web interface and the user, the database with user data, and the pi module.
The websocket client-server connection in this project creates a handshake connection as an http request from the EC2 instance to the running server script on the RasPi. It is essential to the project to establish a connection through some sort of method between the Raspberry Pi and the web interface because we needed two way communication to display information from sensors on the Pi on the website as well as be able to control the outlet's status (on/off) from buttons on the website. Websockets were a good way of creating this connection because it established easy connection between the Javascript incorporated into the website and the Python server script running on the Pi. Potential problems: Not all browsers support websockets, but most of those in which they don't work are obsolete (see [Introduction to Websockets] for more specific information).
FSM.png Figure 2. Original plan for configuration of the website pages and link paths
On boot, the pi should run the server side websocket code(works on pi3 but not pi0, pi0 requires manual start, debugging). This starts the server that listens for emissions that are communicating with the IP address of the pi. The EC2 instance (continually running) connects to the server through a javascript script embedded in the website's html. This is kept track of by the Websocket Status shown at the bottom of the page. When connected, the client side (EC2) will send input from buttons on the page as messages to the pi, which interprets the incoming messages and converts them into instructions for its GPIO pins. 2-16-19Indexpage.png Figure 3. Rough design of website home page

Sensors & Hardware

Sensors to Transmit Data: We decided to add sensors to collect data that can be displayed on the main web page. For our project, we were only able to add a temperature and light sensor, but many more features could be added in the future as the MCP3008 that we used has 8 channels available total. We had to wire an AD converter into the Raspberry Pi because it does not have one built in. The AD converter reads a voltage from the device and runs voltage through a conversion equation in the code to output a meaningful value. The AD converter sends that signal to one of the I/O pins on the pi so that it can constantly be reading a stream of data which we can display on the website.

Below is our program for converting values. Inside the for loop is our equation for converting voltage to temperature. For the photo-resistor, we decided to leave the values read from the ADC and tested a range of what values were considered bright or dark.

  1. Main program loop.

while True:

   # Read all the ADC channel values in a list.
   values = [0]*2
   for i in range(2):
       # The read_adc function will get the value of the specified channel (0-7).
       if i==1:
           millivolts = mcp.read_adc(i)*(3300/1024)
           temp_C = ((millivolts-500.0)/10.0)
           temp_F = (temp_C*9.0/5.0)+32
           temp_C = "%.1f" % temp_C
           temp_F = "%1.f" % temp_F
           values[i] = temp_F
           values[i] = mcp.read_adc(i)

Power Supply and Relay: Our device plugs directly into the wall, however a typical outlet supplies 120 volts. The Raspberry Pi can only handle 5 volts at a time so we had to include a relay to the module in order to separate the pi from the wall outlet voltage unless the device needs to be turned on. A signal is sent from our pi to tell the relay when to flip the switch closed and allow mains voltage to turn the module on and supply wall voltage to the outlets on the front plate for any device to be plugged into. We also decided to add a small LED beside the outlets that automatically turns on when the relay closes so that the user can always know when the outlets have power even if nothing is plugged in.

Results and Solution


Goals: Create a working website that allows us to interact remotely with a physical device consisting of a relay, raspberry pi, and sensors to be able to turn a connected outlet on and off, with a timing setting.

Actual: The website is able to interact remotely with the physical device and turn the outlet on and off. The server script works pretty consistently to open a websocket connection between the pi and website, and the website is hosted publicly as of right now so that anyone with the QR code or link have access to the outlet.

Problems: The server script on the pi zero does not turn on automatically on boot. Next steps would be to get crontab working so that both the IP Address emailer for the pi (currently have a smtp problem with accessing gmail, although curiously the emailer works on boot when the pi is attached to an HDMI cable) and the automatic server start work. This could be solved in several ways. First, because websockets can be created in a way that allows you to send messages knowing only the server IP address, whether or not the RasPi IP address is consistent, it can be sent as a variable to the EC2 acting as a server to be used to connect to the Pi's server script. This would be helpful if we use this device in an environment like WashU where the wifi makes the IP address of the Pi inconsistent, so the script can be changed dynamically. Otherwise, we can continue to use the email system and change the scripts only when necessary, which might be easier in a more stable internet environment. This would require debugging the gmail bug, which would allow us to obtain the email on boot - there may also be a crontab problem, because the server script is not running on boot.


Goals: Build a module that can contain the pi and its power supply, relay, ADC and other sensors as well as be safely wired to mains voltage.

Actual: A module that contains the pi 0, relay, ADC and sensors, and has two outlet plugs available for safe usage.

Problems: We were only able to have one electrical outlet on the box due to spacing issues inside when we had originally envisioned having four plugs available. Also, there was not enough room in the box itself to contain the power supply for the pi so we had to have a separate external battery. A next step would be to that entirely self contained so there is no need to plug into anything externally but a wall outlet. However, the box was built successfully and safely, and all the components work the way they should.

Next Steps

  • Create a database of users that would improve security so that people don't have access to each others' outlets (password protected)
  • Fix the crontab commands
  • Add different features
    • Outlets on timers (allow setting lights to come on at night, or if we have a motion sensor and there's no signal after 5 min, etc.)
    • Outlets changing status depending on sensor input (turn outlet off if it's indicated as a light outlet above a certain brightness, use temp sensor to turn on fan outlet above a certain temp, etc.)
    • Outlets with different statuses (light outlets, fan outlets, etc. as demonstrated in above examples)