LamPI Setup

July 07, 2015

This document describes how to install the LamPI environment on your Raspberry-PI

Shopping List ... what do you need

Before you install LamPI it is good to know that LamPI makes use of other software packages. Although it is sometimes possible to bundle this software with my release I prefer not to do so. LamPI will wotk with the latest version of this software and you can download yourself. When in doubt, you can install the release mentioned in this documentation as it is tested by me ...

LamPI needs several other packages in order to be installed on a RaspberryPI successfully.

For your Linux installation you need amongst others:

For the software to work you also need:

If you like to automate most of the installation (and you probably want to), please visit the page of PI-install.

What Platform(s) does LamPI run on?

 

LamPI Installation

Of course we all like to use our RaspberryPI for multiple tasks. Reality is: If you need to rely on the Raspberry + LamPI combo to switch your lighting and other devices reliably, then you must seriously consider reserving a RaspberryPI device for JUST DOING THAT and nothing else.

Therefore, I decided to make the configuration and installation locations for LamPI really simple: Put everything in the LamPI homedirectory or one of its subdirectories. Of course it is quite good possible to use other locations, but I must warn you, unless you are an experienced user it will be difficult to get everything up and running so why not use the pi home directory and its subdirectories ~/www, ~/config, ~/scripts, ~/exe and ~/receivers?

Starting the System

This short chapter describes the basic and minimal steps to take to get LamPI up and running.

 

1. Setup the database for LamPI

LamPI will not function without a MySQL database in place. Unfortunately, the standard user on the Raspberry-PI is user "pi" and that user is not known to the MySQL system. Therefore we need to make a new user for the database, one that is NOT a Linux user, but a user only for the database. In my system (as you can see in the file "~/config/params.js" is Use a standard and default user "coco". The password of this user is "coco" as well. (More information is in the PI-install file).

Of course you are free to use the same username and password for your LamPI setup, but I imagine that you would like to use one of your own. Setting up a user if not difficult, first you have to enter the mySQL system through the commandline on Raspberry and make a new database, user and password for that user. After this is done, you can setup the system further but you must provice the system with the new database name, user and password in the file ~/config/params.js

That said, in the file ~/config.params.js it is possible to specify your credentials for the MySQL database. However, in that file you can see that it is equally possible to specify these credentials as ENV rironmental parameters that are read by the params.js file. Should you want to specify global parmeters in the ENV settings, than follow the following precedure:

1. Edit the ~/.profile file with for example nono:

nano ~/.profile


2. And append the following lines:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/scripts" ] ; then
  PATH="$HOME/scripts:$PATH"
fi

DBUSER="<your Login>"; export DBUSER
DBPASSWD="<you Password>"; export DBPASSWD
DBHOST="<your IP>"; export DBHOST
DBNAME="<yourDbaseName>"; export DBNAME

This will make DBUSER and the others available as environment variables to the system, and read them in the ~/config/params.js file.

Dor not forget to run

. .profile

2. Configure the database.cfg file

Most of the configuration of LamPI can be done from the user interface application. This includes making/deleting of rooms, scenes and timers. Also, assigning devices to rooms, with the correct type and address is cometihing that can be done from the user interface. Should for whatever reason the LamPI configuration not work as expected or desired than it's good to know that there is a main configuration file for the LamPI operation that is read upon startup and that would contain the correct information.

As shipped, your LamPI system contains the standard database.cfg file, which is mine and probably not useful for others (=you). Therefore edit the ~/config/database.cfg file

vi ~/config/database.cfg

The database.cfg file contains a readable jSon description of the LamPI configuration. It is possible to change database.cfg with a simple text editor (and unfortunately for some complex settings you must) and its content is used to initialize the MySQL database which is queried upon program setup. In the "Config" menu of the application you can set several parameters and you can make backups and do restores from xxxxxx.cfg files in the ~/config directory.

This way, you can make a backup of YOUR database.cfg file and do restores as well if you messed up for whatever reason.

 

3. Startup Parameters

The "LamPI-node.js" file reads its program parameters from a special file in "~/config/params.js". Since parameters are specific to the running program you need to change the standard values to those that match your setup of the program.

nano ~/config/params.js

It is possible to specify the parameters directly in the file OR (and that is preferred) use the environment variables of your system to specify these parameters. The latter is easy: Just edit your "~/.profile" file and sepcify the value of the parameter. This is safer also, in case you distribute the files from one machine to the other.

nano ~/.profile

and edit for example the parameters of the alarm system, Z-Wave IP gateway and MySQL credentials by adding these lines to the .profile file.

# set PATH so it includes user's private scripts if it exists
if [ -d "$HOME/scripts" ] ; then
  PATH="$HOME/scripts:$PATH"
fi

WLOGIN="your_login_name"; export WLOGIN
WPASSWD="your_password"; export WPASSWD
WHOST="192.168.2.101"; export WHOST

ZHOST="192.168.2.51"; export ZHOST

DBLOGIN="your_login_name"; export DBLOGIN
DBPASSWD="your_password"; export DBPASSWD
DBHOST="192.168.2.80"; export DBHOST

Most important parameters are:

 

3. Start the daemon

Wthout the daemon running, LamPI will not have a database and will not run correctly. Start the ~/daemon/LamPI-node.js with the following command:

cd ~/scripts;
./PI-node -i

Check whether LamPI will start correctly now and read the database. At anytime you can see the output of the LamPI-node.js process by inspecting the log-file. A good way to do this is with the following command:

tail -f ~/log/PI-node.log

Each time you need to restart the LamPI daemon, use the following command:

./PI-node -r

 

4. Loading a new configuration file

If you mess up or add new devices to your system, then it is of-course possible to add devices to the system with the GUI. But if you made a regular backup of your "~/config/database.cfg" file, it is easier to just restore the system should for whatever reason your database fail.

You can load a configuration file on more than one way:

  1. Use the GUI, go to the "Config" menu and select the "Backup" button. In the backup/restore screen do a restore of the "database.cfg" file or another file where you saved your active configuration
  2. Initialize the database from the commandline. This is the ultimate survivors kit, if everything fails this will probably work. Make sure that a working version of your database.cfg file is in the ~/config directory, and type in firefox or IE:

    http://192.168.xx.yy:8080/init

    This command which will load the database.cfg through the frontend. This method will work excellent even when the GUI does not work (if you messed up).


Jul. 2015