Compiling Z-Connector for OpenWRT, DD-WRT routers and their clones

Official announcements from Z-Wave.Me team. Check this forum to get information about new releases and bug fixes.
User avatar
PoltoS
Posts: 3738
Joined: 26 Jan 2011 19:36

Compiling Z-Connector for OpenWRT, DD-WRT routers and their clones

Post by PoltoS » 10 Sep 2011 23:55

This short post describes how to compile Z-Connector for OpenWRT family routers.We suppose you are familiar with Linux and with OpenWRT. The following description is not a final script - you will need to edit some variables!# Compiling ipkg package of Z-Connector for OpenWRT and DD-WRT routers and their clones
#
# Be sure to enable IPKG on your router. Some routers require JFFS or external storage to be enabled
#
# Download your personal Z-Connector from www.z-wave.me web site and decopress it on your Linux (we suppose it is Ubunu)
#
# Run this script from the directory of Z-Connector (where Unix and Windows folder are located)

# Install flex utility
sudo apt-get install flex

# Install SVN OpenWRT tree
svn co svn://svn.openwrt.org/openwrt/branches/backfire

cd backfire

# Install feeds
./scripts/feeds update -a
./scripts/feeds install argtable

# copy Z-Connector to the tree
mkdir packages/z-connector
cp -R ../Unix packages/z-connector/src
mv packages/z-connector/src/Makefile_OpenWRT packages/z-connector/Makefile
(cd package/z-connector/src; make clean)

make menuconfig
# select Target System
# save the config

make package/z-connector-compile
make package/openssl-compile
make package/feeds/packages/argtable-compile

# Specify correct ARCH
ARCH=[[Arch]]
OpenWRThost=[[IP]]

# Copy to the router
scp bin/$ARCH/packages/argtable*.ipk bin/$ARCH/packages/z-connector*.ipk bin/$ARCH/packages/libopenssl*.ipk bin/$ARCH/packages/zlib*.ipk root@$OpenWRThost:/tmp

# Install on the router
ssh root@$OpenWRThost ipkg install /tmp/argtable*.ipk /tmp/z-connector*.ipk /tmp/libopenssl*.ipk /tmp/zlib*.ipk

# Now you need to copy Certificates somewhere on the router
scp -r ../Certificates root@$OpenWRThost:[[cert directory]]

# And probably load modules for your stick
ssh root@$OpenWRThost ipkg install kmod-usb-serial-pl2303
insmod pl2303

# or
ssh root@$OpenWRThost ipkg install kmod-usb-core kmod-usb-acm
insmod acm

# Then you can try to start z-connector on your roter using:
root@OpenWRT:/ # CERT_DIR=[[cert directory]]
root@OpenWRT:/ # DEVICE=[[DEVICE]]
root@OpenWRT:/ # z-connector -d $DEVICE -s z-cloud.z-wave.me --cert=$CERT_DIR/cert.pem --key=$CERT_DIR/cert.key --cacert=$CERT_DIR/cacert.pem

# Final step is to make startup script, but this depends on your router! Something like:
#!/bin/bash

# replace [[XXX]] with appropriate value
BIN_PATH=[[path to z-connector]] # path to z-connector binary: /usr/bin/, /jffs/bin, /opt/bin or some other depending on your router
CERT_DIR=[[cert directiry]] # directory where you have stored certificates
DEVICE=[[Device]] # /dev/ttyUSB0, /dev/ttyACM0, /dev/usb/tty/0 or another depending on the Z-Wave hardware and kernel version you have

while [ 1 ] do
$BIN_PATH/z-connector -d $DEVICE -s z-cloud.z-wave.me --cert=$CERT_DIR/cert.pem --key=$CERT_DIR/cert.key --cacert=$CERT_DIR/cacert.pem
sleep 1 # spare the CPU
done
Sooner or later we will make a simple script and share binary for most popular routers. Here are binaries for Asus RT-N16. Don't forget, that you will still need to copy certificates as shown above and make startup script.

grawsom
Posts: 4
Joined: 17 Nov 2011 14:04

Anyone there can help with this to WRT350N v.2

Post by grawsom » 10 Sep 2011 23:55

Have updated my router with OpenWrt Backfire 10.03.1 - but don't know to do the Linux stuff...

User avatar
PoltoS
Posts: 3738
Joined: 26 Jan 2011 19:36

Please try to follow the description above

Post by PoltoS » 10 Sep 2011 23:55

You will need a Linux box to compile Z-Connector for OpenWRT. We are not sure you can do it on Windows. Basically you can even do it on a Live CD of Ubuntu if you download some additional packages like gcc.

filipvervloesem
Posts: 10
Joined: 03 May 2012 12:54

Error in the makefile

Post by filipvervloesem » 10 Sep 2011 23:55

I tried compiling Z-connector and the Makefile seems to contain an error. The following line:
$(INSTALL_BIN) $(PKG_BUILD_DIR)/z-connector $(1)/bin/

should be changed to:
$(INSTALL_BIN) $(PKG_BUILD_DIR)/z-agent $(1)/bin/

I also had to select the option "[*] Build the OpenWrt based Toolchain" in the make menuconfig step, as it's impossible to compily anything without creating the right toolchain for your target architecture first.

I suppose the argtable and libopenssl-packages can also be installed from regular OpenWRT repositories (no need to compile them yourself).

User avatar
PoltoS
Posts: 3738
Joined: 26 Jan 2011 19:36

Thnks for your comments

Post by PoltoS » 10 Sep 2011 23:55

We will fix the typo in Makefile.Yes, you need to compile the whole toolchain before.And you can also install argtable and openssl precompiled pakages. See./scripts/feeds update -a
./scripts/feeds install argtablelines above - they install argtable. OpenSSL libraries are usually pre-installed on all routers, since they are needed for HTTPS and VPN services.

filipvervloesem
Posts: 10
Joined: 03 May 2012 12:54

"Socket has gone" error

Post by filipvervloesem » 10 Sep 2011 23:55

I attached a Z-Wave USB-stick and compiled the latest version of the z-connector (1.02) for DD-WRT, but I'm unable to set up a reliable connection to the zwave.me-server. This is the debug-output of z-agent:

Opening device...
[D] Configuring device...
[D] Creating a socket...
[D] Enabling keep-alives on the socket...
Connecting to server...
[D] Initialising OpenSSL environment...
[D] Allocating SSL context...
[D] Loading personal certificate...
[D] Loading personal certificate key...
[D] Loading CA certificate...
[D] Setting verification mode...
Establishing SSL connection...
[D] Allocating SSL session...
[D] Assigning socket...
Performing SSL handshake...
[D] Initialising SSL state...
[D] Sending handshake...
[D] Server has closed the SSL connection
[D] Shutting down SSL session...
[D] Freeing SSL session...
Establishing SSL connection...
[D] Allocating SSL session...
[D] Assigning socket...
Performing SSL handshake...
[D] Initialising SSL state...
[D] Sending handshake...
Loop started
[D] socket has data
[D] 5 bytes:
[D] 01 03 00 07 FB
[D] socket has data
[D] 5 bytes:
[D] 01 03 00 07 FB
[D] socket has data
[D] 5 bytes:
[D] 01 03 00 07 FB
[D] Server has closed the connection
[E] Socket has gone
Loop ended
[D] Shutting down SSL session...
[D] Freeing SSL session...
[D] Freeing SSL context...

Any idea what's going on here? It looks like a similar issue has already been observed and fixed) for Mac OS X...

User avatar
PoltoS
Posts: 3738
Joined: 26 Jan 2011 19:36

Make sure the port is correct

Post by PoltoS » 10 Sep 2011 23:55

There are two possibilities:
1) The port is a wrong one. Check Run_Z-Agent.sh file to set the correct port
2) You are using not the latest version of Z-Connector. We have updated Z-Connector two days ago fixing this issue for Mac OS X.

It might also be possible that this fix breakes correct work of Z-Connector on DD-WRT. This is to be checked. Please try with the latest version (download again - unfortunately the version number was nt changed - we will fix this next time. If it will not help, we will provide you with previous version to make tests.

filipvervloesem
Posts: 10
Joined: 03 May 2012 12:54

Still the same error

Post by filipvervloesem » 10 Sep 2011 23:55

I recompiled the last version from source and still get the same error. I used following command to run the z-agent on DD-WRT:
/mnt/bin/z-agent -s z-cloud.z-wave.me --cacert /mnt/etc/certs/cacert.pem --cert /mnt/etc/certs/cert.pem --key /mnt/etc/certs/cert.key -d /dev/tty

Meanwhile, I tried to run the Z-Connector on Windows (7) and Mac OS X (10.6). On those systems, I also get the "Socket has gone" error, so it does not seem to be related to DD-WRT.

User avatar
PoltoS
Posts: 3738
Joined: 26 Jan 2011 19:36

/dev/tty is not the correct port

Post by PoltoS » 10 Sep 2011 23:55

It should be /dev/ttyUSBx. Please check the port. On Windows and Mac OS X it was well tested and proved to work, so the problem is certainly in the selected port.

filipvervloesem
Posts: 10
Joined: 03 May 2012 12:54

Fixed by loading required kernel module

Post by filipvervloesem » 10 Sep 2011 23:55

Apparently the required kernel module was not yet properly loaded (I did not notice this earlier). Once I loaded it, a device file /dev/ttyUSB0 was created and now z-agent runs fine. Note I switched to OpenWRT in the mean time as my DD-WRT-installation was a bit outdated. Thanks for the detailed installation instructions!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest