btmon on Lubuntu installation difficulties

Post any 3rd party software here.
Post Reply
sub3marathonman
Posts: 95
Joined: Fri Feb 11, 2011 9:32 am

btmon on Lubuntu installation difficulties

Post by sub3marathonman » Wed Dec 30, 2015 9:12 pm

I have decided to try to use emoncms with Lubuntu (15.10). I thought it would be relatively straightforward, as I previously have gotten emoncms working with Windows 8.

Things went fairly straightforward, following the emoncms installation instructions
https://github.com/emoncms/emoncms/blob ... Install.md
and watching the two youtube videos from Chris Walker for Ubuntu 12.04 (a bit outdated)
https://www.youtube.com/watch?v=lmftwvb56HQ
and Ubuntu 14.04
https://www.youtube.com/watch?v=K3k_q2hRaLU

I got things installed fine, and even was able to sign in to emoncms on localhost, which is how I was setting it up.

However, getting Python 2.7.10 and the btmon.py working correctly has proven difficult.

I got Python 2.7 installed fine, and from researching on the github website that mwall just set up
https://github.com/matthewwall/mtools
I also installed the python-mysqldb add-on.

I got the btmon.py 3.1.1 saved, had a bit of confusion trying to run btmon.py instead of just btmon, but I did get it working with the btmon -h command to see the help guide. I copied the btmon config.cfg file I had set up and working with the Windows 8 installation. I also copied the btcfg.py file and saved that too in the same directory.

I then did what seemed to be the logical step which was to do the command "btmon -c config.cfg" which was just the slight variation from the Windows 8 command "btmon.py -c config.cfg" which was working fine.

Now, what is interesting is the error states that the -c is an "invalid option," and it does not show up in the help guide. I don't know why it was necessary, or how I even found out it was necessary, but somehow I used the -c option with the Windows 8 version.

I've tried it without the -c option, and get the error "Invalid command line parameters."

I'm also not sure about the config.cfg file being correct with the Lubuntu 15.10, but it seems I cant test that file until I get past the -c option problem.

As a bit of further research, I have changed the command to "python ./btmon.py" and it does run the btmon script. However, adding the config.cfg in the command doesn't seem to have any effect on the btmon values.

With more attempts, I now have the command "python ./btmon.py -h" which does show the -c option, and have run the command "python ./btmon.py -c ./config.cfg" which does seem to have some effect, but then I get the error "unknown parameter in config file: Values instance has no attribute 'reverse_polarity'"

So any help will be greatly appreciated.
sjthespian
Posts: 10
Joined: Wed Sep 07, 2011 11:31 pm

Re: btmon on Lubuntu installation difficulties

Post by sjthespian » Wed Dec 30, 2015 10:37 pm

If it helps, here is the init script I use on my Ubuntu box. It gets installed in /etc/init.d/btmon. It is a slightly modified version of the one that comes with the mtools package (https://launchpad.net/ubuntu/trusty/+package/mtools). The easiest way to install btmon and the related tools is by using the packages.

Code: Select all

#!/bin/sh

### BEGIN INIT INFO
# Provides:		btmon
# Required-Start:	$syslog
# Required-Stop:	$syslog
# Should-Start:		$local_fs
# Should-Stop:		$local_fs
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Starts btmon
# Description:		btmon collects data from brultech energy monitor
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
APP=/opt/mtools/bin/btmon.py
CONFIG=/opt/mtools/etc/btmon.cfg
PIDFILE=/var/run/btmon.pid
LOGFILE=/var/log/btmon.log

set -e

case "$1" in
    start)
    echo -n "Starting btmon:"
    $APP --config-file=$CONFIG >> $LOGFILE 2>&1 &
    pid=$!
    echo $pid > $PIDFILE
    echo
    ;;

    stop)
    echo -n "Shutting down btmon:"
    if [ -f $PIDFILE ]; then
        kill `cat $PIDFILE`
        rm $PIDFILE
    fi
    echo
    ;;
    
    *)
    echo "Usage: $0 {start|stop}" >&2
    exit 1
    ;;
esac

exit 0
sub3marathonman
Posts: 95
Joined: Fri Feb 11, 2011 9:32 am

Re: btmon on Lubuntu installation difficulties

Post by sub3marathonman » Wed Dec 30, 2015 10:50 pm

sjthespian wrote:The easiest way to install btmon and the related tools is by using the packages.
Thank you for the help.

One problem is that I'm such a newbie that I'm not sure what or how you "use the packages" to install btmon. :oops: I also don't understand what the mtools package on launchpad does or how it relates to btmon.

And I thought I had done the installation properly, as I can get btmon to do something, but I'm now stuck on the config.cfg aspect. And it does seem that some of the parameters from the Windows 8 config.cfg file don't have documentation in the btmon.py -h guide. Also, it seems the parameters are now with a hyphen instead of an underscore, so I'm not sure if my old method will still work or if I have to change it to the hyphen.
sjthespian
Posts: 10
Joined: Wed Sep 07, 2011 11:31 pm

Re: btmon on Lubuntu installation difficulties

Post by sjthespian » Wed Dec 30, 2015 11:40 pm

Argh, ignore my comment about the package, that's not the right package.

I grabbed the full mtools tarball from github, you can get the most recent version from https://github.com/matthewwall/mtools.

Here's an example of my config file (with the hostnames changed to example.com), I'm running my GEM in server mode as I couldn't get client mode working properly. The OEM block is what feeds the output to emoncms.

Code: Select all

[source]
device_type = gem

serial_read = false
serial_port = COM1

ip_read = true

ip_host = gem.example.com
ip_port = 8000
ip_mode = client
ip_poll_interval = 10
reverse_polarity = true

mysql_read = false

sqlite_read = false

[mysql]
mysql_out = false

[sqlite]
sqlite_out = false

[rrd]
rrd_out = false

[wattzon]
wattzon_out = false

[plotwatt]
plotwatt_out = false

# enersave is deprecated - use bidgely instead
[enersave]
enersave_out = false
es_token = 

[bidgely]
bidgely_out = false
by_url = https://api.bidgely.com/v1/users/TOKEN/homes/1/gateways/1/upload

[peoplepower]
peoplepower_out = false

# the seg map is optional.  if not specified, every channel will be uploaded.
[smartenergygroups]
smartenergygroups_out = false

[thingspeak]
thingspeak_out = false
ts_tokens =
ts_fields =

[pachube]
pachube_out = false
pbe_token = 
pbe_feed =

[oem]
oem_out = true
oem_url = http://localhost/emoncms/input/post
oem_token = xxxxxxx
oem_node = 1

sub3marathonman
Posts: 95
Joined: Fri Feb 11, 2011 9:32 am

Re: btmon on Lubuntu installation difficulties

Post by sub3marathonman » Wed Dec 30, 2015 11:57 pm

sjthespian wrote:
Here's an example of my config file (with the hostnames changed to example.com), I'm running my GEM in server mode as I couldn't get client mode working properly. The OEM block is what feeds the output to emoncms.
Your help is greatly appreciated!

One interesting thing I immediately see is that you're doing reverse_polarity, which is at least one of the apparent problems with my attempts. I was thinking that maybe that parameter had been eliminated at some point.

I'll have to study this tomorrow.

Thanks again.
Post Reply