Sunday, January 19, 2014

PogoPlug as external event logger for MicasaVerde VeraLite

Recently I set up a VeraLite z-wave home automation controller from MiCasaVerde.
My main goals are to use this for home energy monitoring and climate control (AC/heat).


- Energy monitoring is done with an Aeon Labs Home Energy Monitor (DSB28-ZWUS).
- AC is controlled by a Trane Z-Wave thermostat

There is a plugin for the VeraLite called "DataMine" which can do graphing of energy usage, but it runs on the VeraLite itself.

I wanted to have the flexibility to record the data on a separate server in order to have additional options for storage, processing and presentation.

The MIOS OS running on the VeraLite has the option to specify an external event logger, which will be used to implement this.

I basically followed the instructions from the excellent MiCasaVerde forum:

Re: HOWTO: Event logging to database

1. set up a web server with PHP and MySQL that supports HTTPS. Configuration is described in my previous post: Install Lighttpd/PHP5/MySQL on PogoPlug or Dockstar running Debian

2. create the database and database tables for logging the VeraLite events, for example:

mysql> create database vera;
mysql> create user 'vera'@'localhost' identified by 'vera';
mysql> grant all privileges on vera.* to 'vera'@'localhost';
mysql> flush privileges;
mysql> quit;
$
$ mysql -uvera -pvera vera < alert.sql
$


3. deploy the alert.php file on the web server
- needs to be accessible at the root of the web server as /alert (use url rewrite)
- adjust the db name/username/password if necessary



4. configure VeraLite/MIOS to use the alternate event logger

http://[YOUR-VERA-IP-ADDRESS]:3480/data_request?id=variableset&Variable=AltEventServer&Value=[YOUR-WEBSERVER-IP-ADDRESS]


5. configure notifications as needed on the VeraLite through the MIOS UI


Install Lighttpd/PHP5/MySQL on PogoPlug or Dockstar running Debian


I wanted to set up a PogoPlug with an HTTP(S) server, PHP support and MySQL so I can use it for logging my home automation data (e.g. energy usage).

I had already installed Debian Wheezy on the PogoPlog E02 (See my previous post).

Since the Seagate Dockstar has the same CPU as the PogoPlug E02, these instructions should also work for the Dockstar.

For the most part I followed the instructions here: Installing Lighttpd With PHP5 (PHP-FPM) And MySQL Support On Debian Wheezy

1. install MySQL
apt-get install mysql-server mysql-client

Note:
Probably a good idea to enter a root password for MySQL when asked.

Note2:
Unfortunately, this install hung on the message "InnoDB: using native Linux AIO".
I had to reboot the server and then run
dpkg --configure -a to finish the installation, which went fine after that.


2. install lighttpd
apt-get install lighttpd


3. install PHP5, PHP5 FPM (FastCGI Process Manager) and related PHP modules
apt-get install php5 php5-fpm php5-mysql php5-cli php5-xcache


4. configure lighttpd to use fastcgi and php5-fpm (more details: http://www.howtoforge.com/installing-lighttpd-with-php5-php-fpm-and-mysql-support-on-debian-wheezy)

- edit the /etc/lighttpd/conf-enabled/15-fastcgi-php.conf file to use the FPM (replace the existing content which uses php-cgi with this):
## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server += ( ".php" =>
    ((
        "socket" => "/var/run/php5-fpm.sock",
        "broken-scriptfilename" => "enable"
    ))
)


- enable the modules
lighttpd-enable-mod fastcgi 
lighttpd-enable-mod fastcgi-php 

- reload lighttpd
/etc/init.d/lighttpd force-reload

- edit the /etc/php5/fpm/php.ini file, uncomment the line:
cgi.fix_pathinfo=1

- reload FPM
/etc/init.d/php5-fpm reload

5. configure URL rewriting for lighttpd
- edit /etc/lighttpd/lighttpd.conf to add the url.rewrite section based on your needs

6. configure SSL for lighttpd

- create a self-signed certificate
apt-get install openssl

mkdir /etc/lighttpd/cert


cd /etc/lighttpd/cert


openssl req -new -x509 -keyout midnightcoding.pem -out midnightcoding.pem -days 365 -nodes


chmod 600 /etc/lighttpd/cert


lighttpd-enable-mod ssl


- edit the ssl configuration file
vi /etc/lighttpd/onf-available/10-ssl.conf

- change the line with ssl.pemfile to point to the path /etc/lighttpd/cert/midnightcoding.pem


7. install phpMyAdmin (optional)

apt-get install phpmyadmin

(select lighted as the web server for phpMyAdmin)


8. get phpmyadmin and other url rewrite rules to play nice

- url.rewrite overwrites the alias.url used by phpmyadmin in /etc/lighttpd/conf-enabled
  -> need to add a special rule to pass along  phpmyadmin urls "as-is"

url.rewrite-if-not-file = (
     "^/(phpmyadmin)/(.*)" => "$0",     
     "^/([^?]*)(\?.*)?$" => "/$1.php$2"
)



Now you should be able to access your server at:
https://[YOUR-SERVER-IP]/phpmyadmin




Tuesday, January 7, 2014

Seagate Dockstar - use a digital photo frame as display

I wanted to put a cheap display on my Seagate Dockstar that I am currently using as Internet Radio and AirPlay receiver (using mpd and mpc).

After some research, I found some recommended suitable displays. The displays I bought are based on the "AppoTech AX206" chip and are  supported by LCD4Linux, but the display firmware needs to be "hacked" first to allow it to be used from Linux.

I got a lot of information from this post: Digital Picture Frame as a router status display and the OpenWRT forum. See here for more info and supported devices.

I got the display to work on the Raspberry Pi successfully, now onto the next device.

Some Dockstar instructions are here (in German): LCD Display an DockStar


Installation on the Dockstar:
Unfortunately the LCD4Linux version installable with "apt-get install lcd4linux" is too old and does not include the needed DPF drivers. So we need to rebuild LCD4Linux.


0. Hack the LCD firmware, please refer to the links above for this.

1.install necessary dependency packages

apt-get install libgd2-noxpm

2. install SVN and other dependencies to be able to build lcd4linux

apt-get install subversion
apt-get install pkg-config  automake autoconf make checkinstall

apt-get install libtool libusb-dev


(Note: these files might take up quite a lot of space, about 40+ MB on my system. They are only necessary to successfully compile LCD4Linux)


3. make a folder where to put the LCD4Linux files, e.g. /home/root/dpf

cd /home/root
mkdir dpf


4. get (checkout) the LCD4Linux files (currently this is revision 1200):

svn co https://ssl.bulix.org/svn/lcd4linux/trunk lcd4linux

5. build the DPF version of LCD4Linux

cd lcd4linux
./bootstrap
./configure --with-drivers='DPF' --with-plugins='all,!dbus'



6. install the LCD4Linux package

checkinstall -D



On success you should get:

**********************************************************************

 Done. The new package has been installed and saved to

 /home/root/dpf/lcd4linux/lcd4linux_0.11.0-1200-1_armel.deb

 You can remove it from your system anytime using:

      dpkg -r lcd4linux

**********************************************************************


Notes:
 - checkinstall will ask for a name, I used "LCD4Linux with DPF"
 - checkinstall will complain aboput the version number, so I used "0.11.0-1200" since 1200 was the SVN revision that was used
 - as noted in the success message, the installed package can be removed with "dpkg -r lcd4linux"



7. create or adjust your LCD4Linux configuration file 
 - the file needs to be located in /etc and called lcd4linux.conf


or get an example file from here:


wget http://pkern.at/wp-content/uploads/lcd4linux/lcd4linux.conf

Note: the permissions on the lcd4linux.conf file need to be set as:

chmod 600 lcd4linux.conf


8. start/restart LCD4Linux

kill lcd4linux && sleep 1 && lcd4linux

Success:




9. Adjust lcd4linux.conf file according to your needs