This is a guide to setting up a power monitoring system using Brultech GEM, ECM-1240, or ECM-1220 devices.
btmon.py
is a Python script that collects data from Brultech devices then saves the data or uploads the data to online power monitoring services. btmon uses little memory or processing power, so it is well-suited to running on devices such as routers or plug computers. Since it is pure Python it will run on just about anything that has Python, including MacOSX, Windows, Linux.
btcfg.py
is a Python script that will query and modify the configuration of Brultech devices. This can be useful when there is no windows computer available to run Brultech's IA software (for ECM devices) or Java available to run Green-Eye Monitor Setup (for GEM devices).
--help
option for a list of all options
--debug
option for more details about what btmon is doing
--skip-upload
with the --debug
option to see what would be uploaded without actually uploading
btmon is compatible with many online services. See the comments in btmon.py for details about how to create accounts and configure each online service.
Installing btmon:
General RecommendationsConfiguring the GEM or ECM:
Debian Linux
Windows
How to configure the GEMConfiguration Notes:
How to configure the ECM
How to configure network settings
PolarityExample Configurations:
Real-Time Mode
Client and Server Modes
Polling versus Blocking
Multiplexing
Run btmon on a router
Run btmon on Windows
Save to RRD from serial ECM-1240
Upload to Smart Energy Groups from ethernet GEM
Save to MySQL from serial GEM
Collect data from multiple GEM via TCP/IP with btmon in server mode
Collect data from multiple ECM via serial
Collect data from multiple ECM via serial with polling
Run multiple instances of btmon
btmon.py is a single Python script, so installation consists of downloading the script to your computer. It is good practice to put the script into a separate folder since there probably will be a configuration file to go with the script. btcfg.py can be placed in the same folder as btmon. btcfg.py will be useful if the GEM/ECM configuration tools from Brultech will not run (e.g. no Java or no Windows).
Of course, Python must be installed. MacOSX and most flavors of linux come with Python. Python is very easy to install on Windows.
Additional Python modules may be required. For example, if the Brultech device is connected via serial, the Python serial module will be required. If saving to a MySQL database is desired, then the Python MySQLdb module must be installed.
The approach to installing Python modules varies. For example, on Redhat systems one would use yum install python-serial
, on Debian systems one would use apt-get install python-serial
, and on many systems one could use Python's built-in installer easy_install pyserial
.
sudo apt-get install python2.6
mkdir btmon cp Downloads/btmon.py btmon
That's it! Depending on the configuration, you might have to install other Python modules. If btmon complains about a missing module, install that module using apt-get.
http://python.org/download/windows
mkdir c:\btmon copy Downloads\btmon.py c:\btmon
That's it! Depending on the configuration, you might have to install other Python modules. If btmon complains about a missing module, install that module using easy_install.
The examples in this guide require setting the real-time mode, send interval, and packet format.
There are three tools for configuring a GEM:
The GEM has many settings, such as real-time mode, per-channel type and range, polarity, etc. See the Brultech documentation for details about all of the configuration options.
The examples in this guide require setting the real-time mode and send interval.
There are two tools for configuring an ECM:
The ECM has many settings, such as real-time mode, channel polarity, etc. See the Brultech documentation for details about all of the configuration options.
Some GEM have a built-in serial-to-ethernet device. Any ECM can be connected to a serial-to-ethernet device as well. Typically this is a WizNET or similar that converts the GEM serial to TCP/IP. Some devices convert serial to wired ethernet, others convert serial to wireless ethernet.
The serial-to-ethernet device has a number of parameters, including:
There are a number of tools available to configure the serial-to-ethernet device. These can be downloaded from the device vendor or from Brultech. For example, WIZnet makes the source available for their configuration tool, so it is available on multiple platforms:
The examples in this guide require setting the client/server mode, IP address, and port.
Two channels on the ECM-1240 and 32 channels on the GEM count not just power, but also power direction. Each channel has two counters. The absolute counter increments when power flows. The polarized counter increments when power flows in one direction, but not in the other. The polarity of the channel indicates whether the power should be considered positive or negative.
There are many ways to configure the polarity.
--reverse-polarity
option to btmonbtmon interprets the polarized counter differently than the GreenEyeMonitor setup tool. btmon interprets an increase to the polarized counter as 'positive' energy. GreenEyeMonitor interprets an increase to the polarized counter as 'negative' energy. As a result, the polarity reported by btmon will be the inverse of the polarity reported by GreenEyeMonitor.
Use the --reverse-polarity
option to make the polarity reported by btmon match the polarity reported by GreenEyeMonitor and other Brultech tools.
GEM and ECM-1240 devices have a real-time mode. When in real-time mode, the device emits packets at a regular interval. When the device is not in real-time mode it will not emit a packet until a packet is requested.
When configuring a GEM/ECM, first ensure that the device is not in real-time mode. If the device is in real-time mode when configuration commands are sent, the real-time packets can interfere with communications.
When communicating via TCP/IP, the GEM/ECM can be in either client or server mode. When the GEM/ECM is in server mode, it responds to requests - the computer running btmon must initiate the request for communication. When the GEM/ECM is in client mode, the GEM/ECM initiates the communication.
Server mode is typical for most installations. Client mode is useful when a firewall is betwen the GEM/ECM and the computer on which btmon is running, or when there are multiple GEM and a single instance of btmon.
The --ip-mode option to btmon specifies the mode for btmon, not the GEM/ECM. So if the GEM/ECM is in server mode, btmon should be in client mode.
btmon.py --device-type=gem --ip --ip-mode=client --ip-host=192.168.X.Y --ip-port=5000
btmon.py --device-type=gem --ip --ip-mode=server --ip-port 6000
Technically it is the serial-to-ethernet hardware (e.g. WizNET) that has client/server modes - the GEM/ECM communicates via serial with the WizNET, and the WizNET communicates with other devices via TCP/IP.
btmon can either accept real-time packets from the GEM/ECM (the GEM/ECM must be in real-time mode) or it can poll for data (the GEM/ECM must *not* be in real-time mode).
The polling mode is useful if there are multiple computers that need to communicate with a single GEM/ECM. In most cases btmon should be in blocking mode, accepting real-time packets from the GEM/ECM.
Polling is specified with the --serial-poll-interval=X
(for serial connections) or --ip-poll-interval=X
(for TCP/IP connections) option.
Multiple GEM/ECM can share a single serial connection. For example, up to 4 ECM-1240 can be connected to one serial port, or multiple GEM can be connected to a single WizNET.
Although multiplexing is possible, it is not encouraged. When devices are multiplexed they are prone to cause contention - the result is packet loss. Instead of reliably receiving a packet every 10 seconds, the data collector may experience periods of multiple minutes where no data are received.
btmon cannot communicate with multiple device types on a single connection. For example, if a GEM and ECM-1240 are both connect to a single WizNET, btmon can collect from one or the other but not both. If the GEM emits ECM binary packets then btmon can collect from both devices, but this configuration is not encouraged.
When polling multiplexed devices, a list of one or more device identifiers must be specified. The identifiers for the ECM-1240 are 0xfc, 0xfd, 0xfe, or 0xff. The identifier for the GEM is the serial number.
This example shows how to run btmon on an ASUS router with Tomato USB, collecting data from a Green-Eye Monitor attached via ethernet and uploading data to COSM (pachube).
Hardware: ASUS N16 router
Software: Tomato USB v1.28 with optware
btmon.py --ip --ip-mode=client --ip-host=X.X.X.X --ip-port=5000 --print
[source] device_type = gem ip_read = true ip_host = X.X.X.X ip_port = 5000 ip_mode = client [pachube] pachube_out = true pbe_token = ZZZZZ pbe_feed = YYYYY
btmon.py -c config.cfg
This example shows how to run btmon on Windows, collecting data from an ECM-1240 attached by serial to COM1 and uploading data to emoncms.
- Python 2.7
- http://python.org/download/windows
- pyserial (for reading from serial port)
- http://sourceforge.net/projects/pyserial/files/pyserial
mkdir c:/Program Files/btmon/bin copy btmon-x.y.z.py c:/Program Files/btmon/bin/btmon.py
btmon.py --serial --serial-port=COM1 --print
[source] serial_read = true serial_port = COM1 [oem] oem_out = false oem_url=http://emoncms.org/input/post oem_token = XXXXXX
btmon.py -c config.cfg
This example shows how to run btmon on a Linux system, collecting data from an ECM-1240 attached by USB-serial adapter to /dev/ttyUSB0 and saving to RRD files on local disk.
btmon.py --serial --serial-port=/dev/ttyUSB0 --print
[source] device_type = ecm1240 serial_read = true serial_port = /dev/ttyUSB0 [rrd] rrd_out = true rrd_dir = /var/rrd
btmon.py -c config.cfg
This example shows how to run btmon, collecting data from a Green-Eye Monitor attached by ethernet and uploading data to Smart Energy Groups.
btmon.py --device-type=gem --ip --ip-mode=client --ip-host=X.X.X.X --ip-port=5000 --print
[source] device_type = gem ip_read = true ip_host = X.X.X.X ip_port = 5000 ip_mode = client [seg] smartenergygroups_out = true seg_upload_period = 180 seg_token = XXXXXXX
btmon.py -c config.cfg
This example shows how to run btmon, collecting data from a Green-Eye Monitor attached by USB-serial adapter to /dev/ttyUSB0 and saving to local MySQL database.
btmon.py --device-type=gem --serial --serial-port=/dev/ttyUSB0 --print
# mysql -u root -p mysql> create user gemuser identified by 'gempass'; mysql> grant usage on gem.* to gemuser@localhost identified by 'gempass'; mysql> grant all privileges on gem.* to gemuser@localhost;
[source] device_type = gem serial_read = true serial_port = /dev/ttyUSB0 [mysql] mysql_out = true mysql_user = gemuser mysql_passwd = gempass mysql_database = gem
btmon.py -c config.cfg
This example shows how to run btmon in server mode, collecting data from two Green-Eye Monitors via TCP/IP. In this example, btmon runs on a computer with IP address 192.168.X.Y.
btmon.py --device-type=gem --ip --ip-mode=server --ip-port=2000 --print
[source] device_type = gem ip_read = true ip_port = 2000 ip_mode = server
btmon.py -c config.cfg
This example shows how to run btmon, collecting data from two ECM-1240 via a single serial.
btmon.py --device-type=ecm1240 --serial --serial-port=/dev/ttyUSB0 --print
[source] device_type = ecm1240 serial_read = true serial_port = /dev/ttyUSB0
btmon.py -c config.cfg
This example shows how to run btmon, collecting data from two ECM-1240 via a single serial using polling.
btmon.py --device-type=ecm1240 --serial --serial-port=/dev/ttyUSB0 --serial-poll-interval=30 --device-list=fc --print
btmon.py --device-type=ecm1240 --serial --serial-port=/dev/ttyUSB0 --serial-poll-interval=30 --device-list=fd --print
btmon.py --device-type=ecm1240 --serial --serial-port=/dev/ttyUSB0 --serial-poll-interval=30 --device-list=fc,fd --print
[source] device_type = ecm1240 serial_read = true serial_port = /dev/ttyUSB0 serial_poll_interval = 30 device_list = fc,fd
btmon.py -c config.cfg
This example shows how to run two instances of btmon. The first instance collects data from a GEM and saves data to a local sqlite database. The second instance collects data from the database and uploads to Smart Energy Groups, OpenEnergyMonitor, and COSM.
First configure the collect instance:
btmon.py --device-type=gem --ip --ip-mode=client --ip-port=5000 --print
btmon.py --device-type=gem --ip --ip-mode=client --ip-port=5000 --sqlite
[source] device_type = gem ip_read = true ip_port = 5000 [sqlite] sqlite_out = true
btmon.py -c collect.cfg
Configure and test the Smart Energy Groups upload:
btmon.py --device-type=gem --sqlite-src --smartenergygroups-out --seg-token=SEG_TOKEN
Configure and test the Open Energy Monitor upload:
btmon.py --device-type=gem --sqlite-src --oem-out --oem-token=OEM_TOKEN
Configure and test the COSM upload:
btmon.py --device-type=gem --sqlite-src --pachube-out --pbe-token=COSM_TOKEN
When testing the uploads, it might help to specify the --debug
option.
Put it all together:
[source] device_type = gem sqlite_read = true [seg] smartenergygroups_out = true seg_token = SEG_TOKEN [oem] oem_out = true oem_token = OEM_TOKEN [cosm] pachube_out = true pbe_token = COSM_TOKEN
btmon.py -c upload.cfg
Copyright © Matthew Wall, all rights reserved
$Id: btmon-howto.html 540 2013-03-06 14:21:45Z mwall $
Last modified: