- Raspberry pi - any generation will do, RPI Zero with GPIO would suffice.
- A current cost Envi or Envir Smart Meter
- And old ethernet patch cord
- Some method to connect wires to the GPIO pins on the pi (solder, caps, bread-board or nothing at all)
- contrary to a lot of information you do not need a USB to serial adapter or a current cost data cable
No need to download yet
- https://gitlab.com/lalelunet/measureit or my fork https://github.com/HarvsG/measureit
- https://forum.pvoutput.org/t/guide-for-currentcost-envir-on-pi-with-pvoutput-intergration-service/871
- https://groups.google.com/forum/#!topic/measureit/xzt-RjCxc8Y
- https://forum.pvoutput.org/c/energy-monitors/currentcost
- https://code.google.com/archive/p/pvccupload/downloads
Taken from this tutorial
-
Cut the ethernet cable in half, leaving a reasonable length on each end.
-
Strip wires 1 and 4 (solid brown and solid blue for me).
RJ45 pins are numbered on the male connector end-on from left to right with the plastic latch pointing UP
-
Using any preferred method connect the Wire 1 (brown) from the ethernet to the Serial Rx pin for my pi, this was physical pin 10.
-
Connect wire 4 (blue) to any of the ground pins
-
Plug the other end (the RJ45) into the currentcost.
-
Now on a pi with a Rasberry Pi OS install the pi run
sudo raspi-config
-
Select
5 Interfacing Options
, then selectP6 Serial
. -
Disable 'login over serial' and enable the hardware serial
-
Restart you pi with
sudo shutdown -r now
-
Soon aftere boot run
dmesg | grep tt
-
Look for a line like
[ 1.049107] 20201000.serial: ttyAMA0 at MMIO 0x20201000 (irq = 81, base_baud = 0) is a PL011 rev2
make a note ofttyAMA0
or whatever it is for you- This is our serial device from the GPIO, we will continue to use it on this tutorial.
-
cd ~
thensudo nano serial_read.py
and paste in:
#!/usr/bin/env python
# note that this is a python 2 script
import time
import serial
import sys
if sys.version_info >= (3,0):
print("Sorry, the rest of this tutorial requires Python 2.x, not Python 3.x")
print("You ran this script with version: " + str(sys.version_info))
sys.exit(1)
ser = serial.Serial(
port='/dev/ttyAMA0', #you will need to change this if you got different results in 11
baudrate = 57600, #for some earlier CurrentCost devices this was 9600
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=3
)
while 1:
x=ser.readline()
print x
sudo apt install python-pip -y && sudo pip install pyserial
sudo python serial_read.py
wait a good 30seconds and see if any xml rolls in- If it does, your serial device is working, otherwise the rest will not work
- If you see a python version error then it is because your device is running python3 as it's default
python
command, this will likely cause problems later on. - A possible, but untested workaround would be after step 2 below to edit https://github.com/HarvsG/measureit/blob/master/measureit_system_files/install/svc-run-measureit#L3 and change
/usr/bin/python
to wherever python2 is intalled. e.g/usr/bin/python2
- confirm the installs will work by running them manually before the script does
sudo apt-get update && apt-get install -y git vim daemontools-run php7.3-fpm php7.3-mysql nginx samba samba-common-bin python-mysqldb python-serial python-setuptools
cd /home/pi
,git clone git://github.com/HarvsG/measureit.git
- Run the install script with
sudo /home/pi/measureit/measureit_system_files/install/install-measureit-image.sh
- If the device name found in step 11 above is anything other than
ttyAMA0
orttyUSB0
then: -sudo nano /web/measureit/measureit_system_files/python/data-input.py
changettyAMA0
to whatever you found above. - Navigate to the webpage (the IP of the raspberry pi) and enter your settings.
- first step is to open the inspector and switch to the log page - look out for 500 server errors, which indicates changes have not been made.
- set your PVoutput data in the system settings.
- Then if your sensor has multiple clamps, add each of these, usually 3
- for each of the clamps and sensor go to their settings page and fill in each box, you can leave the
PVOutput API Key:
blank as you have set it in system settings, - For the
PVOutput System ID:
set the clamps to0
and the sensor to your pv output ID e.g45567
. - For the timezone as far as I can tell measureit will use the raspberry pi's GMT/UTC and ignore any DST so you need to specify any offset from UTC here. You will also need to update it if DST changes
- Navigate to the IP of the pi in your browser, settings and click
grabber restart
. - When you navigate to the IP address of your pi you should see the KW usage updating regularly, and PV output updating
Also see here
- most errors seem to be in database quieries, turn on logging with
sudo mysql
,SET GLOBAL general_log_file = '/var/run/mysqld/mysqld.log';
,SET GLOBAL general_log = 'ON';
andsudo tail -f /var/run/mysqld/mysqld.log
although this won't show errors you can copy and paste the queries (via a text editor, removing indents) to the mysql terminal and see what happens - remember to
SET GLOBAL general_log = 'OFF';
when you are done sudo tail -f /tmp/measureit.log
show the output of the python grabbersudo svc -d /service/measureit
,sudo /usr/bin/python /web/measureit/measureit_system_files/python/data-input.py debug
will provide a more verbose output to the log file, (and will print the xml rolling in).sudo svc -u /service/measureit
to restart the normal grabber service when you are finished.
-
sudo apt update && sudo apt upgrade -y
-
sudo apt install apache2 mariadb-server git python-mysqldb python-serial python-setuptools
-
sudo python /usr/lib/python2.7/dist-packages/easy_install.py pip
,sudo pip install twython==2.7.0 requests requests_oauthlib
-
sudo bash
,mkdir /var/www
,mkdir /var/www/measureit
-
cd /var/www/measureit
,git clone git://github.com/lalelunet/measureit.git .
include the.
-
cd /var/www/measureit/measureit_system_files/install
,sudo service mysql start
,cat createdb.sql | mysql -uroot -p
You will be asked for a password, easiest to give the login password of your pi
-
Exit
exit
-
Now type the local IP address of your pi into a browser on another device, in my case
192.168.1.100
, you should see the apache 'It works!' page -
sudo nano /etc/apache2/sites-available/000-default.conf
change
DocumentRoot /var/www/html
toDocumentRoot /var/www/measureit/measureit_public_html/
-
sudo service apache2 restart
-
sudo mkdir -p /package
,sudo chmod 1755 /package
,sudo wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
-
sudo tar xvzf daemontools-0.76.tar.gz
,cd admin/daemontools-0.76/src
,sudo perl -pi -le 's/extern int errno;/#include <errno.h>/' *.[hc]
-
sudo ../package/install
,sudo mkdir /etc/servers
,sudo mkdir /etc/servers/measureit
-
sudo cp -R /var/www/measureit/measureit_system_files/install/svc-run-measureit /etc/servers/measureit/run
,chmod +x /etc/servers/measureit/run
-
cd /service
,sudo ln -s ../etc/servers/measureit
This was the old plan but is mostly redudant
Pin pairings on RS232 Serial port connector. Pins are numbered as you look at the male connector end on with the row of 5 on top. Transmit/recieve are from the perspective of the PC, not the Current cost unit.
9-pin | pin definition Direction (PC view) |
---|---|
1 | DCD (Data Carrier Detect) input |
2 | RX (Receive Data) input |
3 | TX (Transmit Data) output |
4 | DTR (Data Terminal Ready) output |
5 | GND (Signal Ground) - |
6 | DSR (Data Set Ready) input |
7 | RTS (Request To Send) output |
8 | CTS (Clear To Send) input |
9 | RI (Ring Indicator) input |
RJ45 Pinout for serial connection to the CurrentCost Envi. RJ45 pins are numbered on the male connector end-on from left to right with the plastic latch pointing UP. The colours may not be reliable.
Pin | Colour | Definition |
---|---|---|
4 | Blue | Ground |
2 | Brown/white | Current cost recieve |
1 | Brown | Current cost Transmit |
So pin pairings will be:
RJ45 pin | RS232 pin |
---|---|
1 (Tx) | 2 (Rx) |
5 (GND) | 5 (GND) |
2 (Rx) | 3 (Tx) |
The final pairing is probably uneccessary as some have said that the Envi is transmit only. However according to the Current Cost website, depending on the unit firmware, it may store some historical data. Presumably this would require some send information.
- https://swinders.co.uk/raspberrypi-home-energy-monitor/
- https://electrosome.com/pl2303-usb-to-uart-converter/
- https://web.archive.org/web/20080906120557/http://www.spaaace.com/cope/?p=106
- https://web.archive.org/web/20080820225044/http://e.inste.in/2008/06/15/interfacing-the-currentcost-meter-to-your-pc/
- https://www.flickr.com/photos/pixelfrenzy/2499443217/
- https://web.archive.org/web/20170604143001/http://81624.de/wiki.81624.de/doku.php?id=measureit:install
- https://dalelane.co.uk/blog/?p=456