Install phoneDistance

From xPL
Revision as of 10:44, 4 June 2015 by Fcorthay (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The distance calculator receives NMEA position messages on an UDP port. From this, it calculates the distance to several locations such as home or work and sends them as an xPL message.

Before all, make sure you have installed an xPL hub.

Install xPL phone distance calculator

On your mobile phone, install a a GPS location streamer such as GPS2IP. Set-up the application to send GPGGA to a selected UDP port.

Under construction icon-blue

Download the xPL phone distance calculator script.

Move the script to xPL scripts directory:

SCRIPTS_BASE_DIR=/home/control/Documents/Controls
mv xpl-phoneDistance.pl $SCRIPTS_BASE_DIR
chown control:users $SCRIPTS_BASE_DIR/*.pl
chmod 775 $SCRIPTS_BASE_DIR/*.pl

Test the phone distance calculator

Test it:

su control
SCRIPTS_BASE_DIR=/home/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-phoneDistance.pl -h
$SCRIPTS_BASE_DIR/xpl-phoneDistance.pl -vn alert

Open a 2nd terminal window (on any machine with xPL installed) and monitor the xPL protocol:

SCRIPTS_BASE_DIR=/home/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-monitor.pl -vf

Open a 3rd terminal window (on any machine with xPL installed) and control the lights:

SCRIPTS_BASE_DIR=/home/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c alert.basic command=play
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c alert.basic command=play soundFile=pop.wav

The doorbell sound should play.

Launch the xPL distance calculator at startup

The xPL distance calculator is to be launched after the xPL hub.

Ubuntu

On Ubuntu, the xPL distance calculator starts-up once xpl-hub_started has been emitted.

Edit /etc/init/xpl-phoneDistance.conf :

################################################################################
# xPL alert, plays sound
#
description "xPL alert"
version     "1.0"
author      "Francois Corthay"

#-------------------------------------------------------------------------------
# Configuration variables
#
env SCRIPTS_DIR='/home/control/Documents/Controls'
env SCRIPT_NAME='xpl-phoneDistance.pl'
env PARAMETERS='-n door -s doorBell.wav'

#-------------------------------------------------------------------------------
# Start and stop conditions
#
start on xpl-hub_started
stop on shutdown
respawn
setuid control
setgid audio

#-------------------------------------------------------------------------------
# Start daemon
#
exec $SCRIPTS_DIR/$SCRIPT_NAME $PARAMETERS

Start the device and test it:

su root
service xpl-phoneDistance start
service xpl-phoneDistance status
initctl list | grep xpl
ps aux | grep -i xpl | grep -v grep | sed 's/.*\/Controls\///'

su control
SCRIPTS_BASE_DIR=/home/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c alert.basic command=play