Difference between revisions of "Install state"

From xPL
Jump to: navigation, search
(Created page with " ::<html> <a title="By Dsmurat (+) [LGPL (http://www.gnu.org/licenses/lgpl.html)], via Wikimedia Commons" href="http://commons.wikimedia.org/wiki/File%3AUnder_construction_ic...")
 
Line 4: Line 4:
 
<a title="By Dsmurat (+) [LGPL (http://www.gnu.org/licenses/lgpl.html)], via Wikimedia Commons" href="http://commons.wikimedia.org/wiki/File%3AUnder_construction_icon-blue.svg"><img width="512" alt="Under construction icon-blue" src="//upload.wikimedia.org/wikipedia/commons/thumb/d/d5/Under_construction_icon-blue.svg/512px-Under_construction_icon-blue.svg.png"/></a>
 
<a title="By Dsmurat (+) [LGPL (http://www.gnu.org/licenses/lgpl.html)], via Wikimedia Commons" href="http://commons.wikimedia.org/wiki/File%3AUnder_construction_icon-blue.svg"><img width="512" alt="Under construction icon-blue" src="//upload.wikimedia.org/wikipedia/commons/thumb/d/d5/Under_construction_icon-blue.svg/512px-Under_construction_icon-blue.svg.png"/></a>
 
</html>
 
</html>
 +
 +
 +
The [http://en.wikipedia.org/wiki/XPL_Protocol xPL] home state device stores the current state of different devices
 +
such as lights, shutters, etc…
 +
This information can be retrieved by clients such as [https://en.wikipedia.org/wiki/Web_2.0 web 2.0] pages
 +
in order to display the proper state of the devices to be controlled.
 +
 +
The state update is best controlled with the help of the [[install central|central xPL device]].
 +
 +
Before all,make sure you have installed an [[install xpl hub|xPL hub]].
 +
 +
= Install xPL home state device =
 +
 +
Download the [http://www.dspc.ch/xPL/Downloads/xpl-homeState.pl xPL home state] script.
 +
 +
Move the script to xPL scripts directory:
 +
SCRIPTS_BASE_DIR=/home/control/Documents/Controls
 +
mv xpl-homeState.pl $SCRIPTS_BASE_DIR
 +
chown control:users $SCRIPTS_BASE_DIR/*.pl
 +
chmod 775 $SCRIPTS_BASE_DIR/*.pl
 +
 +
= Configure xPL home state device =
 +
 +
Edit <code>/home/control/Documents/Controls/centralActions.xml</code>:
 +
<?xml version="1.0" encoding="ISO-8859-1"?>
 +
&lt;!--
 +
  possible rules:
 +
    messageType_source_target_class_name1_value1_name2_value2="messageType target class name1=value1 name2=value2"
 +
    messageType_source_target_class_name1_value1_name2_value2="messageType target class name1=value1 name2=value2|messageType target class name1=value1 name2=value2"
 +
    messageType_source_target_class_name1_value1_name2_value2="messageType target class name1=value1 name2=value2|sleep 100 ms|messageType target class name1=value1 name2=value2"
 +
-->
 +
<actions>
 +
  <pingPong
 +
    xpl-cmnd_any_any_pingPong.basic_message_ping="xpl-trig * pingPong.basic message=pong"
 +
  />
 +
    <eib
 +
    xpl-trig_any_any_eib.basic_group_01.01.001_data_0x00="xpl-cmnd dspc-state.home state.basic command=update room=study level=lights object=ceiling value=off"
 +
    xpl-trig_any_any_eib.basic_group_01.01.001_data_0x01="xpl-cmnd dspc-state.home state.basic command=update room=study level=lights object=ceiling value=on"
 +
    xpl-trig_any_any_eib.basic_group_01.01.002_data_0x00="xpl-cmnd dspc-state.home state.basic command=update room=study level=lights object=stand value=off"
 +
    xpl-trig_any_any_eib.basic_group_01.01.002_data_0x01="xpl-cmnd dspc-state.home state.basic command=update room=study level=lights object=stand value=on"
 +
    xpl-cmnd_any_any_state.basic_command_set_room_study_level_lights_object_ceiling_value_off="xpl-cmnd dspc-eib.home eib.basic group=1/1/1 data=0x00"
 +
    xpl-cmnd_any_any_state.basic_command_set_room_study_level_lights_object_ceiling_value_on="xpl-cmnd dspc-eib.home eib.basic group=1/1/1 data=0x01"
 +
    xpl-cmnd_any_any_state.basic_command_set_room_study_level_lights_object_stand_value_off="xpl-cmnd dspc-eib.home eib.basic group=1/1/2 data=0x00"
 +
    xpl-cmnd_any_any_state.basic_command_set_room_study_level_lights_object_stand_value_on="xpl-cmnd dspc-eib.home eib.basic group=1/1/2 data=0x01"
 +
  />
 +
</actions>
 +
 +
The comments in the beginning of the file show the structure of the rules.
 +
Each line defines a pattern which, compared to an incoming xPL message, can trigger one or more other messages.
 +
The format of these rules has been defined in order to allow to write one per line.
 +
If a parameter of a message to be sent contains a space character, that character has to be replaced by an underscore.
 +
 +
The rules are grouped in parts such as <code>pingPong</code> and <code>eib</code> in the preceeding example.
 +
This has no effect in the interpretation of the commands:
 +
it's only purpose is to structure the XML file and to allow commenting out parts of the configuration items
 +
or adding comments in the file.
 +
 +
The configuration file is read anew each time a new xPL message arrives.
 +
This allows to edit and update the rules without having to stop and restart the xPL central device.
 +
 +
= Test xPL home state device =
 +
 +
Test it on a [[install BeagleBone|BeagleBone]]:
 +
su control
 +
SCRIPTS_BASE_DIR=/home/control/Documents/Controls
 +
$SCRIPTS_BASE_DIR/xpl-homeState.pl -h
 +
$SCRIPTS_BASE_DIR/xpl-homeState.pl -v -n home
 +
 +
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 another terminal and send a message to the serial port:
 +
su control
 +
SCRIPTS_BASE_DIR=/home/control/Documents/Controls
 +
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c pingPong.basic message=ping
 +
 +
The monitor should display the <code>ping</code> message,
 +
directly followed by a <code>pong</code> message emitted by the xPL central device.
 +
 +
= Launch the xPL home state device at startup =
 +
 +
The xPL central device is to be launched after the xPL hub.
 +
 +
== Ubuntu ==
 +
 +
On Ubuntu, the xPL central device starts-up once <code>xpl-hub_started</code> has been emitted.
 +
 +
Edit <code>/etc/init/xpl-homeState.conf</code>:
 +
################################################################################
 +
# xPL central message parser
 +
#
 +
description "xPL central message parser"
 +
version    "1.0"
 +
author      "Francois Corthay"
 +
 +
#-------------------------------------------------------------------------------
 +
# Configuration variables
 +
#
 +
env SCRIPTS_DIR='/home/control/Documents/Controls'
 +
env SCRIPT_NAME='xpl-homeState.pl'
 +
env PARAMETERS='-n home'
 +
 +
#-------------------------------------------------------------------------------
 +
# 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-central start
 +
service xpl-central status
 +
 +
SCRIPTS_BASE_DIR=/home/control/Documents/Controls
 +
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c pingPong.basic message=ping
 +
 +
== Mac OS ==
 +
 +
On Mac OS, the xPL central device starts-up later than the hub.
 +
 +
Edit <code>/Library/LaunchDaemons/xpl-central.plist</code>:
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 +
<plist version="1.0">
 +
  <dict>
 +
    <key>Label</key>
 +
    <string>xPL central message parser</string>
 +
    <key>OnDemand</key>
 +
    <false/>
 +
    <key>UserName</key>
 +
    <string>control</string>
 +
    <key>ProgramArguments</key>
 +
    <array>
 +
      <string>/Users/control/Documents/Controls/xpl-central.pl</string>
 +
      <string>-n</string>
 +
      <string>lounge</string>
 +
      <string>-w</string>
 +
      <string>25</string>
 +
      <string>-a</string>
 +
      <string>/Users/control/Documents/Controls/centralActions.xml</string>
 +
    </array>
 +
  </dict>
 +
</plist>
 +
 +
Start the device and test it:
 +
su root
 +
launchctl load /Library/LaunchDaemons/xpl-central.plist
 +
 +
SCRIPTS_BASE_DIR=/Users/control/Documents/Controls
 +
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c pingPong.basic message=ping
 +
 +
[[Category: install]]

Revision as of 16:47, 1 April 2014


Under construction icon-blue


The xPL home state device stores the current state of different devices such as lights, shutters, etc… This information can be retrieved by clients such as web 2.0 pages in order to display the proper state of the devices to be controlled.

The state update is best controlled with the help of the central xPL device.

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

Install xPL home state device

Download the xPL home state script.

Move the script to xPL scripts directory:

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

Configure xPL home state device

Edit /home/control/Documents/Controls/centralActions.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
  possible rules:
    messageType_source_target_class_name1_value1_name2_value2="messageType target class name1=value1 name2=value2"
    messageType_source_target_class_name1_value1_name2_value2="messageType target class name1=value1 name2=value2|messageType target class name1=value1 name2=value2"
    messageType_source_target_class_name1_value1_name2_value2="messageType target class name1=value1 name2=value2|sleep 100 ms|messageType target class name1=value1 name2=value2"
-->
<actions>
  <pingPong
    xpl-cmnd_any_any_pingPong.basic_message_ping="xpl-trig * pingPong.basic message=pong"
  />
   <eib
    xpl-trig_any_any_eib.basic_group_01.01.001_data_0x00="xpl-cmnd dspc-state.home state.basic command=update room=study level=lights object=ceiling value=off"
    xpl-trig_any_any_eib.basic_group_01.01.001_data_0x01="xpl-cmnd dspc-state.home state.basic command=update room=study level=lights object=ceiling value=on"
    xpl-trig_any_any_eib.basic_group_01.01.002_data_0x00="xpl-cmnd dspc-state.home state.basic command=update room=study level=lights object=stand value=off"
    xpl-trig_any_any_eib.basic_group_01.01.002_data_0x01="xpl-cmnd dspc-state.home state.basic command=update room=study level=lights object=stand value=on"
    xpl-cmnd_any_any_state.basic_command_set_room_study_level_lights_object_ceiling_value_off="xpl-cmnd dspc-eib.home eib.basic group=1/1/1 data=0x00"
    xpl-cmnd_any_any_state.basic_command_set_room_study_level_lights_object_ceiling_value_on="xpl-cmnd dspc-eib.home eib.basic group=1/1/1 data=0x01"
    xpl-cmnd_any_any_state.basic_command_set_room_study_level_lights_object_stand_value_off="xpl-cmnd dspc-eib.home eib.basic group=1/1/2 data=0x00"
    xpl-cmnd_any_any_state.basic_command_set_room_study_level_lights_object_stand_value_on="xpl-cmnd dspc-eib.home eib.basic group=1/1/2 data=0x01"
  />
</actions>

The comments in the beginning of the file show the structure of the rules. Each line defines a pattern which, compared to an incoming xPL message, can trigger one or more other messages. The format of these rules has been defined in order to allow to write one per line. If a parameter of a message to be sent contains a space character, that character has to be replaced by an underscore.

The rules are grouped in parts such as pingPong and eib in the preceeding example. This has no effect in the interpretation of the commands: it's only purpose is to structure the XML file and to allow commenting out parts of the configuration items or adding comments in the file.

The configuration file is read anew each time a new xPL message arrives. This allows to edit and update the rules without having to stop and restart the xPL central device.

Test xPL home state device

Test it on a BeagleBone:

su control
SCRIPTS_BASE_DIR=/home/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-homeState.pl -h
$SCRIPTS_BASE_DIR/xpl-homeState.pl -v -n home

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 another terminal and send a message to the serial port:

su control
SCRIPTS_BASE_DIR=/home/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c pingPong.basic message=ping

The monitor should display the ping message, directly followed by a pong message emitted by the xPL central device.

Launch the xPL home state device at startup

The xPL central device is to be launched after the xPL hub.

Ubuntu

On Ubuntu, the xPL central device starts-up once xpl-hub_started has been emitted.

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

################################################################################
# xPL central message parser
#
description "xPL central message parser"
version     "1.0"
author      "Francois Corthay"

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

#-------------------------------------------------------------------------------
# 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-central start
service xpl-central status

SCRIPTS_BASE_DIR=/home/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c pingPong.basic message=ping

Mac OS

On Mac OS, the xPL central device starts-up later than the hub.

Edit /Library/LaunchDaemons/xpl-central.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>xPL central message parser</string>
    <key>OnDemand</key>
    <false/>
    <key>UserName</key>
    <string>control</string>
    <key>ProgramArguments</key>
    <array>
      <string>/Users/control/Documents/Controls/xpl-central.pl</string>
      <string>-n</string>
      <string>lounge</string>
      <string>-w</string>
      <string>25</string>
      <string>-a</string>
      <string>/Users/control/Documents/Controls/centralActions.xml</string>
    </array>
  </dict>
</plist>

Start the device and test it:

su root
launchctl load /Library/LaunchDaemons/xpl-central.plist

SCRIPTS_BASE_DIR=/Users/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c pingPong.basic message=ping