Difference between revisions of "Nest Model"

From ESE205 Wiki
Jump to navigation Jump to search
m (Protected "Nest Model" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
 
(42 intermediate revisions by 2 users not shown)
Line 11: Line 11:
 
[[https://classes.engineering.wustl.edu/ese205/core/index.php?title=Nest_Model_Log View Project Log]]<br>
 
[[https://classes.engineering.wustl.edu/ese205/core/index.php?title=Nest_Model_Log View Project Log]]<br>
 
[[https://github.com/ESE205/nest-model View Github]]<br>
 
[[https://github.com/ESE205/nest-model View Github]]<br>
[[https://docs.google.com/presentation/d/1_IsuZnEumobEa8rsyQlTz5eNDzsU0gBrtKkOBxEbRbE/edit?usp=sharing View Preliminary Presentation]]
+
[[https://docs.google.com/presentation/d/1_IsuZnEumobEa8rsyQlTz5eNDzsU0gBrtKkOBxEbRbE/edit?usp=sharing View Preliminary Presentation]]<br>
 +
[[https://classes.engineering.wustl.edu/ese205/core/index.php?title=Websockets Tutorial]]<br>
 +
[[https://docs.google.com/presentation/d/1H0JmwNLXyh9OyK6Ur5o5aX-A8gYnp-j3Xey6sHiex3A/edit?usp=sharing Poster]]
  
 
== Objectives and Goals ==
 
== Objectives and Goals ==
Line 33: Line 35:
 
* AC Duplex Outlet - $0.43
 
* AC Duplex Outlet - $0.43
 
* Module box - $27.44
 
* Module box - $27.44
* MCP 3008 - $3.75
+
* [https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf MCP 3008 - $3.75]
* [https://www.analog.com/media/en/technical-documentation/data-sheets/TMP35_36_37.pdf TPM Gz36 - $1.50]
+
* [https://www.analog.com/media/en/technical-documentation/data-sheets/TMP35_36_37.pdf TMP 36Gz - $1.50]
 
* SD card - provided ($4.99)
 
* SD card - provided ($4.99)
 
* Component (fan) - $16.99
 
* Component (fan) - $16.99
 
* Cable - $6
 
* Cable - $6
 +
* Outlet Covers - $14.44
 
Total: -----needs to be updated ----
 
Total: -----needs to be updated ----
  
Line 49: Line 52:
 
==== DevOps and Server Side Resources ====
 
==== DevOps and Server Side Resources ====
 
[https://websockets.readthedocs.io/en/stable/intro.html Websockets Tutorial]<br>
 
[https://websockets.readthedocs.io/en/stable/intro.html Websockets Tutorial]<br>
 +
 +
==== Project Results ====
 +
<gallery>
 +
Nest-model-QR.png | Website QR Code
 +
</gallery>
  
 
== Gantt Chart ==
 
== Gantt Chart ==
Line 54: Line 62:
 
[[Media:GanttChart2-16.png]]<br>
 
[[Media:GanttChart2-16.png]]<br>
  
== Design Solution ==  
+
== Design and Solution ==  
Design and Solutions
 
  
Website:
+
==== Website ====
 +
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. <br>
 +
[[File: Communicationflow.png|400px]]
 +
Figure 1. Communication depicted between the AWS web interface and the user, the database with user data, and the pi module.<br>
 +
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 [[https://blog.teamtreehouse.com/an-introduction-to-websockets Introduction to Websockets]] for more specific information).<br>
 +
[[File: FSM.png|400px]]
 +
Figure 2. Original plan for configuration of the website pages and link paths<br>
 +
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.
 +
[[File: 2-16-19Indexpage.png|400px]]
 +
Figure 3. Rough design of website home page <br>
  
[[Media:2-16-19Indexpage.png ‎]]
+
==== Sensors & Hardware ====
Figure 1. Rough design of website home page
+
<br>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.
  
[[Media:]]
+
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.
Figure 2. Communication depicted between the AWS web interface and the user, the database with user data, and the pi module.
 
  
[[Media:FSM.png]]
 
Figure 3. Configuration of the website pages and link paths
 
  
//TODO: Explain what the website does<br>
+
# Main program loop.
==== Web Interface ====
+
while True:
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.
+
    # 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
 +
        else:
 +
            values[i] = mcp.read_adc(i)
  
==== Sensors & Hardware ====
+
<gallery>
<br>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. 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 outputs a meaningful value.  
+
Wiring.jpg|Pi3 with ADC and sensors in a breadboard
*insert fritz diagram of MCP3008 and sensors/pi*
+
</gallery>
 +
 
 +
<br>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.
 +
 
 +
<gallery>
 +
Relay_diagram_picture.png | Schematic diagram of relay wiring to pi0
 +
</gallery>
 +
 
 +
<gallery>
 +
Diagram of system.png|Overall diagram of connectivity in module
 +
</gallery>
 +
 
 +
== Results and Solution ==
 +
[[File: OutletTest.mp4 | 400px]]
 +
==== Software ====
 +
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.
  
<br>Power Supply: 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. *need to add explanation about how the relay works*
+
==== Hardware ====
 +
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. <br>
  
*insert relay circuit diagram*
+
Actual: A module that contains the pi 0, relay, ADC and sensors, and has two outlet plugs available for safe usage. <br>
  
 +
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)
  
 
[[Category:Projects]]
 
[[Category:Projects]]
 
[[Category:Spring 2019 Projects]]
 
[[Category:Spring 2019 Projects]]

Latest revision as of 14:43, 4 May 2019

Overview

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

Links

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

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

Challenges

  • 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.


Budget

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

https://docs.google.com/spreadsheets/d/10Ftzdzjh8UOGXznYvhBb2OvnZ2Exib2vUMbfKiH339s/edit?usp=sharing
Media:GanttChart2-16.png

Design and Solution

Website

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
       else:
           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

Software

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.

Hardware

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)