Configuration

In most situations Wattsworth should work well with the default settings. For more complex setups involving systems that may loose power, are connected through networks, or other special cases the reference material in this section shows how to fine tune the installation to meet these needs.

Storage

Make sure you set up data journaling on the nilmdb partition. This will prevent data corruption if the computer looses power without properly shutting down.

Edit /etc/fstab and add the data=journal option to the parition with the nilmdb database.

# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump>  <pass>
  UUID=XXX   /   ext4    errors=remount-ro,data=journal  0 1
                               # add this  --^

If the partition is the root partition you must add this option directly to the volume as well, otherwise the system will not boot properly. For example if your root partition is on /dev/sda2:

$> sudo tune2fs -o journal_data /dev/sda2

<span class="lead" id="storage">Storage Setup</span>
<hr/>
<p>
  This section explains how to properly format and configure
    an extra hard drive for a NILM system. It is usually a good idea to place the Nilm Database on a seperate hard drive. This prevents the database from filling the primary drive to the point
  where the system become unusable and also makes it easy to retrieve collected data from an installation by simply swapping out the extra harddrive.
</p>
<p><b>Formatting a drive</b> After installing the drive and booting the system, the first step to use
  the drive is to place a usable filesystem on it. There are many tools that can be used for this but one of the easiest is GParted. This program must be run as root. From the command line type type the following:
</p>
<div class="alert alert-danger"><i class="icon icon-warning-sign"></i> Be very careful with gparted, formatting the primary drive will destroy the installation</div>
  <section class="indented cm-view ">
    <textarea class="cm-textarea-sh">
      $ sudo gparted </textarea>
  </section>
  <p>
  Select the extra drive from the dropdown menu as shown. Generally the extra drive should be <b>/dev/sdb</b>
  but this is not always the case. If the drive already has multiple partitions this most likely means it is the primary drive.
</p>
  <div class="row">
    <div class="col-sm-12 col-md-6">
      <div class="thumbnail">
        <%=image_tag "hdd_gparted_1.png"%>
        <div class="caption">
          Carefully select the device node for the extra drive
        </div>
      </div>
    </div>
    <div class="col-sm-12 col-md-6">
      <div class="thumbnail">
        <%=image_tag "hdd_gparted_2.png"%>
        <div class="caption">
          Create a new msdos partition table. This will erase the drive.
        </div>
      </div>
    </div>
  </div>
  <p>
  Select <b>Device</b> > <b> Create Partition Table</b> to bring up the Create Partition dialog. Select <b>msdos</b> and click Apply. Select <b>Partition</b> > <b>New</b> to bring up the New Partition dialog. Add a new <b>ext4</b> partition to the drive and assign it the full extents of the disk (this is the default). Click Add to close the dialog. Finally click <b>Apply</b> to format the disk and then close the program.
  <div class="row">
    <div class="col-sm-12 col-md-6 col-md-offset-3">
      <div class="thumbnail">
        <%=image_tag "hdd_gparted_3.png"%>
        <div class="caption">
          Add an <b>ext4</b> partition to fill the disk
        </div>
      </div>
    </div>
  </div>
  <p>
    To use the drive for the Nilm database it must be mounted to the correct location in the filesystem. Edit <b>/etc/fstab</b> in a word processor and add the following line where /dev/sdX1 is the name of the drive you just formatted. The number one refers to the first (and only) partition. Note that you will need to run the word processor as root (sudo) in order to edit this file.
    <pre>
    /dev/sdX1 /opt/data ext4 errors=remount-ro 0 1 </pre>
    When using an external drive as the primary storage volume, drive letters cannot be used since they change. The UUID is a unique drive partition identifier that should be used instead. Running <span class="text-mono">sudo lsblk /dev/sdX1</span> will print out the UUID. The new line in <b>/etc/fstab</b> should resemble the following.
    <pre>
    UUID=XXXXXXXX-XXXXX-XXXX-XXXX-XXXXXXXXXXXX /opt/data ext4 errors=remount-ro 0 1 </pre>
    Run the following commands to mount the drive and setup the permissions. Use <b>df</b> to verify the configuration:
    <section class="indented cm-view ">
      <textarea class="cm-textarea-sh">
$ sudo service nilm-capture stop #stop data capture if it is already running
$ sudo mount -a
$ sudo chown -R nilm:nilm /opt/data #assign the drive to the nilm user
$ df -h</textarea>
    </section>
  </p>
  <p>
  The output from <b>df</b> should look similar to that below:
  </p>
  <pre>
  Filesystem      Size  Used Avail Use% Mounted on
  /dev/sda1       1.8T  5.3G  1.7T   1% /
  ... other mount points ...
  /dev/sdc1       917G   72M  871G   1% /opt/data</pre>
<p>If you have already configured your meters and want to start collecting data, run:</p>
    <section class="indented cm-view ">
      <textarea class="cm-textarea-sh">
$ sudo service nilm-capture start</textarea>
    </section>