Close

Using SmartEE

A project log for SmartEE the Smart Plug

An Opensource Smart Plug

johnJohn 08/12/2015 at 21:150 Comments

SmartEE uses a simple text based protocol on port 1336. You can access it directly over telnet but the easiest way to integrate it into your project is to use the python module [plug.py]. This module encapsulates a plug object and provides direct methods to read data, erase the SD card, set the RGB LED, and of course turn on and off the relay. It can be directly incorporated into any Python project with minimal dependencies. You need [sockets] for TCP/IP communication, and [serial] for USB communication. There is currently a dependency on [numpy] for the data processing but this isn't strictly necessary. However, most projects manipulating power data will probably want numpy anyway.

[demo.py] facilitates shell scripting applications and to demonstrates the usage of [plug.py]. Running [demo.py] with the help flag shows the documentation and example commands:

usage: demo.py [-h] [--relay {on,off}] 
               [--read] [--usb] [--erase]
               [--file FILE] device

demo.py
    John Donnal 2015
    GPL v2 (see LICENSE)

    This demonstrates some of the capabilities of the SmartEE plug control board

    Usage:

    1.) Control plug relay:
        python demo.py --relay on  192.168.1.4
        python demo.py --relay off 192.168.1.4
    2.) Read meter over WiFi, appending to a 
        data file
          python demo.py --read 192.168.1.4
    3.) Download data over USB, appending 
        to a data file
          python demo.py --read --usb /dev/ttyACM0

    Data files created by this script are 
    CSV formatted with the following columns
 ts | vrms | irms | watts | pavg | pf | freq | kwh

    ts   | timestamp (UNIX milliseconds)
    vrms | RMS Voltage
    irms | RMS Current
    watts| Watts
    pavg | 30 second average of watts
    pf   | Power Factor
    freq | Line Frequency (Hz)
    kwh  | Energy used since plugged in (kWh)

-----------------------------------------------------

positional arguments:
  device            Device: either a /dev/NODE 
                            or an IPv4 address

optional arguments:
  -h, --help        show this help message and exit
  --relay {on,off}  Set relay state
  --read            request meter data
  --usb             plug connected by USB, 
                    specify device node, 
                    *not* IPv4 address
  --erase           erase data after reading 
  --file FILE       destination file for meter data

These files are in the [software] directory of the git repository. Check it out! - and of course if you have any questions please let me know!

Discussions