First up, I need to give a huge thanks to this blog post on how to install c-gate on the raspberry pi Addicted to Pi. This was critical in getting my Clipsal C-Bus CNI talking to my openhab server.
I'll expand a bit on the process here, being more specific to my own setup. Initially you need to ssh to your pi in order to install the software.
It's probably best to check the clipsal c-bus website for the latest download, if this link doesn't work then you should google it and check you're downloading the latest version. Find it here.
If you know your bash code then these next few pieces will be familiar, if not don't worry. You can always ask questions in a forum or on stack overflow.
Write the following lines into your ssh terminal window:
- wget https://updates.clipsal.com/ClipsalSoftwareDownload/mainsite/cis/technical/CGate/cgate-2.11.4_3251.zip
- unzip cgate-2.11.4_3251.zip
- sudo mv cgate /usr/local/bin
You now need to add a startup script for C-Gate. The cbus forums are a help here(particularly this thread)
Enter 'sudo nano /etc/init.d/cgate' to your terminal and it will open the nano text editor. If you've never used this then it's worth doing some research.
I added a startup script for C-Gate. The cbus forums are a help here (particularly this thread)
sudo nano /etc/init.d/cgate
#!/bin/sh
### BEGIN INIT INFO
# Provides: cgate
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $portmap
# Should-Stop: $portmap
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
test -x /usr/local/bin/cgate/cgate.jar || exit 0
CGATEDIR=/usr/local/bin/cgate
CGATEJAR=$CGATEDIR/cgate.jar
CGATEPID=$CGATEDIR/cgate.pid
JAVARE=/usr/bin/java
PARAMS=”-Djava.awt.headless=true -jar -noverify $CGATEJAR”
LOCKFILE=”$CGATEDIR/cgate.lock”
case “$1” in
start)
echo -n “Starting C-Gate server:”
cd $CGATEDIR
start-stop-daemon –start \
–chuid pi \
–chdir $CGATEDIR \
–make-pidfile –pidfile $CGATEPID \
–exec $JAVARE \
— $PARAMS &
echo “.”
;;
stop)
echo -n “Stopping C-Gate server:”
start-stop-daemon –stop –quiet \
–pidfile $CGATEPID
if [ -e $CGATEPID ]
then rm $CGATEPID
fi
# rm $CGATEPID
# rm $LOCKFILE
echo “.”
;;
restart)
echo -n “Restarting C-Gate server:”
cd $CGATEDIR
start-stop-daemon –stop –quiet \
–pidfile $CGATEPID
# rm $CGATEPID
# rm $LOCKFILE
start-stop-daemon –start \
–chuid pi \
–chdir $CGATEDIR \
–make-pidfile –pidfile $CGATEPID \
–exec $JAVARE \
— $PARAMS &
echo “.”
;;
*)
echo “Usage: /etc/init.d/cgate (start|stop|restart)”
exit 1
;;
esac
exit 0
Change permissions on cgate folder and on the startup script:
sudo chown -R pi:pi /usr/local/bin/cgate
sudo chmod +x /usr/local/bin/cgate/cgate.jar
sudo chmod 755 /etc/init.d/cgate
sudo update-rc.d cgate defaults
If on Debian Jessie you’ll need this instead:
sudo nano /etc/systemd/system/cgate.service
And paste this in:
[Unit]
Description=cgate[Service]
ExecStart=/usr/bin/java -Djava.awt.headless=true -jar -noverify /usr/local/bin/cgate/cgate.jar
Restart=always
User=root
Group=root
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/usr/local/bin/cgate/[Install]
WantedBy=multi-user.target
I used the C-Bus Toolkit from a windows laptop to set up and map my CNI projects. You can download it from the clipsal website here and install it on a windows computer. You then need to enable access on the raspberry pi:
sudo nano /usr/local/bin/cgate/config/access.txt
Then add a line, using the ip address of your windows computer (you can get this by typing ipconfig on your windows command line or by clicking on your windows network and clicking the properties of your internet connection):
remote XXX.XXX.XXX.XXX Program
Save, then restart cgate:
sudo service cgate restart
In order for me to access the CNI, I had to change the ip address to match the raspberry pi's ethernet ip address. To do this I typed ifconfig to find the pi's ethernet settings, in my case the IP address was 169.254.188.1 with subnet mask 255.255.0.0.
I had to use the cbus toolkit and a direct LAN connection to the CNI in order to change the ip address of the CNI to align with my raspberry pi. I gave it the ip address of 169.254.188.2 and the same subnet mask. You have to use the control systems IP utility tool (pictured below) from the C-Bus toolkit.Now you can connect with your windows laptop using File>Connect to
Remote C-Gate… with the IP address of your Pi and whatever name you want to choose. Create a new project and add a CNI network using the CNI ip
address and the port 10001 (pictured below).
Edit the c-gate config file so that your default project loads:
sudo nano /usr/local/bin/cgate/config/C-gateConfig.txt and set the project.default and project.start lines to your project’s name.Once you're connected via a windows connection, you can test the lights to see if you can switch them on and off and map the clipsal system.
I’ll post another tutorial on how to connect the openhab server to the lights and create a phone app to control them. I'll start with some openhab fundamentals and then how to connect the Tradfri lights.
0 Comments