An adaptation of Watt-Lite Twist for [Energy in a Box at KomTek] 1. It allows users to choose an amount of watt-hours, measure how that amount is being used up by multiple devices and look how the usage is distributed between those devices.
Created at Interactive Institute in [Eskilstuna] 2.
An (e)lVis setup consists of a Python web server that streams power measurements and a JavaScript client. The client can run either in the web browser or in Node.
The web app has been tested in Chrome and Firefox. On Mac, it works better in Chrome.
The Node version runs on a Raspberry Pi.
There are three implementations: plugwise
, zwave
and fake
. The
zwave
and fake
implementations have been tested recently.
On a Raspberry Pi, run tools/install.sh
to make the Node implementation
work. Otherwise, just make sure you have python-serial
installed.
- Edit
config.py
to suit your needs. You may want to edit theSOURCE
variable to switch between implementations. - Run:
cd server && ./elvis_server.py
. - Either open
http://localhost:8000/app/index.html
in your web browser or runclient/client.js
using Node (~/node/0/bin/node
on RPi).
Using the web interface:
- When the twist to start message is spinning, use the ↑↓ arrow keys to set the amount of kWh to use.
- Connect and use devices on multiple sensor plugs.
- Look at the changing pie chart. Keep the space bar pressed to see another display mode.
At any time, the arrow keys can be used to start over with another amount of kWh.
In the Node interface, use a mouse wheel and mouse buttons instead.
sudo cp ~/git/elvis/tools/elvis /etc/init.d/elvis
sudo chmod 755 /etc/init.d/elvis
sudo update-rc.d elvis defaults
Kill it using sudo service wltl stop
.
All Python scripts are in server/
:
- The
energy_watch*
modules will collect and make available accumulated energy measured in the sensors. As long as the server runs, these values will increase. It is up to the client to reset set a zero value based on when the interaction starts. - In
util
thePublisher
class is defined that implements a small pubsub system. - The main program is in
elvis_server.py
and sets up a Tornado web server. This server serves three types of data:- The app in the
static/
directory. - The
CLIENT_CONFIG
config variable. - An EventSource stream with an array of energy values.
- The app in the
The most interesting JavaScript happens in static/
:
- The
App
class inapp.js
defines all drawing logic. - In
index.html
andmain.js
an HTML DOM environment is set up to work withApp
. - The alternative, static setup in
index_demo.html
can be used for showing a static demo, e.g. to take a picture.
The Node client is in client/client.js
. It provides a UI to static/app.js
.
Mouse events are gathered using udev in client/mouse.js
.
Use your browser’s Developer Tools to debug the interface. If you’re
confident that the sensor measurements work already, set SOURCE = 'fake'
in config.py
to speed things up.
Check the (real or fake) datastream using
curl http://localhost:8000/data
.