Existing Raspberry Pi SD card upgrade guide (ADVANCED)

I've been working on the upgrade path for upgrading from: emonSD-13-03-15.img.zip and emonSD-13-08-14.img.zip SD card images (that we have been shipping out for almost a year with the standard raspberrypi and rfm12pi adapter board and are available on the ready to go image page here https://github.com/emoncms/emoncms/blob/low-write/docs/setup.md) - to the latest version of the low-write branch and the new features developed for the emonpi such as the in-browser emonhub.conf editor, the wifi config, nodes module and app module. 

This forum post is the advanced step by step process to go through to upgrade an existing installation, I will try and package this up into an upgrade script next.

There is more information on the new features available in these forums posts:

emonPi and RFM69Pi emonbase ready-to-go SD card image
http://openenergymonitor.org/emon/node/10729

Using Emonpi features in v8.5
http://openenergymonitor.org/emon/node/10732

This was tested with the emonSD-13-08-14.img.zip image with the local install of emoncms enabled and logging data. Many of the feature may be useful such as the in-browser emonhub.conf editor whether your logging locally or not, but most of the benefits of upgrading are for installations where data is being logged locally on the raspberrypi.

Upgrade procedure

Start by SSH'ing into your raspberrypi, i.e ssh pi@IPADDRESS (password:raspberry). Then place your raspberrypi in write mode with command: rpi-rw.

The variant of emonhub used on the emonpi that makes use of MQTT and the new emoncms nodes module requires an update to the rfm12pi firmware to work, it needs received RF data to be printed with OK at the start of each line. To update the firmware a couple of pieces of software need to be installed. But before that you may need to make some more space on the SD card. You can skip this step if you have a larger SD card or dont want to upgrade the firmware or use the emon-pi variant of emonhub.

Around 400Mb can be free'd by deleting: wolfram-engine, sonic-pi and scratch

sudo apt-get purge -y wolfram-engine sonic-pi scratch
sudo apt-get autoremove -y
sudo apt-get clean

 

1) Upgrading emoncms and installing new modules

The latest version of the low-write branch and the new modules brings:

  • An in-browser emonhub.conf editor and emonhub.log viewer
  • The new apps module with mysolar and mysolar&wind dashboards in addition to myelectric.
  • In browser wifi config
  • New nodes module for use with emon-pi variant of emonhub (see below)
  • Improvements to the feed engines that make it possible to use accumulating watt hour or kwh feeds for generating daily data graphs and improved data viewer and csv export.

Start by stopping emonhub and feedwriter so that no data is written during the upgrade:

sudo service emonhub stop
sudo service feedwriter stop

Keep a backup of the existing emoncms installation before installing the new one:

mkdir /home/pi/backup
mv /var/www/emoncms /home/pi/backup/emoncms

Install new low-write emoncms and modules:

cd /var/www
git clone -b low-write https://github.com/emoncms/emoncms.git
cp /var/www/emoncms/default.settings.php /var/www/emoncms/settings.php
cd /var/www/emoncms/Modules
git clone https://github.com/emoncms/nodes.git
git clone https://github.com/emoncms/app.git
git clone https://github.com/emoncms/config.git
git clone https://github.com/emoncms/wifi.git

redis-cli “flushall”

Create a emoncms.conf file for use with the nodes module:

sudo touch /home/pi/data/emoncms.conf
sudo chown pi:www-data /home/pi/data/emoncms.conf
sudo chmod 664 /home/pi/data/emoncms.conf

Update the emoncms database by logging in to emoncms and running database update and check.

At this point if you want to restart emonhub and feedwriter and test that everything is still running as normal inputs being received and data being stored in feeds you can do this with:

sudo service emonhub start
sudo service feedwriter start
 

2) Installing requirements for updating RFMPi firmware

The new RFMPi firmware standardises the message format to include the OK at the from of the data received over RF.

git clone https://github.com/openenergymonitor/avrdude-rpi.git ~/avrdude-rpi && ~/avrdude-rpi/install
sudo apt-get install arduino -y
sudo apt-get install python-pip -y
pip install ino
git clone https://github.com/openenergymonitor/RFM2Pi.git

To update the firmware the steps are then:

sudo service emonhub stop
cd RFM2Pi
./update-RFM12

The new firmware should work fine with the existing installation of emonhub on the raspberrypi which is the development branch.

 

3) Switching to the emon-pi variant of emonhub

(The emon-pi variant of emonhub needs the firmware upgrade in step 2 to work)

The emon-pi variant of emonhub is a variant that I adapted from Paul Burnell's experimental branch (which may in time be superseded by another version of emonhub that Paul is currently working on), it sends the node data to the local emoncms via MQTT rather than HTTP requests, although it can send by HTTP too if configured, it can also receive node data via MQTT to be sent out over the RFM network for control applications.

To upgrade to the emon-pi variant you may want to start by making a backup of the existing emonhub directory:

mv /home/pi/emonhub /home/pi/backup/emonhub
sudo mv /boot/emonhub.conf /home/pi/backup

Installation of the emonhub emon-pi variant:

sudo service emonhub stop
cd
git clone https://github.com/openenergymonitor/emonhub.git && emonhub/install
sudo cp /home/pi/emonhub/conf/emonhub-blanknodes.conf /home/pi/data/emonhub.conf
sudo chown pi:www-data /home/pi/data/emonhub.conf
sudo chmod 664 /home/pi/data/emonhub.conf

Install emoncms-nodes-service to subscribe to MQTT messages published by the emon-pi variant of emonhub:

sudo cp /var/www/emoncms/Modules/nodes/emoncms-nodes-service /etc/init.d/
sudo chmod 755 /etc/init.d/emoncms-nodes-service
sudo update-rc.d emoncms-nodes-service defaults

Start services:

sudo service emonhub start
sudo service emoncms-nodes-service start
sudo service feedwriter start

Configure new emonhub.conf

To get existing inputs and feeds up and running again you will need to reconfigure emonhub.conf this can now be done from the in-browser editor by logging in to emoncms and clicking on the EmonHub tab.

If you wish to keep using existing inputs rather than use the new nodes module change the entry:

[[emoncmsorg]]
    Type = EmonHubEmoncmsHTTPInterfacer
    [[[init_settings]]]
    [[[runtimesettings]]]
        pubchannels = ToRFM12,
        subchannels = ToEmonCMS,
        url = http://emoncms.org
        apikey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        senddata = 1
        sendstatus = 1

to point to:

        url = http://localhost/emoncms
        apikey = write api key
        senddata = 1
        sendstatus = 0

or make a copy of this entry with a different interfacer name [[emoncmsorg]] & [[localemoncms]] if you wish to record data locally and send data to a remote install of emoncms,

If you made any custom node definitions these will also need to be re-entered but with the new [[[rx]]], [[[tx]]] tags as in the example here: http://openenergymonitor.org/emon/node/10732

That completes most of the upgrade to the latest raspberrypi software stack being used on the emonpi and soon to be the standard image for emonbase rfm12/69pi adapter board SD cards too.

There are a few more steps to get the wifi config up and running and the in browser system update tool. But the above covers the main parts of upgrading the emonhub/emoncms part while keeping existing data feeds and configurations.

craigfryer's picture

Re: Existing Raspberry Pi SD card upgrade guide (ADVANCED)

Thanks for this useful guide.

Just a few comments.

The command redis-cli “flushall” had problems when I cut and pasted as the quotation marks were the wrong character, it should be redis-cli "flushall".

The Update the emoncms database needs to be a little clearer.

  1. sudo service emonhub start
  2. sudo service feedwriter start
  3. Log in to emoncms via a browser
  4. Go to Admin section, then click on "Update & Check"

After the "pip install ino" command I received the following message:
error: could not create '/usr/local/lib/python2.7/dist-package/ino' Permission denied
It didn't appear to cause a problem, but it was unexpected.

craigfryer's picture

Re: Existing Raspberry Pi SD card upgrade guide (ADVANCED)

Is it still recommended to migrate to the emon-pi variant of emonhub?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.