1. What you need
- A Raspberry Pi
- A Current Cost Meter
- A RJ45 to USB converter cable
2. Setting Up the Raspberry Pi
Install the latest version of the Rasbian image onto a suitable SD card, insert into the Pi, connect to a network and boot-up.
If you need help follow the instructions here at the Raspberry Pi website.
3. Get the necessary software packages
With the Pi connected to a network with Internet access run the following commands (some may take a while and you may have to confirm with a “yes”):
sudo apt-get update sudo apt-get upgrade sudo apt-get install lighttpd rrdtool sudo apt-get install python3-dev python3-numpy
This installs all of the necessary packages we need.
4. Download and Install PySerial
PySerial is used to communicate with Serial Ports (here a USB port) and handle receiving the data from the Current Cost Display.
To download PySerial do the following (as the user pi , with a home directory of /home/pi)
cd ~ ; mkdir pyserial cd pyserial
On the Pi start a graphical display (startx) open the Midori Browser and navigate to https://pypi.python.org/pypi/pyserial
Download the latest version of PySerial (was 2.6 in May 2013) and save it into the pyserial directory you created earlier.
Either at the command prompt, or in a Terminal Window:
cd ~ cd pyserial tar -xvpf./pyserial-2.6.tar.gz # check the file name is correct cd pyserial2.6 # dir name = version downloaded sudo python setup.py install # this installs pyserial
5. Add the user Pi to the dialout group
To be authorized to use the USB port the user Pi has to be a member of the Linux group called “dialout” to make this so, enter:
sudo usermod -a -G dialout pi
6. Download the web-site files, lighttpd config files, RRD and Python scripts.
Go to the following URL on GitHub https://github.com/naylogj/powermon.git and download the powermon.tar file and save in the home directory of the user Pi (i.e. in /home/pi).
This will unpack several subdirectories.
7. Setting up the webserver/website
The next step is to install the web site files in /var/www and setup the lighttpd configuration.
At this point think of a user id (not Pi !) and password for accessing the website.
Edit the light.user file, and copy the config files.
cd /home/Pi/currentcost/lighthttpd nano light.user # edit the file (see below)** and save. sudo cp light.user /etc/lighttpd/light.user sudo cp lighttpd.conf /etc/lighttpd/lighttpd.conf
**Replace user:password with your-user-id:your-password and save it again.
Install the web site files by:
sudo chown -R pi /var/www sudo chgrp -R www-data /var/www sudo usermod -G www-data pi cp -rp /home/pi/currentcost/www/* /var/www cd /var sudo chgrp -R www-data ./www sudo chmod -R 760 ./www cd ~ sudo /etc/init.d/lighttpd restart
The last command will restart the webserver.
If you open a web browswer and point it at the IP address of your Raspberry Pi (e.g. http://192.168.x.y) then the front page of the web-site should appear. If you click on a link, you should get challanged to enter the user id and password you specified above.
8. Creating the RRD store
This is the file that stores all of the data recieved from the Current Cost Meter. To create this do:
cd /home/pi/currentcost/setup ./rrdcreate.sh
9. Installing the Powermon service and crontab entries
To install the powermon service (which automatically starts the data collection python script at bootup) do the following:
cd /home/pi/currentcost/init sudo cp powermon /etc/init.d/powermon sudo update-rc.d powermon defaults
To install the automatic (cron) jobs to update the graphs do the following:
cd /home/pi/currentcost/setup crontab -e # go to the bottom of the # comments and read in (CTRL+R in nano) # the pi_crontab file # save the file (accept the offered file name) # check this has worked by running crontab -l
10. Start the data collection service get_data_rrd.py
To start the data collection service issue the following command:
sudo /etc/init.d/powermon start
You should now be collecting data .. wait 10 minutes and check your website.