Page 1 of 1

Raspberry Pi BTMon.py Setup Guide

Posted: Fri Jun 24, 2016 11:38 am
by ben
BTMon.py Raspberry Pi Setup Guide

Updates:
2016-06-24: created initial guide.


This guide assumes a Raspberry Pi or other system is already setup and running EmonCMS. If you haven't previously setup a system, please start with the guide below.

viewtopic.php?f=40&t=1567

Required downloads

- PuTTy or equivalent SSH program http://www.chiark.greenend.org.uk/~sgtatham/putty/.


Installing BTMon

Steps:
NOTE: You may copy and paste the command line information from this guide into PuTTy.


1. Go to your home folder.

Code: Select all

cd /home/pi
2. Download the latest version of BTMon.

Code: Select all

sudo wget https://raw.githubusercontent.com/matthewwall/mtools/master/bin/btmon.py
3. Create a configuration file for BTMon, replace TOKEN with the API Key copied above and the NODE_NAME with whatever you want it labelled as. In this example, we'll be using BTMon in Server mode. Change device_type to ecm1240 is using an ECM-1240 and not a GEM.

Energy Monitor running as TCP Client

a. Copy/paste the following code. Change ip_port to whatever port the GEM is configured to send to.

Code: Select all

printf "[source]\ndevice_type = gem\nip_read = true\nip_port = 8000\nip_mode = server\n[oem]\noem_out = true\noem_token = TOKEN\noem_url = http://localhost/emoncms/input/post.json\noem_node = NODE_NAME" > btmon.cfg
Energy Monitor using Serial-to-USB Cable

a. Download and install PySerial (this link may change, if below doesn't work check https://pypi.python.org/pypi/pyserial for a new link and replace the string following wget).

Code: Select all

wget https://pypi.python.org/packages/3c/d8/a9fa247ca60b02b3bebbd61766b4f321393b57b13c53b18f6f62cf172c08/pyserial-3.1.1.tar.gz#md5=2f72100de3e410b36d575e12e82e9d27
sudo tar xvf pyserial-3.1.1.tar.gz
cd pyserial-3.1.1
sudo python setup.py install
cd ..
sudo rm -R pyserial*
b. Plug in the Serial-to-USB cable and find out how it's been assigned.

Code: Select all

dmesg | grep -Eio "ttyUSB[0-9]+"
c. Take the value from above and run the command below, replace "ttyUSB#" with the value found above. Change serial baud to 19200 if using an ECM-1240.

Code: Select all

printf "[source]\ndevice_type = gem\nserial_read = true\nserial_port = /dev/ttyUSB#\nserial_baud = 115200\n[oem]\noem_out = true\noem_token = TOKEN\noem_url = http://localhost/emoncms/input/post.json\noem_node = NODE_NAME" > btmon.cfg
4. Start BTMon to test.

Code: Select all

sudo python btmon.py -c btmon.cfg --debug
Starting on boot

Steps
1. Run the following command.

Code: Select all

sudo sed -i 's:exit 0:python /home/pi/btmon\.py -c /home/pi/btmon\.cfg \&\nexit 0:' /etc/rc.local

Re: Raspberry Pi BTMon.py Setup Guide

Posted: Sun Jul 10, 2016 2:52 pm
by rora002
Hi Ben,

Thanks for your guide here. It has been very helpful. I have managed to get btmon.py running, and uploading data to emoncms.org.

I have set up btmon.py to start on boot, and so far this works fine for an hour, then stops. Is a log stored for the script somewhere that can help me find out what is going wrong?

Thanks,
Rob

Re: Raspberry Pi BTMon.py Setup Guide

Posted: Mon Jul 11, 2016 8:16 am
by mwall
rora002 wrote: I have set up btmon.py to start on boot, and so far this works fine for an hour, then stops. Is a log stored for the script somewhere that can help me find out what is going wrong?
rob,

is btmon still running?

run btmon in debug mode and dump the output to file:

Code: Select all

sudo /home/pi/btmon.py -c /home/pi/btmon.cfg --debug > /var/tmp/btmon-out.txt
then you can look at the output to diagnose any problems.

m

Re: Raspberry Pi BTMon.py Setup Guide

Posted: Sun Jun 25, 2017 10:08 am
by Automan
I need more help trying to use my ECM-1240

I think Emoncms may have changed where it locates files or again it may just be being silly :)

I have the Emoncms webpage on my pi loading but it says

The log file has no write permissions or does not exists. To fix, log-on on shell and do:
touch /var/log/emoncms.log
chmod 666 /var/log/emoncms.log



Edit: Solution easy, if one has a brain :)

Just run the two commands with sudo in front so they are run with root user privleges

sudo touch /var/log/emoncms.log
sudo chmod 666 /var/log/emoncms.log

Re: Raspberry Pi BTMon.py Setup Guide

Posted: Sun Jun 25, 2017 3:57 pm
by Automan
Made some more progress...

In this thread it has

a. Copy/paste the following code. Change ip_port to whatever port the GEM is configured to send to.
Code:
printf "[source]\ndevice_type = gem\nip_read = true\nip_port = 8000\nip_mode = server\n[oem]\noem_out = true\noem_token = TOKEN\noem_url = http://localhost/emoncms/input/post.json\noem_node = NODE_NAME" > btmon.cfg

Then later

c. Take the value from above and run the command below, replace "ttyUSB#" with the value found above. Change serial baud to 19200 if using an ECM-1240.
Code:
printf "[source]\ndevice_type = gem\nserial_read = true\nserial_port = /dev/ttyUSB#\nserial_baud = 115200\n[oem]\noem_out = true\noem_token = TOKEN\noem_url = http://localhost/emoncms/input/post.json\noem_node = NODE_NAME" > btmon.cfg

So the first btmon.cfg is deleted and replaced by the later one with some of the information missing.

Merged the two together and it sort of works.