Skip to content

Commit

Permalink
RasPi docs update - low-write section reworked
Browse files Browse the repository at this point in the history
**CHANGELOG**
* default.settings.php - Edited to increase default sleep
period to 600 seconds
* default.settings.php - Edited to hide emonpi
update option for emonhub
* docs/RaspberryPi/general.md - New section
added to disable system logs
* docs/RaspberryPi/Low-write-mode.md - Add
tmpfs volumes, disable ext4 journaling, move php sessions to tmpfs.
*
docs/RaspberryPi/MQTT - Added info about comma-delimited values
*
docs/RaspberryPi/install_Raspbian_Jessie.md - Reworded following forum
comments
* docs/RaspberryPi/read.md - Reworded following forum
comments
* Renamed readme.md as install_Wheezy.md
* Renamed
install_Raspbian_Jessie.md as read.md (making Jessie the current default
OS)
**Notes;**
At stages in the guides, I've recommended powering
down the Pi and restarting, as against calling a reboot, to avoid
errors.
The results obtained by following the guide for both Jessie &
Wheezy were 0.05kB/s, compared with over 7kB/s for a standard v9
install.
  • Loading branch information
Paul-Reed committed Dec 9, 2015
1 parent 3aa217e commit 9361146
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 73 deletions.
4 changes: 2 additions & 2 deletions default.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// Redis Low-write mode
'redisbuffer'=>array(
'enabled' => false // If enabled is true, requires redis enabled and feedwriter service running
,'sleep' => 60 // Number of seconds to wait before write buffer to disk - user selectable option
,'sleep' => 600 // Number of seconds to wait before write buffer to disk - user selectable option
),

'csvdownloadlimit_mb' => 10, // Max csv download size in MB
Expand Down Expand Up @@ -121,7 +121,7 @@
$log_filename = dirname(__FILE__).'/' . 'emoncms.log';

// If installed on Emonpi, allow update from admin menu
$allow_emonpi_update = true;
$allow_emonpi_update = false;

//experimental feature for virtual feeds average, default is true, set to false to activate average agregation with all data points, will be slower
$data_sampling = false;
Expand Down
68 changes: 62 additions & 6 deletions docs/RaspberryPi/Low-write-mode.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,67 @@
##Enabling Low-write mode
Due to the number of writes that the full version of emoncms makes, the lifespan of an SD card will almost certainly be shortened. and it is therefore recommended that you eventually move the operating system partition (root) to an USB HDD or to lower the write frequency to the SD card by using the low-write mode.
Due to the number of writes that the full version of emoncms makes, the lifespan of an SD card will almost certainly be shortened, and it is therefore recommended that you eventually move the operating system partition (root) to an USB HDD or to lower the write frequency to the SD card by using the low-write mode.

As a general guide;
* A default installation of emoncms writes on average over 7kB of data to the disk per second.
* [Disabling Apache, Redis & emoncms logs](general.md#Disabling-System-Logs) reduces this to about 5kB per second.
* This guide will reduce the average amount of data written to less approximately 100Bytes per second or less.
* A further optional stage to protect the SD card is making the filesystem read-only. This is the best option when emoncms is deployed in a location where the electricity supply regularly fails or is interrupted (Guide to follow).

###Preparation

Before following this guide, it is essential that emoncms was initially installed by following the [Raspberry Pi installation guide](readme.md) or you have used git to install a working version of emoncms on your Raspberry Pi, and because the low-write mode **is not compatible with PHPFIWA feeds**, it's important that any existing PHPFIWA feeds are deleted, otherwise the system will become unstable.
Before following this guide;
1. It is essential that emoncms was initially installed by following the [Raspberry Pi installation guide](readme.md) or you have used git to install a working version of emoncms on your Raspberry Pi
1. Because the low-write mode **is not compatible with PHPFIWA feeds**, it's important that any existing PHPFIWA feeds are deleted, otherwise the system will become unstable.
1. If you have not already done so, ensure that you have [disabled your Apache, Redis & emoncms logs.](general.md#Disabling-System-Logs)

Update emoncms to current version:

cd /var/www/emoncms && git pull

###Changes to filesystem

sudo nano /etc/fstab

comment out the line starting `/dev/mmcblk0p2...` with a # so it reads `# /dev/mmcblk0p2...` and at the very top of the file, add the following 4 lines of text:

# Temporary mount points
tmpfs /tmp tmpfs nodev,nosuid,size=30M,mode=1777 0 0
tmpfs /var/log tmpfs nodev,nosuid,size=30M,mode=1777 0 0
/dev/mmcblk0p2 / ext4 defaults,ro,noatime,errors=remount-ro 0 1

Reboot the system `sudo reboot`
The filesystem will then restart in read-only mode, which allows us to disable the filesystem journaling.
Run the following command:

`sudo tune2fs -O ^has_journal /dev/mmcblk0p2`

The command takes a short while to complete, then shutdown the system, and remove the power lead when the pi has ceased activity.

`sudo poweroff`

Reconnect power and allow the pi to reboot.
Remount the filesystem as read-write:

`sudo mount -o remount,rw /dev/mmcblk0p2 /`

This will allow you to edit fstab:

`sudo nano /etc/fstab`

Delete the line `/dev/mmcblk0p2 / ext4 defaults,ro,noatime,errors=remount-ro 0 1` and also delete the # from the line starting `# /dev/mmcblk0p2` (which you commented out earlier).
Save & exit, then reboot.

`sudo reboot`

Edit the php config file to direct php5 sessions to tmpfs (RAM):

`sudo nano /etc/php5/apache2/php.ini`

Find the line - `; session.save_path = "/var/lib/php5/sessions"` and replace it with - `session.save_path = "/tmp"` **(Raspbian Jessie)** OR
Find the line - `; session.save_path = "/var/lib/php5"` and replace it with - `session.save_path = "/tmp"` **(Raspbian Wheezy)**

Save & exit.

Create a symlink to run feedwriter as a daemon and set permissions:

cd /etc/init.d && sudo ln -s /var/www/emoncms/scripts/feedwriter
Expand All @@ -18,16 +72,18 @@ Create a symlink to run feedwriter as a daemon and set permissions:
###Enable Low-write mode in emoncms

nano /var/www/emoncms/settings.php

In the section:
* **Redis**, change `$redis_enabled` from `false` to `true`
* **Redis Low-write mode** change `enabled` from `false` to `true`, and _optionally_ change `sleep` to a number (in seconds) which emoncms must cache before writing to disk.
* **Engine settings**, change `//,Engine::PHPFIWA // 6` to `Engine::PHPFIWA // 6` to disable PHPFIWA being an option for future feed selection.

Save & exit, then reboot
Save & exit, then power off your Raspberry Pi:

sudo poweroff

sudo reboot
Once your Pi has completely stopped, disconnect the power lead, then reconnect it, to restart your Raspberry Pi.

In your browser, open `emoncms -> Setup -> Administration` (you may need to log-out & log-in again to see Administration)
Under `Server Information`, the `Emoncms` section will be now extended to show the number of feed data points currently committed to the cache before being written to disk.
_NOTE: this data does not browser auto-update, it's necessary to refresh your browser to see the current data_
_NOTE: this data does not browser auto-update, it's necessary to refresh your browser to see the current data_
9 changes: 5 additions & 4 deletions docs/RaspberryPi/MQTT.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
##Enabling MQTT
MQTT is a "lightweight" messaging protocol, which enables the publishing of data from emoncms, as well as subscribing to data from
MQTT is a "lightweight" messaging protocol, which enables the publishing of data from emoncms, as well as subscribing to data from
other connected devices.
###Preparation

Before following this guide, it is essential that emoncms was initially installed by following the [Raspberry Pi installation guide](readme.md) or you have used git to install a working version of emoncms on your Raspberry Pi,
Before following this guide, it is essential that emoncms was initially installed by following the [Raspberry Pi installation guide](readme.md) or you have used git to install a working version of emoncms on your Raspberry Pi,
as well as a MQTT message broker such as [mosquitto](http://mosquitto.org/) installed and running.

Update emoncms to current version
Expand All @@ -21,7 +21,7 @@ Create a symlink to run phpmqtt_input as a daemon and set permissions

nano /var/www/emoncms/settings.php

In the section **MQTT**, change `$mqtt_enabled` from `false` to `true`, and also change the `$mqtt_server` IP address to that of your mqtt
In the section **MQTT**, change `$mqtt_enabled` from `false` to `true`, and also change the `$mqtt_server` IP address to that of your mqtt
server.
Save & exit, then reboot

Expand All @@ -32,4 +32,5 @@ Save & exit, then reboot
Data from within emoncms can be published by adding the `Publish to MQTT` input process to one or more of the node inputs.
In the process 'Text' box add the topic, for example; emoncms/solar
####emoncms as a subscriber
Unlike the above, the subscriber topic is hardcoded within emoncms, and takes the format `rx/*` - where `*` is the emoncms node number. For example, if data is published to topic rx/20 then emoncms will subscribe to that data, creating and updating node 20 in your inputs page
Unlike the above, the subscriber topic is hardcoded within emoncms, and takes the format `rx/*` - where `*` is the emoncms node number. For example, if data is published to topic rx/20 then emoncms will subscribe to that data, creating and updating node 20 in your inputs page.
Emoncms will also decode data in comma-delimited format, so for example; publishing values 657,899,5,776 to rx/20 will create Node 20, with 4 Key inputs which correspond with the 4 published comma-delimited values. Name labels can then be added to the key inputs in emoncms.
64 changes: 60 additions & 4 deletions docs/RaspberryPi/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If you cannot recall your Database 'user' & 'password', you can obtain them from
$database = "emoncms";
$username = "emoncms";
$password = "new_secure_password";

Save and exit.

***
Expand All @@ -50,7 +50,7 @@ The 'apps' need to save their configurations in the emoncms database, so in your
#####App configuration
You should now see a new menu item - 'Apps' on the menu bar, with a number of sub-menus. At this stage they will not display any data as they have not been configured.
To configure each app, using 'My Electric' as an example, select the spanner/wrench icon top right which will open the 'My Electric' configuration options page, and select the appropriate feeds & currency details and 'save'.
The choice of feeds is totally a user preference, and you could use appropriate feeds to:
The choice of feeds is totally a user preference, and you could use appropriate feeds to:
* Display Power imported
* Display Power exported
* Solar Generation
Expand All @@ -59,16 +59,72 @@ The choice of feeds is totally a user preference, and you could use appropriate
#####App update
The emoncms 'apps' are updated to add new functions and general improvements, and updating your apps installation can be achieved quickly and easily using Github.


To check if an 'apps' update is available, and update your installation:

`cd /var/www/emoncms/Modules/app && git pull`

The command 'git pull' will compare your installed version of 'Apps' with the 'Apps' software stored in Github, and if any new files are available, they will be automatically downloaded to your installation.

Carefully note the message displayed after running the command, as it will tell you if the update was sucessful or not.
Carefully note the message displayed after running the command, as it will tell you if the update was successful or not.

***

####Disabling System Logs
Once you are satisfied that your emoncms installation is running smoothly, and you have no log errors reported, it's advisable to disable system logs, and if you intend to run emoncms in the low-write mode ***this is a requirement***. Disabling the logs will reduce disk activity & usage, and help improve performance.

If at any stage you experience problems with your system, restoring your logs may help you resolve the problem, and can be achieved by reversing these instructions.

#####Disable emoncms log
In emoncms settings.php change `log_enabled = true;` to `log_enabled = false;`

`cd /var/www/emoncms && nano settings.php`

Save & exit

####Disable MYSQL log **(Jessie only)**

`sudo nano /etc/mysql/my.cnf`

Comment out the line `# log_error = /var/log/mysql/error.log` with a # - as shown.

#####Disable Apache log
Edit the apache configuration file (according to your operating system):

`sudo nano /etc/apache2/sites-available/000-default.conf` **(Raspbian Jessie)** OR
`sudo nano /etc/apache2/sites-available/default` **(Raspbian Wheezy)**

Comment out the line - `# CustomLog ${APACHE_LOG_DIR}/access.log combined`

Save & exit:

`sudo nano /etc/apache2/envvars`

and delete the word 'apache2' from `export APACHE_LOG_DIR=/var/log/apache2$SUFFIX` so that it reads `export APACHE_LOG_DIR=/var/log/$SUFFIX`

Save & exit, then disable the log to other-vhosts:

`sudo nano /etc/apache2/conf-available/other-vhosts-access-log.conf` **(Raspbian Jessie)** OR
`sudo nano /etc/apache2/conf.d/other-vhosts-access-log` **(Raspbian Wheezy)**

Comment out the line - `# CustomLog ${APACHE_LOG_DIR}/other_vhosts_access.log vhost_combined`

Save & exit:

#####Disable Redis log
Configure redis to run without logging or data persistence:

`sudo nano /etc/redis/redis.conf`

Comment out the line - `# logfile /var/log/redis/redis-server.log` and also comment out all redis saves:

# save 900 1
# save 300 10
# save 60 10000

Save & exit:

That completes the log reconfiguration, now reboot to effect the changes:

`sudo reboot`

***
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
## Install Emoncms on Raspberry Pi (Raspbian Jessie)
# Install Emoncms on Raspberry Pi (Raspbian Wheezy)

This guide will install the current full version of emoncms onto a Raspberry Pi running the Raspbian Jessie operating system.
This guide will install the current full version of emoncms onto a Raspberry Pi running the Raspbian Wheezy operating system.
An alternative installation guide is [avaliable for Raspbian Jessie](readme.md) - they are different, so ensure that you use the correct guide!
Due to the number of writes that the full version of emoncms makes, the lifespan of an SD card will almost certainly be shortened, and it is therefore recommended that you eventually [move the operating system partition (root) to an USB HDD](USB_HDD.md) or to lower the write frequency to the SD card by enabling the [low-write mode.](Low-write-mode.md)
Before installing emoncms, it is essential you have a working version of Raspbian Jessie installed on your Raspberry Pi. If not, head over to [raspberrypi.org](https://www.raspberrypi.org/documentation/installation/installing-images/README.md) and follow their installation guide.
Before installing emoncms, it is essential you have a working version of Raspbian installed on your Raspberry Pi. If not, head over to [raspberrypi.org](https://www.raspberrypi.org/documentation/installation/installing-images/README.md) and follow their installation guide.

### Preparation
## Preparation

Start by updating the system repositories and packages:

Expand All @@ -20,9 +21,9 @@ Install the pecl dependencies (serial, redis and swift mailer):

sudo pear channel-discover pear.swiftmailer.org
sudo pecl install channel://pecl.php.net/dio-0.0.6 redis swift/swift

Add the pecl modules to php5 config:

sudo sh -c 'echo "extension=dio.so" > /etc/php5/apache2/conf.d/20-dio.ini'
sudo sh -c 'echo "extension=dio.so" > /etc/php5/cli/conf.d/20-dio.ini'
sudo sh -c 'echo "extension=redis.so" > /etc/php5/apache2/conf.d/20-redis.ini'
Expand All @@ -31,15 +32,15 @@ Add the pecl modules to php5 config:
Issue the command:

sudo a2enmod rewrite
For `<Directory />` and `<Directory /var/www/>` change `AllowOverride None` to `AllowOverride All`. This should be on lines 155 and 166 of `/etc/apache2/apache2.conf`
sudo nano /etc/apache2/apache2.conf

For `<Directory />` and `<Directory /var/www/>` change `AllowOverride None` to `AllowOverride All`. This should be on lines 7 and 11 of `/etc/apache2/sites-available/default`

sudo nano /etc/apache2/sites-available/default

Save & exit, then restart Apache:

sudo /etc/init.d/apache2 restart

### Install the emoncms application via git

Git is a source code management and revision control system but at this stage we use it to just download and update the emoncms application.
Expand All @@ -60,7 +61,7 @@ When prompted, enter the 'MYSQL "root" user' password you were prompted for earl
Create the emoncms database:

CREATE DATABASE emoncms;

Add an emoncms database user and set that user's permissions.
In the command below, we're creating the database 'user' named 'emoncms', and you should create a new secure password of your choice for that user.
Make a note of both the database 'username' ('emoncms') & the 'new_secure_password'. They will be inserted into the settings.php file in a later step:
Expand All @@ -72,24 +73,20 @@ Make a note of both the database 'username' ('emoncms') & the 'new_secure_passwo
Exit mysql:

exit

### Create data repositories for emoncms feed engines:

sudo mkdir /var/lib/{phpfiwa,phpfina,phptimeseries}

and set their permissions

sudo chown www-data:root /var/lib/{phpfiwa,phpfina,phptimeseries}

### Configure emoncms database settings

cd into the emoncms directory:

cd /var/www/emoncms/

Make a copy of default.settings.php and call it settings.php:

cp default.settings.php settings.php
cd /var/www/emoncms && cp default.settings.php settings.php

Open settings.php in an editor:

Expand All @@ -101,37 +98,41 @@ Update your settings to use your Database 'user' & 'password', which will enable
$database = "emoncms";
$username = "emoncms";
$password = "new_secure_password";

Save and exit.

Create a symlink to reference emoncms within the web root folder:
Save and exit.
Set write permissions for the emoncms logfile:

cd /var/www/html && sudo ln -s /var/www/emoncms
`touch /var/www/emoncms/emoncms.log` followed by `chmod 666 /var/www/emoncms/emoncms.log`

### In an internet browser, load emoncms:

[http://localhost/emoncms](http://localhost/emoncms)

The first time you run emoncms it will automatically set up the database and you will be taken to the register/login screen.
The first time you run emoncms it will automatically set up the database and you will be taken to the register/login screen.
Create an account by entering your email and password and clicking register.
Once you are logged in;
* Check the Administration page - 'Setup > Administration' noting and acting upon any messages reported.
* Update your database - 'Setup > Administration > Update database'.
* Make a note of your 'Write API Key' from the 'Setup > My Account' page, and also ensure that the correct timezone is selected & saved.

### Install Emonhub

git clone https://github.com/emonhub/dev-emonhub.git ~/dev-emonhub && ~/dev-emonhub/install

Edit the emonhub configuration file, entering your emoncms 'Write API Key', and if necessary, also your rfm2pi frequency, group & base id:

nano /etc/emonhub/emonhub.conf

Save & exit. Edit /boot/cmdline.txt file by changing the line to;
`dwc_otg.lpm_enable=0 console=tty1 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait`
Save & exit, then edit inittab by adding a '#' to the beginning of the last line:

sudo nano /etc/inittab

so that it reads - `# T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100` then save & exit.
Edit the cmdline.txt file:

sudo nano /boot/cmdline.txt

by changing the line to - `dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait`
At this stage, power off your Raspberry Pi:

sudo poweroff
Expand All @@ -142,6 +143,7 @@ Once your Pi has stopped, disconnect the power lead and connect your RFM69Pi add

###System Options
* [Move the operating system partition (root) to an USB HDD](USB_HDD.md)
* [Disabling Apache, Redis & emoncms logs](general.md#Disabling-System-Logs)
* [Enabling low-write mode](Low-write-mode.md)
* [Enabling MQTT](MQTT.md)
* [Installing emoncms Apps](general.md#install-emoncms-apps)
Expand Down
Loading

0 comments on commit 9361146

Please sign in to comment.