I assembled my Moteino circuit inside the KillAWatt. Everything fits very nicely and the LED blinks every ~2 seconds, and data finds its way to my RaspberryPi where EmonCMS records and graphs it nicely. At the last minute I found a leftover TMP36 analog temperature sensor that I had around, and thought – why not add it to the Moteino and report temperature along with power readings?
WARNING: If you attempt this project, make sure you never work on your KillAWatt while it is plugged in! It is a shock hazard and you should never connect anything to it (including an oscilloscope that is not galvanically isolated from mains). You should never try to connect the Moteino/circuit to your computer to read serial from it while inside the KAW! I mean this, the KAW might not work at all, or you will cause some damage to your tools or yourself!
I feared the TMP36 sensor alone would draw too much power (even an extra constant 2mA is too much for my KAW!). But it turns out it’s a very low power sensor (just 0.05mA). Since Adafruit has a very nice demo and code for TMP36, I won’t replicate the details here, you can check them out at Adafruit’s learning system.
Now I’m getting temperature, voltage and current waveform readings from my KAW. Sweet! Some assembly photos:
For a first run, I let my WattMote report my refrigerator power overnight. The KAW was reading 1.19kWh when I checked the next day, in EmonCMS it was showing 1.18kWh, I think I’m happy with this accuracy:
Here is the schematic of a WattMote node:
How does it all work?
The receiving end of the WattMote network is a Moteino that you can attach to a regular computer (boring…) or to a RaspberryPi (oh yeah). In my case I’m using a RaspberryPi with a python script that runs as a long running process (that lives after logoff). The script posts the incoming data to the EMONCMS instance running on the Pi. See details at their site on how to install EMONCMS.
The python script has a bunch of options which you can learn about by invoking the help command (python WattMote.py -h). You will need to either edit the script with your default settings or provide them through the command line. For the script to run properly you will need to tell it what to do and what not, and supply information such as the EMOCMS apiKey. Since not all KillAWatts are the same, you may tweak the incoming voltage/current data by altering these 2 parameters in the WattMote.py file:
CURRENTNORM = 15.8 # conversion to amperes from ADC
VOLTAGENORM = 0.94 # multiply each volt sample by this
On the RaspberryPi, you will connect the receiver (gateway) Moteino using 4 pins:
- Pin2(5V) to Moteino-VIN
- Pin6(GROUND) to Moteino-GND
- Pin8(UART_TXD) to Moteino-RX
- Pin10(UART_RXD) to Moteino-TX.
Then, if you haven’t done this yet, you will need to free your serial port. The serial port by default is used by a getty process which allows you to log into your RPi using the hardware serial interface (kinda cool). To disable that run these commands:
- Make backup first, then edit the original cmdline.txt file and remove parameters that contain “ttyAMA0″:
12sudo cp /boot/cmdline.txt /boot/cmdline_backup.txtsudo nano /boot/cmdline.txt
- Then comment out the line that spawns a getty on ttyAMA0:
12sudo nano /etc/inittab#2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
- Restart the Pi
1RESTART – sudo shutdown –r now
- To test the ttyAMA0 serial port, install minicom and run it. You should see the raw data coming from the WattMote(s):
12Sudo apt-get install minicomminicom -b 115200 -o -D /dev/
- At this point you should be able to start the WattMote.py script. To start it in long running process mode just add a ampersand at the end of the command.
1python WattMote.py &
- To later kill this script you can use “ps aux” to find the script’s ID, then kill it:
123ps aux | grep WattMote (or just ps aux to list all processes)pi 24036 2.0 3.1 11200 5892 ? S 16:34 0:08 python WattMote.pypi@raspberrypi ~ $ sudo kill 24036
See my GitHub WattMote repository on how to setup the Moteinos inside your KillAWatts as transmitting WattMotes, and how to flash your central receiving Moteino.
Some/all parts are now available in the LowPowerLab store.
UPDATE: See Mike T‘s fix video where he shows how to add more stability to the KAW when the mains voltage sags below 120V: