Projects

Check out some of our past and ongoing work


Laboratory Inspections



Want to Replicate our Set-up?


What you'll need

  1. Laptop for datalogging
  2. Router of at least 2.4 GHz
  3. Wemo Insight Smart Plug(s) F7C029. Buy them here

Prior Set-up

  1. Install Linux VM-Ware
  2. Set up a wireless network with a wifi router (Wemos are only 2.4 GHz)
  3. Set up Wemo to connect with your wifi router, and download the Wemo App See Document

Installing the data logging code

    The next step is to install the necessary packages and code on the data logging laptop. Note that we will be using the command line for this process, as well as for running the program later on. If you are new to using the command line, it is a worthwhile investment to get acquainted with the basics. There are several tutorials online for this, such as code academy . If you ever encounter any bugs or confusion along the process, remember that the internet is a great resource. It is likely that someone else has encountered similar issues before, and often times a quick Google search will resolve the problem.

    Our script for data logging is written in Python 2, so the first thing we should do is make sure that Python 2 is installed in the data logging laptop. An easy way to check this is by typing python2 --version in the command line. If Python 2 is installed, you should get an output such as Python 2.7.14 .

    If you do not get a similar output, then you should install Python. A useful resource for this is python-guide .

    After making sure Python 2 is installed, the next step is to make sure you also have pip installed. This is an essential tool that makes it easy to install other packages. For information on this, click here

    Next, we install some packages that are generally useful for developing software:
    sudo apt-get install python-setuptools python-dev
    Presumably, you might have several different projects on the same laptop (if not now, then possibly in the future). Each project might require slightly different configurations, and it can get tricky to make sure they don’t mess up each other’s settings. For example, suppose you need version 10 or later of hypothetical_package for a project, but another project is only compatible with versions 9 or below. This is problematic, since their requirements interfere with one another! The solution to this type of problem is to work with virtual environments, which allow you to install packages in such a way that they don’t interfere with one another. We will be using virutalenvwrapper. To set it up, run the following commands sequentially:

     pip install virtualenv
    sudo pip install virtualenvwrapper
    Export WORKON_HOME=~/Envs
    Source /usr/local/bin/virtualenvwrapper.sh
    

    You might find the following references useful: this and this

    Now, we are able to create a virtual environment for our data logging purposes. You can choose to name it whatever you would like, but here we use the name ‘wemo’. We do so with this command: mkvirtualenv wemo . You should notice that the command line prompt now starts with (wemo) to indicate that you are working inside the virtual environment you just created. If you wish to work outside this environment, you can exit with the command deactivate On the other hand, if you would like to return to the virtual environment, you can do so by typing workon wemo

    For the rest of the process, you should be working in the virtual environment you created for this project.

    Wemos are originally designed to be used with their commercial app, but we can control them with our Python code by using the appropriate Application Programming Interface (API). We will be using the Ouimeaux Python API for Wemo. Documentation for it can be found here . Let’s go ahead and install it by typing in terminal:
     pip install ouimeaux
    pip install ouimeaux[server]
    
    Next, we (finally!) download the LEAC scripts for data logging. We do so using git: git clone https://github.com/leac-mit/green_net After running this command, you should have a folder, green_net, containing our code files.

    Congrats! Now you should have all the necessary software!

    Running the code

    The script you will be running to log data is wemo_logging.py, and it can be run from terminal. Assuming you are inside the green_net/src directory (folder), it can be run with the command:
    python wemo_logging.py 10

    Note that the number 10 above is arbitrary, and should be replaced with the amount of wemos that you intend to use to log data. If any errors occur, it is possible that some of the required packages weren’t properly installed, in which case we encourage you to do a Google search based on the error messages you receive.

    When the code is run, the first thing it will do is try to detect and communicate with all wemos in the network. After about a minute, it should output a message indicating whether this process was successful, or otherwise the number of wemos it failed to detect. It will also initialize a file in which it will record all the observed data, which are power measurements taken every 5 seconds. The file is titled data.csv, and it is inside the green_net/src/data directory.

    Once you would like to stop collecting data and terminate the data logging script, you can execute the following command:exit.sh

    You should be able to find the collected data in the data.csv file mentioned previously, in a format of the form:

    Date (in datetime format), time interval between measurements (in seconds), P_1, P_2, …, P_n

    Where P_i indicates the power measurement in Watts for the appliance connected to Wemo i. An example with actual numbers:

    20170412-12:10:00, 5.00537919998, 340, 590, 42610, 205
    20170412-12:10:05, 5.00529003143, 345, 570, 41890, 185
    20170412-12:10:10, 5.10275387764, 340, 520, 42270, 200

    Where the above data indicates the measured values for 4 Wemos, at 3 different times. You can also check the data while the code is running by way of the following command:cat data.csv

    This will output the data stored thus far into the command line, allowing you to verify that the data is being collected successfully, without having to terminate the code to check. Often times, you will notice some of the columns filled with 0s, which usually means that the corresponding Wemo(s) are not successfully initialized, and are providing the default value of 0 instead of actually measuring the power consumption.

    Understanding and modifying wemo_logging.py

    You might be wondering why we made certain choices for the numerical constants in our code. For instance, why record data every 5 seconds, and not some other arbitrary amount of time? It might depend on your application, and it is ideal for the user to tweak it for their particular use. This can be achieved by changing the value of the LOG_FREQ variable at the top of the WemoLogger class.

    The overall structure of the code might be confusing to decipher at first, depending on your background with Python and object-oriented programming. For the most part, it shouldn’t be necessary to modify its structure.

    If you encounter any bugs with our code, or if there is any part of the process for which this guide was confusing, please do not hesitate to contact us!