{"id":218,"date":"2015-04-19T22:48:49","date_gmt":"2015-04-19T21:48:49","guid":{"rendered":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/?p=218"},"modified":"2015-04-21T01:16:55","modified_gmt":"2015-04-21T00:16:55","slug":"setting-up-raspberry-pi-for-emoncms-with-data-on-an-nfs-mount","status":"publish","type":"post","link":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/setting-up-raspberry-pi-for-emoncms-with-data-on-an-nfs-mount\/","title":{"rendered":"Setting up Raspberry Pi for EmonCMS with data on an NFS mount"},"content":{"rendered":"<p>The instructions\u00a0 for <a href=\"https:\/\/github.com\/emoncms\/emoncms\/blob\/bufferedwrite\/docs\/install.md\">installing Emoncms on the Raspberry Pi <\/a>are at available through the <a href=\"http:\/\/www.openenergymonitor.org\">OpenEnergyMonitor<\/a> site.\u00a0 However I had to take some additional steps.\u00a0 This page lists what I did, drawing heavily from those instructions with thanks.<\/p>\n<p>I used a Raspberry Pi 2 model B.\u00a0 This has Ethernet which I needed to connect to the network, though you could use a Wifi dongle.\u00a0 Before you can use the Pi, you have to install its operating system on a micro-SD card\u2013I used an 8Gbyte one.\u00a0 To receive wireless data from emonTx and emonTh modules, you need an expansion card such as the <a href=\"http:\/\/openenergymonitor.org\/emon\/emonbase\/raspberrypi\">RFM69Pi<\/a>.<\/p>\n<h3>Install Raspbian<\/h3>\n<p>Using Windows, fetch the <a href=\"http:\/\/www.raspberrypi.org\/downloads\">Raspbian installation image<\/a>.\u00a0 Extract the zip file to obtain the single image file, in my case called 2015-02-16-raspbian-wheezy.img.\u00a0 Write this image to the micro-SD card using <a href=\"http:\/\/sourceforge.net\/projects\/win32diskimager\/\">Win32DiskImager<\/a>.\u00a0 Insert the micro-SD card into the Raspberry Pi (it goes in upside down) and power up. Watch in amazement as the boot images whizz by on the HDMI-connected monitor.\u00a0 The initial screens allow you to set the password for the &#8220;pi&#8221; user, and if you are not based in the UK, you can change the Internationalisation options.<\/p>\n<p>The EmonCMS installation instructions suggest making an additional data partition on the SD card.\u00a0 I preferred not to do this for two reasons: the data is precious and the SD card has limited life, even with the write buffering.\u00a0 Instead, I plan to mount a shared folder from my Synology NAS drive to hold the data.\u00a0 I cover this in a separate post, as it is tricky.\u00a0 However, following the instructions caused the root filesystem to overflow during the installation of pre-requisite software, so I recommend expanding the filesystem to the full size of the SD card.\u00a0 There&#8217;s an option to do this in the initial configuration screens.\u00a0 If you&#8217;ve already exited, type &#8220;sudo raspi-config&#8221; to re-invoke the configuration screeen.<\/p>\n<h3>Disable Serial Port login<\/h3>\n<p>By default, Raspbian Wheezy is configured to support login on the serial port.\u00a0 This would conflict with the use of that port for radio communications, so we need to disable logins on the serial port.\u00a0 Edit the configuration files as follows:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo nano \/etc\/inittab<\/pre>\n<p>At the bottom of the file comment out the last line, by adding a \u2018# \u2019 at the beginning:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># T0:23:respawn:\/sbin\/getty -L ttyAMA0 115200 vt100<\/pre>\n<p>[Ctrl+X] then [y] then [Enter] to save and exit.\u00a0 Next, edit the boot command line:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo nano \/boot\/cmdline.txt<\/pre>\n<p>Raspbian has been updated since the Emoncms instructions were written, and the line to change is now a little different.\u00a0 Remove &#8220;console=ttyAMA0,115200&#8221; from the line, so that it reads<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">dwc_otg.lpm_enable=0 console=tty1 root=\/dev\/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait<\/pre>\n<h3>Change the filesystem to be mounted read-only<\/h3>\n<p>To reduce wear on the SD card, the filesystem can be mounted read-only, except when software updates are necessary.\u00a0 The data will be stored on an external NAS drive. Before switching to read-only mode, we need to create commands to switch between read-only and read-write modes, and create a mount-point for the data partition. Do this while logged in as &#8220;pi&#8221;.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">mkdir \/home\/pi\/data<\/pre>\n<p>Turn on the TMPFS filesystem:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo cp \/etc\/default\/tmpfs \/etc\/default\/tmpfs.orig\r\nsudo nano \/etc\/default\/tmpfs<\/pre>\n<p>Find the line that says<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">#RAMTMP=no<\/pre>\n<p>Change it by removing the &#8220;# &#8221; at the beginning of the line and changing &#8220;no&#8221; to &#8220;yes&#8221;:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">RAMTMP=yes<\/pre>\n<p>Use [Ctrl+X] then [y] then [Enter] to save and exit.<\/p>\n<p>Next, replace the filesystem mount point table:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo mv \/etc\/fstab \/etc\/fstab.orig\r\nsudo sh -c &quot;echo 'tmpfs\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/tmp\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tmpfs\u00a0\u00a0 nodev,nosuid,size=30M,mode=1777\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0 0' &gt;&gt; \/etc\/fstab&quot;\r\nsudo sh -c &quot;echo 'tmpfs\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/var\/log\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tmpfs\u00a0\u00a0 nodev,nosuid,size=30M,mode=1777\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0 0' &gt;&gt; \/etc\/fstab&quot;\r\nsudo sh -c &quot;echo 'proc\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/proc\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 proc\u00a0\u00a0\u00a0 defaults\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0 0' &gt;&gt; \/etc\/fstab&quot;\r\nsudo sh -c &quot;echo '\/dev\/mmcblk0p1\u00a0 \/boot\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 vfat\u00a0\u00a0\u00a0 defaults\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0 2' &gt;&gt; \/etc\/fstab&quot;\r\nsudo sh -c &quot;echo '\/dev\/mmcblk0p2\u00a0 \/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ext4\u00a0\u00a0\u00a0 defaults,ro,noatime,errors=remount-ro 0\u00a0\u00a0\u00a0 1' &gt;&gt; \/etc\/fstab&quot;\r\nsudo sh -c &quot;echo '192.168.10.102:\/volume1\/emonpi2\u00a0 \/home\/pi\/data\u00a0\u00a0 nfs \u00a0\u00a0 user=pi \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0 0' &gt;&gt; \/etc\/fstab&quot;\r\nsudo sh -c &quot;echo ' ' &gt;&gt; \/etc\/fstab&quot;\r\nsudo mv \/etc\/mtab \/etc\/mtab.orig\r\nsudo ln -s \/proc\/self\/mounts \/etc\/mtab<\/pre>\n<p>Note: The line referring to \/home\/pi\/data will need to be changed to reflect your NAS drive&#8217;s IP address (or DNS name) and shared folder path.\u00a0 See my separate post for instructions on making this work with Synology DiskStation DSM 5.1.<\/p>\n<p>Create the commands to switch between read-only and read-write mode:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo nano \/usr\/bin\/rpi-rw<\/pre>\n<p>In the empty file which loads, enter the following:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">#!\/bin\/sh\r\nsudo mount -o remount,rw \/dev\/mmcblk0p2\u00a0 \/\r\necho &quot;Filesystem is unlocked - Write access enabled&quot;\r\necho &quot;Type 'rpi-ro' to lock&quot;<\/pre>\n<p>[Ctrl+X] then [y] then [Enter] to save and exit, and then type the following to make the command executable:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo chmod +x\u00a0 \/usr\/bin\/rpi-rw<\/pre>\n<p>Similarly, create the opposite script:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo nano \/usr\/bin\/rpi-ro<\/pre>\n<p>In the empty file which loads, enter the following:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">#!\/bin\/sh\r\nsudo mount -o remount,ro \/dev\/mmcblk0p2\u00a0 \/\r\necho &quot;Filesystem is locked - Write access disabled&quot;\r\necho &quot;Type 'rpi-rw' to unlock&quot;<\/pre>\n<p>[Ctrl+X] then [y] then [Enter] to save and exit, and then type the following to make the command executable:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo chmod +x\u00a0 \/usr\/bin\/rpi-ro<\/pre>\n<p>Reboot to bring the changes into effect:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo shutdown -r now<\/pre>\n<p>Log in again and change the permissions on the data directories. This may bring up error messages when using the Synology NAS.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo chmod -R a+w data\r\nsudo chown -R pi data\r\nsudo chgrp -R pi data<\/pre>\n<p>Continue to follow the instructions from &#8220;Installing Dependencies&#8221; in the instructions in <a href=\"https:\/\/github.com\/emoncms\/emoncms\/blob\/bufferedwrite\/docs\/install.md\">installing Emoncms on the Raspberry Pi.<\/a>\u00a0 However, it turns out it is not really feasible to run MySQL with its data directory NFS mounted from Synology DSM.\u00a0 This is due to a number of factors:<\/p>\n<ul>\n<li>NFS mounts are not in place by the time MySQL starts (this could be worked around)<\/li>\n<li>Synology NFS exports have weird permissions and ownership issues (see separate post; I have no solution)<\/li>\n<li>I seem to recall criticism of the idea anyhow, on the basis that database storage should be local to the server for resiliency reasons.<\/li>\n<\/ul>\n<p>All is not lost however.\u00a0 Synology DSM is a flexible beast, and MySQL is available as a downloadable package for it, called MariaDB.<\/p>\n<ol>\n<li>Log into DSM as &#8220;admin&#8221; at http:\/\/diskstation:5000 (for example)<\/li>\n<li>Open &#8220;Package Center&#8221; and find MariaDB under &#8220;Utilities&#8221;. Press the &#8220;Install&#8221; button and wait until the magic is done.<\/li>\n<li>Find and install &#8220;phpMyAdmin&#8221;, also under &#8220;Utilities&#8221;.<\/li>\n<li>Open &#8220;phpMyAdmin&#8221; &#8211; this opens a new tab or browser window and presents the phpMyAdmin login screen.<\/li>\n<li>Log in as user &#8220;root&#8221; with no password.<\/li>\n<li>Under &#8220;General Settings&#8221;, select &#8220;Change password&#8221;.\u00a0 In the pop-up window, enter a new password for the &#8220;root&#8221; MySQL user, and then press &#8220;Go&#8221;.<\/li>\n<li>In the ribbon at the top centre of the screen, select &#8220;Users&#8221;.<\/li>\n<li>Halfway down the screen, there&#8217;s a section called &#8220;New&#8221;.\u00a0 Click on &#8220;Add user&#8221;.<\/li>\n<li>Under &#8220;Login information&#8221; enter the name &#8220;emoncms&#8221; in the &#8220;User name&#8221; field.<\/li>\n<li>Leave the &#8220;host&#8221; field set to the default value, to allow login from any host (or, for additional security, you could select &#8220;Use text field&#8221; and enter the IP address of the Raspberry Pi which will run the emoncms software).<\/li>\n<li>Enter a password for the &#8220;emoncms&#8221; user in the two fields provided.<\/li>\n<li>Under &#8220;Database for user&#8221;, select the checkbox marked &#8220;<label for=\"createdb-1\">Create database with same name and grant all privileges&#8221;.<\/label><\/li>\n<li>Click &#8220;Go&#8221; (which is at the very bottom right of the page).<\/li>\n<\/ol>\n<p>Continue with the instructions, but disable the MySQL service on the Raspberry Pi, as we&#8217;ll use the one on the Diskstation instead:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">rpi-rw\r\nsudo update-rc.d mysql disable<\/pre>\n<p>In the section of the instructions entitled &#8220;Set emoncms database settings,&#8221; set the username to &#8220;emoncms&#8221; and the password to the password you set in step 11 above. Set the hostname to the IP address of the DiskStation.\u00a0 Set the database name to &#8220;emoncms&#8221;.\u00a0 Once these settings have been made, reboot the Raspberry Pi and point your web browser its newly installed EmonCMS installation.\u00a0 Assuming the Raspberry Pi&#8217;s address is 192.168.1.22, this would be http:\/\/192.168.1.22\/emoncms.\u00a0 Register a new account on that page.\u00a0 You should see an account status page.\u00a0 In the &#8220;My Account&#8221; column, there is an entry called &#8220;Write API key&#8221;.\u00a0 Copy that value (it&#8217;s a string of letters and numbers) as you&#8217;ll need it in the next step.<\/p>\n<p>Enable writing to the SD card with the &#8220;sudo rpi-rw&#8221; command.\u00a0 Edit the emonhub configuration file.\u00a0 The instructions show how to edit the file, but they don&#8217;t explain what to change. Under &#8220;Reporters&#8221; you&#8217;ll see a line like this:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 apikey = xxxxxxxxxxxxxxxxxxxxxxxxxxxx<\/pre>\n<p>Change the string of &#8220;x&#8221;s to the value of the Write API key you copied above.\u00a0 Save the file and exit the editor. Restart emonhub:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo service emonhub restart\r\nrpi-ro<\/pre>\n<p>At this point your EmonCMS installation should be working (although a reboot of the Raspberry Pi might be a good idea) and upon logging in to EmonCMS and clicking on &#8220;Input&#8221;, you might be lucky enough to see any nodes you have already installed listed with their data values.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The instructions\u00a0 for installing Emoncms on the Raspberry Pi are at available through the OpenEnergyMonitor site.\u00a0 However I had to take some additional steps.\u00a0 This page lists what I did, drawing heavily from those instructions with thanks. I used a Raspberry Pi 2 model B.\u00a0 This has Ethernet which I needed to connect to the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-218","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/posts\/218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/comments?post=218"}],"version-history":[{"count":10,"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/posts\/218\/revisions"}],"predecessor-version":[{"id":233,"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/posts\/218\/revisions\/233"}],"wp:attachment":[{"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/media?parent=218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/categories?post=218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lemongrass.org.uk\/lemongrass\/wp-json\/wp\/v2\/tags?post=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}