Setting up an IoT base station using Raspberry PI and EmonCMS

If you are playing around with Internet-of-Things at home, some of the most central components are a base station of some kind and a way to present the data collected by the things – besides the actual things, of course.

In certain cases the base station will also host the presentation layer and thus all the data collected, but in most cases the base station merely acts as a proxy between protocols, e.g. a wireless protocol for receiving measures from the IoT nodes and, e.g., MQTT to send the measures to a remote presentation layer (other options are available, but MQTT seems like the way to go).

There are several options for the presentation layer, but not all of them are available for local installation and thus cannot be used directly on the base station. One of the most commonly used is EmonCMS from the Open Energy Monitor Project, which can either be installed locally or used in a shared cloud environment. Among other cloud options is BlueMix, which is a comprehensive commercial cloud platform with many ready-to-use features for Internet-of-Things.

In this article series I will address how to set up a base station using a Raspberry PI with RFM interface for receiving data wirelessly from IoT nodes, a presentation layer in the form of EmonCMS, as part of the EmonBase operating system, and a flow-control layer based on Node-Red. I will top this off with steps required to secure the web communication for EmonCMS and Node-Red.

The following articles are planned for this series, possibly with more to come:

  1. Introduction and initial setup of Raspberry PI and EmonBase (this article)
  2. Enabling SSL for EmonCMS
  3. Installing Node-Red as an intermediate layer between RFM interface and EmonCMS
  4. Securing Node-Red

Note: This guide was originally written for an older release of EmonHub, but has been updated to reflect the new releases as of May 27. 2015. In the future only new releases will be covered!

This is the first article in this series, in which I will explain how to get started with the Raspberry PI, the EmonBase OS and EmonCMS.


The hardware required for utilising the full flow of EmonCMS on the Raspberry PI is – beside a RPI, naturally – the RFM12PI (or the newer RFM69PI) expansion board for the Raspberry. The expansion board hosts an RFM module that is capable of receiving data wirelessly from other RFM modules (e.g. sensor around your house). It also enables the Raspberry to send commands to the sensors, if they support it and are equipped to take action.

I will not cover any sensors here but – obviously – the setup described here is not worth much without at least one sensor transmitting data to the Raspberry PI. Have a look at the TinyTX3 or EmonHT sensor nodes for inspiration.

The complete list of required hardware is

Most of the hardware you can get from anywhere, but the RFM69PI is sold (and developed) only by the Open Energy Monitor Project.

Once you have all the necessary hardware you can assemble it – the RFM12/69PI attaches to the GPIO pins of the RPI. Do not plug in the SD-card just yet – it needs to visit another computer first. Read on for how to install EmonBase to the SD-card.


EmonBase is the name of the Linux distribution for Raspberry PI that combines EmonHub and EmonCMS, and is maintained and distributed by the Open Energy Monitor Project.

EmonBase is distributed in a special low-write edition made especially for running on SD-cards and provides a read-only file system and write buffering to optimise any required disk activity.

It is easily installed by following the installation guide at the EmonCMS Github page, which is the first thing to do to set up the base station.

After finishing the installation, you can plug the SD-card in to the RPI and power it up. You should make sure to connect it to the internet, either via cable or WiFi (WiFi setup is not covered here).

Once booted, you can access it using ssh or directly if you have attached a screen and keyboard (there is no need for a mouse because there is no desktop environment in EmonBase).

One of the first things that it is a good idea to do on new systems is to make sure that they are up-to-date. This, however, requires making changes to files on the disk and thus – because the EmonBase installed is a special low-write version – the disk is write protected by default. This is to prevent the disk from filling up with log files and, more importantly, to extend the life of the SD-card which has a limited read/write cycle count depending on the make and model. In order to write-enable the disk, issue the following command at the console:


Now you can write changes to the disk, but so can all running processes, so make sure to have this enabled for as short periods of time as possible, otherwise the disk will fill up with logs. To re-enable write protection issue the following command:


Now, with the write protection disabled, the system can be updated with the latest package by issuing the following commands at the prompt:

sudo apt-get update
sudo apt-get upgrade

With the system up-to-date, it is a good idea to expand the root partition to use the entire capacity of the SD-card (only about 2GB is initially allocated).

The EmonBase distribution has a tool (raspi-config), which can expand the root partition to use the entire space of the SD-card, but unfortunately this tool requires the root partition to be the last partition in the partition table and EmonBase is set up with a data partition following the root partition, so the tool will not work.

You can either accept the fact that you will have limited available space or you can go look for resources that explains other ways of resizing a partition without such strict requirements.

Most use cases for EmonHub does not require a graphical user interface, such as Gnome, and the Raspberry PI running EmonHub is seldom connected to a screen. Thus, some resources can be gained by changing the amount of memory allocated for the GPU to the least possible amount. You can do this using the raspi-config tool:

sudo raspi-config

Select Advanced Options and Memory Split, and enter 16 in the input field:

Minimising memory allocated to the GPU
Minimising memory allocated to the GPU

When done, select OK and Finish, and select Yes when prompted for a reboot.

Configure EmonHub

Now that everything is assembled and EmonBase is installed to the SD-card it must be configured to make sure that it can receive data from the nodes using the RFM12/69PI.

First, the serial port must be made available for EmonHub, so the default getty link should be removed. Do this by editing inittab (Newer releases of EmonHub comes with this preconfigured):

sudo nano /etc/inittab

and comment out the last line, so it reads (note the initial hash character):

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

This is not all; there is also a binding in cmdlines.txt that must be removed, so save the inittab by entering <Ctrl>+o followed by <Ctrl>+x and then open cmdlines.txt for editing:

sudo nano /boot/cmdlines.txt

Replace the content of the file with the following(Newer releases of EmonHub comes with this preconfigured):

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Save and close the file, as just done with inittab.

It is necessary to reboot the RPI for these changes to take effect and the serial port to be free for use by EmonHub, so do a reboot and log in to a console whe the system is up again.

Now EmonHub can be configured to talk with the RFM12/69PI, so open the EmonHub configuration file for editing:

sudo nano /boot/emonhub.conf

and find the section interfacers.

Note that on newer releases of EmonHub the configuration file has moved to /home/pi/data/emonhub.conf.

Here, make sure that the section contains the following interface:

    Type = EmonHubJeeInterfacer
        com_port = /dev/ttyAMA0
        com_baud = 38400
        group = 210
        frequency = 433
        baseid = 15

The values shown above are the defaults for the RFM12PI. They can be the same for RFM69PI, but com_baud should be changed to 57600 if running the RFM69PI in compatibility mode (for use with RFM12B-based nodes).

Beware that newer releases of EmonHub comes with a number of nodes preconfigured in the configuration file. If you are not using any of the original nodes from the Open Energy Monitor Project it is recommended to comment out all preconfigured nodes.

Save and exit by entering <Ctrl>-o followed by <Ctrl>-x.

This article is concentrated around running everything locally, so EmonHub will be configured to post data to the local installation of EmonCMS. This requires additional configuration of EmonHub, which, if you are running an older release of EmonHub, fortunately can be done simply by running a ready-made script:


If, however, you are running a newer release, everything is already set up for you, except for the configuration of the reporter, which must be done anyway.

You should now be able to access EmonCMS by steering your browser to


substituting <RPI_IP_ADDRESS> with the IP address of the Raspberry PI.

The first time you visit your local EmonCMS installation you will need to create a user by clicking Register on the login page. Once registered and logged in you should take note of the write API key, which will be used configure the reporter (called interfacer in newer releases) for reporting to the local EmonBase.

Again, edit the EmonHub configuration file and create a new reporter – make a copy of the existing one named emonCMS or emoncmsorg. Once copied, rename it to something unique and meaningful, e.g. emoncmslocal. Then change the url entry to http://localhost/emoncms and put in the write API key that you got from your profile page in EmonCMS.

Finally, if you are using a newer release of EmonHub, disable the remote reporting to by setting the senddata and sendstatus values to 0 (zero) for the emoncmsorg interfacer.

Save the changes and restart EmonHub and Apache:

sudo service emonhub restart
sudo service apache2 restart


Now you should have a Raspberry PI capable of receiving data wirelessly using the RFM12/69 interface and presenting the data as measures using EmonCMS. Of course you must set up the presentation layer to show the received measures just the way you like it and to get any measures you need to set up one or more nodes to send data to the base station.

On top of that, the base station should be set up to last as long as possible, using the specific hardware that you have chosen for it, because of the low-write, data buffering and read-only file system.

5 comments on “Setting up an IoT base station using Raspberry PI and EmonCMSAdd yours →

  1. Great start – keep up the good work

    I have been running EmonCMS v6 for a couple of years on a RPi and am now making the switch to the newer low write versions as I have now had one too many SD cards die (obviously just before I was meaning to do a local backup!).

    I had been looking at running node red on this too and your planned articles are just what I was looking for. Will you be covering using node red to post direct to

    Many thanks

    1. Hi Gary,

      Thanks for stopping by!

      Sorry to hear about your crash. The low-write version seems quite robust – I have not had a crash yet and have been running on the same SD-card for about a couple of years now.

      In general the article series is based on the setup that I am using, which does not post data to, but it should be very easy to configure Node-Red to forward to rather than a local EmonCMS installation. Basically, I use the EmonCMS node, which can be configured for both (using the EmonCMS ReST API rather than MQTT).

      I am close to finishing the article about installing Node-Red and integrating it into the flow.

      Good luck with your IoT projects!


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: