Difference between revisions of "X10 Integration"

From SecuriWiki
Jump to: navigation, search
m (formatting)
m (fixing wrapping)
 
(12 intermediate revisions by one user not shown)
Line 2: Line 2:
 
There is <b><big>unofficial</big></b> support for integration with X10 using the mochad package.
 
There is <b><big>unofficial</big></b> support for integration with X10 using the mochad package.
  
<font color="red"><big>Usual disclaimer, use at your own risk. This has been tested on two devices so far to my knowledge, and I am not responsible if it breaks yours.</big></font>
+
<font color="red"><big>Usual disclaimer, use at your own risk. This has been tested on 3 devices so far to my knowledge, and I am not responsible if it breaks yours.</big></font>
 +
 
 +
This has been most recently tested to work with firmware R070. When upgrading, you may have to reinstall (following all below instructions, your mochad.conf should be unaffected by the upgrade).
  
 
== Installation ==
 
== Installation ==
Line 11: Line 13:
 
You may use my host as the package repo for opkg (just please don't hose it ^_^):
 
You may use my host as the package repo for opkg (just please don't hose it ^_^):
 
http://remote.thejanky.org/mirrors/almondplus/packages/
 
http://remote.thejanky.org/mirrors/almondplus/packages/
To use this, edit /etc/opkg.conf in your favorite editor and replace the first url, as that one doesn't point anywhere. If you want to use the other unofficial repo, you can switch it back after you do this installation.
+
To use this, edit /etc/opkg.conf in your favorite editor and prepend the file with:
 +
<code><pre>src/gz snapshots http://remote.thejanky.org/mirrors/almondplus/packages/</pre></code>
 +
If you want to use the other unofficial repo, you can switch it back after you do this installation.
  
 
Then install some dependencies and mochad.
 
Then install some dependencies and mochad.
Line 20: Line 24:
 
</pre></code>
 
</pre></code>
  
Udev does not currently have an init script, so we have to make one and start it:
+
The above installation should do everything for you now. If for some reason it didn't, refer to [[#Old Installation]].
<code><pre>
+
cat <<EOF >/etc/init.d/udev
+
#!/bin/sh /etc/rc.common
+
START=38
+
  
start() {
+
If you are utilizing the X10 mapping or LimitlessLED mapping, you will need to configure your map (and LLED hub information) in /etc/mochad.conf. If you are just using it for tcp connections/push notifications, you should be all set!
    /sbin/udevd --daemon
+
    /sbin/udevadm trigger
+
    /sbin/udevadm settle
+
}
+
EOF
+
chmod +x /etc/init.d/udev
+
/etc/init.d/udev enable
+
/etc/init.d/udev start
+
</pre></code>
+
 
+
Finally, enable and start mochad:
+
<code><pre>
+
/etc/init.d/mochad enable
+
/etc/init.d/mochad start
+
</pre></code>
+
  
 
== Using Mochad ==
 
== Using Mochad ==
Line 81: Line 66:
  
 
To see your current device list with device IDs, look at /DeviceList.xml on your A+.
 
To see your current device list with device IDs, look at /DeviceList.xml on your A+.
 +
 +
=== HTTP Interface ===
 +
I wrote a tiny perl script to interface with mochad, in case you prefer that to TCP (and since all dependencies already exist on the Almond+). This is now automatically installed by the package, but I am leaving the code here as an example/reference.
 +
 +
<code><pre>
 +
#!/usr/bin/perl -w
 +
use warnings;
 +
use strict;
 +
use IO::Socket::INET;
 +
use CGI;
 +
 +
my $q = CGI->new();
 +
print $q->header();
 +
 +
if (! $q->param()) {
 +
  exit();
 +
}
 +
 +
my $sock = IO::Socket::INET->new(
 +
        PeerHost => '127.0.0.1',
 +
        PeerPort => '1099',
 +
        Proto    => 'tcp'
 +
        );
 +
die "Cannot connect to the server $!\n" unless $sock;
 +
 +
my $req = $q->param('q') . "\n";
 +
my $size = $sock->send($req);
 +
shutdown($sock, 1);
 +
 +
my $resp = "";
 +
$sock->recv($resp, 1024);
 +
print "$resp\n";
 +
 +
$sock->close();
 +
</pre></code>
 +
 +
<code><pre>
 +
chmod +x /www/cgi-bin/mochad.pl
 +
</pre></code>
 +
 +
Then you can send any command as an HTTP GET request to the parameter "q":
 +
<code><pre>
 +
http://<ALMOND_IP>/cgi-bin/mochad.pl?q=AP 1 on
 +
</pre></code>
 +
 +
or if you can't do spaces (%20 = space):
 +
<code><pre>
 +
http://<ALMOND_IP>/cgi-bin/mochad.pl?q=AP%201%20on
 +
</pre></code>
 +
 +
== Upgrading ==
 +
When upgrading the Almond+, you may have to follow the installation instructions again.
 +
 +
== Uninstalling ==
 +
You should be able to uninstall with opkg (<code>opkg remove mochad</code>). You may have to delete the conf file manually (/etc/mochad.conf).
  
 
== References ==
 
== References ==
Line 92: Line 132:
 
My fork:
 
My fork:
 
https://sourceforge.net/u/armattillo/mochad/ci/master/tree/
 
https://sourceforge.net/u/armattillo/mochad/ci/master/tree/
 +
 +
 +
== Old Installation ==
 +
You may use my host as the package repo for opkg (just please don't hose it ^_^):
 +
http://remote.thejanky.org/mirrors/almondplus/packages/
 +
To use this, edit /etc/opkg.conf in your favorite editor and replace the first url, as that one doesn't point anywhere. If you want to use the other unofficial repo, you can switch it back after you do this installation.
 +
 +
Then install some dependencies and mochad.
 +
<code><pre>
 +
opkg update
 +
opkg install libusb-1.0 usbutils
 +
opkg install mochad
 +
</pre></code>
 +
 +
Udev does not currently have an init script, so we have to make one and start it:
 +
<code><pre>
 +
cat <<EOF >/etc/init.d/udev
 +
#!/bin/sh /etc/rc.common
 +
START=38
 +
 +
start() {
 +
    /sbin/udevd --daemon
 +
    /sbin/udevadm trigger
 +
    /sbin/udevadm settle
 +
}
 +
EOF
 +
chmod +x /etc/init.d/udev
 +
/etc/init.d/udev enable
 +
/etc/init.d/udev start
 +
</pre></code>
 +
 +
Finally, enable and start mochad:
 +
<code><pre>
 +
/etc/init.d/mochad enable
 +
/etc/init.d/mochad start
 +
</pre></code>

Latest revision as of 03:43, 31 May 2016

There is unofficial support for integration with X10 using the mochad package.

Usual disclaimer, use at your own risk. This has been tested on 3 devices so far to my knowledge, and I am not responsible if it breaks yours.

This has been most recently tested to work with firmware R070. When upgrading, you may have to reinstall (following all below instructions, your mochad.conf should be unaffected by the upgrade).

Installation

You may install it manually by compiling from source, copying over the binaries, etc, or you can use opkg. Links are posted at the end for the manual method, I will simply state the opkg method here.

You can probably do most if not all of this from the OpenWRT web interface, but the method I am describing here requires ssh access and basic shell knowledge.

You may use my host as the package repo for opkg (just please don't hose it ^_^): http://remote.thejanky.org/mirrors/almondplus/packages/ To use this, edit /etc/opkg.conf in your favorite editor and prepend the file with:

src/gz snapshots http://remote.thejanky.org/mirrors/almondplus/packages/

If you want to use the other unofficial repo, you can switch it back after you do this installation.

Then install some dependencies and mochad.

opkg update
opkg install libusb-1.0 usbutils
opkg install mochad

The above installation should do everything for you now. If for some reason it didn't, refer to #Old Installation.

If you are utilizing the X10 mapping or LimitlessLED mapping, you will need to configure your map (and LLED hub information) in /etc/mochad.conf. If you are just using it for tcp connections/push notifications, you should be all set!

Using Mochad

To interact with mochad directly, you send commands via TCP on port 1099. The commands are of the form:

SYSTEM DEVICE COMMAND [PARAMETERS]

Systems

  • AP - Almond Plus controlled devices
  • RF - X10 RF module
  • PL - X10 Powerline module
  • LL - LimitlessLED module

Devices

All devices for each system should be supported.

  • AP - Device id (numerical, 1, 2 ...)
  • X10 RF/PL - X10 Device specification, House Code & Unit Code (e.g. A4, C6)
  • LL - LimitlessLED group number (1-3)

Commands

To see your current device list with device IDs, look at /DeviceList.xml on your A+.

Example Commands

# Turn A+ device 1 on
echo "AP 1 on" | nc localhost 1099
# Turn A+ device 2 off
echo "AP 2 off" | nc localhost 1099
# Get switch status of A+ device 1 (ugly, I know)
echo "AP 1 get_val 1" | nc localhost 1099

Controlling Almond+ using X10 RF Controllers

If you want to be able to control LimitlessLED or Almond+ devices using X10 RF Controllers, you will need to modify the /etc/mochad.conf. This file specifies mappings from X10 device codes to Almond+ device and LLED group IDs.

To see your current device list with device IDs, look at /DeviceList.xml on your A+.

HTTP Interface

I wrote a tiny perl script to interface with mochad, in case you prefer that to TCP (and since all dependencies already exist on the Almond+). This is now automatically installed by the package, but I am leaving the code here as an example/reference.

#!/usr/bin/perl -w
use warnings;
use strict;
use IO::Socket::INET;
use CGI;

my $q = CGI->new();
print $q->header();

if (! $q->param()) {
  exit();
}

my $sock = IO::Socket::INET->new(
        PeerHost => '127.0.0.1',
        PeerPort => '1099',
        Proto    => 'tcp'
        );
die "Cannot connect to the server $!\n" unless $sock;

my $req = $q->param('q') . "\n";
my $size = $sock->send($req);
shutdown($sock, 1);

my $resp = "";
$sock->recv($resp, 1024);
print "$resp\n";

$sock->close();
chmod +x /www/cgi-bin/mochad.pl

Then you can send any command as an HTTP GET request to the parameter "q":

http://<ALMOND_IP>/cgi-bin/mochad.pl?q=AP 1 on

or if you can't do spaces (%20 = space):

http://<ALMOND_IP>/cgi-bin/mochad.pl?q=AP%201%20on

Upgrading

When upgrading the Almond+, you may have to follow the installation instructions again.

Uninstalling

You should be able to uninstall with opkg (opkg remove mochad). You may have to delete the conf file manually (/etc/mochad.conf).

References

Related forum topics: http://forum.securifi.com/index.php/topic,1913.0.html http://forum.securifi.com/index.php/topic,615.msg7006.html#msg7006

Original Mochad project: http://sourceforge.net/projects/mochad/

My fork: https://sourceforge.net/u/armattillo/mochad/ci/master/tree/


Old Installation

You may use my host as the package repo for opkg (just please don't hose it ^_^): http://remote.thejanky.org/mirrors/almondplus/packages/ To use this, edit /etc/opkg.conf in your favorite editor and replace the first url, as that one doesn't point anywhere. If you want to use the other unofficial repo, you can switch it back after you do this installation.

Then install some dependencies and mochad.

opkg update
opkg install libusb-1.0 usbutils
opkg install mochad

Udev does not currently have an init script, so we have to make one and start it:

cat <<EOF >/etc/init.d/udev
#!/bin/sh /etc/rc.common
START=38

start() {
    /sbin/udevd --daemon
    /sbin/udevadm trigger
    /sbin/udevadm settle
}
EOF
chmod +x /etc/init.d/udev
/etc/init.d/udev enable
/etc/init.d/udev start

Finally, enable and start mochad:

/etc/init.d/mochad enable
/etc/init.d/mochad start