Using the Raspberry to use a local emonCms server (with Debian packages)
The main advantages of hosting our own emonCms server is that we own our data (better privacy, backup…). Furthermore you can also configure it to send also the data to a remote server.
Basically we use the Raspberry PI SD card to boot and use an external USB hard drive to host the complete file system. We use an external hard drive because SD cards have limited write cycles. To do that, to be sure to have enough power using the USB hard drive, we use a self-powered hub.
Here is the additional equipment we used :
Connect all the equipments. Here is how we did it :
2 Install emonCms using debian packages
We chose to install emonCms using Debian packages because even if it's less straightforward it is easier to update it in the future.
2.1 Prepare the file system
The idea is to install the file system on the external hard drive and to use the SD card only to boot.
Plug in this SD card to your computer and check which device was assigned to it and write it on an SD card (4 Go) :
sudo fdisk -l
Copy the image to the SD card :
sudo dd if=2014-01-07-wheezy-raspbian.img of=/dev/sdX
where /dev/sdX is the device corresponding to your SD card.
Connect the USB drive to your computer and using a tool like gparted
create a partition (ext4
type). We chose a size of 16 GB
Plug in the SD card to your Raspberry Pi and switch it on.
Connect over ssh to your Raspberry Pi (password is raspberry
by default) :
Plug in the USB hard drive to the hub connected to the Raspberry.
sudo fdisk -l
You should have an output like this :
/dev/mmcblk0p1 corresponds to the boot partition and /dev/mmcblk0p2 corresponds to the root partition (on the SD card).
/dev/sda1 is the partition of the USB hard drive that we created above and that will be used as a file system for the Raspberry.
So that the Raspberry uses the USB hard drive as a file system we will copy the root partition on the SD card to the hard drive :
sudo dd if=/dev/mmcblk0p2 of=/dev/sda1 bs=4M
Check the file system :
sudo e2fsck -f /dev/sda1
Extend the partition to the maximal capacity :
sudo resize2fs /dev/sda1
Now we will indicate to the Raspberry to use the new partition on the hard drive
Mount the USB disk :
sudo mount /dev/sda1 /mnt
and replace this line :
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
/dev/sda1 / ext4 defaults,noatime 0 1
Unmount the USB disk :
sudo umount /dev/sda1
and replace :
Reboot, connect to your Raspberry over ssh and execute :
sudo df -h
You should get an output like this :
Here we can see that the root partition (/) has a 16 GB size.
Update the system :
sudo aptitude update && sudo aptitude safe-upgrade
Configure local date/time :
sudo dpkg-reconfigure tzdata
2.2 Install emonCms
This is the documentation to install emonCms 8.1.2.
2.2.1 Install emonCms packages
To install emonCms we used debian packages and we followed this documentation.
Add the emonCms repository :
sudo sh -c "echo 'deb http://emon-repo.s3.amazonaws.com wheezy unstable' >> /etc/apt/sources.list"
Update the system and install the packages :
sudo apt-get update && sudo apt-get -y --force-yes install emoncms
The Debian package manager will ask you a series of questions to configure emonCms. These are used to generate a valid settings.php file for the installation. Please note that database user without password is not supported.
emonCms will be installed in /usr/share/emoncms/www
2.2.2 Install redis and swift mailer modules
2.2.3 Install rfm12pi module
This is required if you want values collected by the Raspberry Pi to be published on emonCms.
sudo aptitude install emoncms-module-rfm12pi
2.2.4 Enable Apache2 site and modules
sudo a2ensite emoncms
sudo a2enmod rewrite
2.2.5 Remove references to the Pi's UART (ttyAMA0)
, remove references to ttyAMA0
. Before it looked like :
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda1 rootfstype=ext4 elevator=deadline rootwait
After it should look like :
dwc_otg.lpm_enable=0 console=tty1 root=/dev/sda1 rootfstype=ext4 elevator=deadline rootwait
, remove also references to ttyAMA0
by commenting out this line :
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
2.2.6 Configure emonCms
Make sure the date/time is right. By default the Raspbian uses the ntp
protocol for clock synchronization.
In your browser go to this address : http://<RASPBERRY_IP>/emoncms
Click on the register link and create a new user.
Login using this new user.
Click on the “admin” menu (link on the top right) and update the database.
Click on the “Raspberry Pi” menu (link on the top left) :
You should see the message : “RFM12 to Pi interface script is up and running”
Set the right frequency (depending on the model you bought).
Set the network group : 210.
If you want to replicate your data on the emonCms.org server then you have to create an account on it, get the API
key and add it here.
Here is what you should get :
Click on the “input” menu, you should see all the data coming from the sensors.
2.2.7 Install additional modules
With this module you can receive an email if for example a sensor reaches a given value (e.g. if the temperature is higher than…).
With this module you can get a notification if a sensor is inactive.