Install phoneDistance

From xPL
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 the phone distance calculator

Mobile phone

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

My GPS2IP settings are:

  • Time between sending: 60 seconds
  • GPS accuracy: moderate
  • NMEA message to send: GGA
  • Generate in background mode: on
  • Connection method: UDP push
  • Phone IP selection: cellular IP

Linux machine

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 home

Start the mobile phone application (GPS2IP). The location information should appear in the terminal window at the receival of each new GPS location.

Open a 2nd terminal window and look at the loged positions:

cat /tmp/phoneDistance.log

Open a 3rd 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

Launch the xPL distance calculator at startup

Multiple instances of the distance calculator can be launched at startup, each with a different GPS UDP port, allowing to follow different phones.

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 phone distance calculator
#
description "xPL phone distance"
version     "1.0"
author      "Francois Corthay"

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

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

#-------------------------------------------------------------------------------
# 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\///' | sort