Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
The steps to get Clipsal’s Cgate2 running on Raspberry Pi. This assumes that you have a fresh out the box Raspberry Pi model B and already have Toolkit installed and working on a windows machine. The Pi is setup as a headless device connected to the C-Bus network. I have a PCI and so used a USB to Serial converter to connect the USB port on the Pi to the serial port of the PCI. In everything that follows it assumes you are you are user “Pi” on the Raspberry Pi. These are my notes but I got a huge amount of help from those that went before… 1. Make sure your Pi is up to date: First step it to ensure your Pi is up to date. Make sure you have an internet connection and run; sudo apt-get update Followed by: sudo apt-get upgrade sudo apt-get dist-upgrade This may take a few minutes. 2. Now give your Pi a static IP address: To do this edit the network interface configuration file; sudo nano /etc/network/interfaces It should look like this; iface lo inet loopback iface eth0 inet dhcp Change dhcp to static and on the following lines the address, netmask and address of your router or gateway, in my case the file looks like this; iface lo inet loopback iface eth0 inet static address 192.168.0.104 netmask 255.255.255.0 gateway 192.168.0.1 Use Ctrl X to exit. Type Y when prompted to save. Now reboot. 3. Now install TightVNC so you can manage the Pi remotely: Make sure you are connected to the internet and then type; sudo apt-get install tightvncserver When this completes, start the server; vncserver You will be asked to create a password for remote connections – do so. When asked to create a view only password, say No. Now install TightVNC viewer on your windows machine and log on to the Pi. In the remote host connect dialogue on the windows machine, enter the fixed IP address you configured above followed by :1. In my case “192.168.0.104:1” You should now be able to see the Pi’s desktop. 4. Now to start TightVNC every time the Raspberry Pi boots so you can log in remotely: Create a new file in the init.d directory: sudo nano /etc/init.d/tightvncserver.sh Enter the following script: #!/bin/sh # /etc/init.d/tightvncserver VNCUSER='pi' case "$1" in start) su $VNCUSER -c '/usr/bin/tightvncserver :1' echo "Starting TightVNC Server for $VNCUSER " ;; stop) pkill Xtightvnc echo "TightVNC Server stopped" ;; *) echo "Usage: /etc/init.d/tightvncserver {start|stop}" exit 1 ;; esac exit 0 Give the script executable permission: sudo chmod 755 /etc/init.d/tightvncserver To start or stop the server; sudo /etc/init.d/tightvncserver start sudo /etc/init.d/tightvncserver stop To make the TightVNC server start each time the Pi boots; sudo update-rc.d tightvncserver defaults 5. Next you need to install Java for ARM: Get the Java download from : http://jdk8.java.net/fxarmpreview/ I downloaded the .gz file to my windows machine and then transferred it to the home directory “/home/pi” Pi using the file transfer utility “WinSCP”. Make sure you are logged-on as Pi and in “/home/pi” directory and then create a new directory where we will install the JDK files to eventually. sudo mkdir -p -v /opt/java Next, unpack the Oracle JDK .gz file using this command tar xvzf ~/jdk-8-ea-b36e-linux-arm-hflt-29_nov_2012.tar.gz The unpacking process may take some time. It unpacks all the contents of the Oracle JDK tz file to a new directory named "jdk1.8.0" located in “/home/pi”. With the unpack complete move the new unpacked directory to the Java install location that we created earlier under "opt/java". sudo mv -v ~/jdk1.8.0 /opt/java Delete the original .gz file as it is no longer needed rm ~/jdk-8-ea-b36e-linux-arm-hflt-29_nov_2012.tar.gz To complete the JDK installation let the system know there is a new JVM installed and where it is located. Use the following command. sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/jdk1.8.0/bin/java" 1 Finally need to tell the system that we want this JDK to be the default Java runtime for the system. sudo update-alternatives --set java /opt/java/jdk1.8.0/bin/jav Now java is installed. To test and verify we can execute the java command using the version argument. java -version You should get the following response: That's it the Oracle JDK is installed and ready for use. Next configure a JAVA_HOME environment variable. Add the following line to you "/etc/environment" using the nano text editor. JAVA_HOME="/opt/java/jdk1.8.0" Also, edit your "~/.bashrc" file using this command nano ~/.bashrc and add the following two lines to the bottom of the file and save. export JAVA_HOME="/opt/java/jdk1.8.0" export PATH=$PATH:$JAVA_HOME/bin Reboot to apply the export to your environment. 6. Now to install C-Gate2 Copy the entire C-Gate2 directory from where it is installed on your windows machine using WinSCP to /home/pi/C-Gate2 on the Raspberry Pi. Make sure C-Gate2 and all sub directories have RW permission. You are now ready to run C-Gate, type: sudo /home/pi/C-Gate2/ java –jar –noverify cgate.jar You should see something like this: To check that all is well, type the cgate command “noop” you should get a response of “200 OK”. 7. Now make C-Gate start at boot time and stop at shutdown. The same type of script used above for TighVNC , this is one I found on the net and adapted with bits from JulianC’s post on the Clipsal CIS forum. Create the script with: sudo nano /etc/init.d/cgate.sh And then copy in the following: #!/bin/sh # # Starts and stops the c-gate server on Raspberry Pi, user Pi CGATEDIR="/home/pi/C-Gate2" CGATEJAR="$CGATEDIR/cgate.jar" CGATEPID="$CGATEDIR/cgate.pid" JAVARE="/opt/java/jdk1.8.0/bin/java" PARAMS="-jar -noverify $CGATEJAR" LOCKFILE="$CGATEDIR/cgate.lock" exho -n "$CGATEJAR" startcgate() { echo -n "Starting C-Gate server:" cd $CGATEDIR start-stop-daemon --start \ --make-pidfile --pidfile $CGATEPID \ --chuid pi \ --exec $JAVARE \ --chdir $CGATEDIR \ -- $PARAMS & echo "." } stopcgate() { echo -n "Stopping C-Gate server:" start-stop-daemon --stop --quiet \ --pidfile $CGATEPID echo "." } case "$1" in start) startcgate ;; stop) stopcgate ;; restart) stopcgate startcgate ;; *) echo "Usage: /etc/init.d/cgate (start|stop|restart)" exit 1 ;; esac exit 0 Once you've saved your file, make sure that it's executable by running "chmod 755 /etc/init.d/cgate.sh". Then to make it run at startup: sudo update-rc.d /etc/init.d/cgate.sh Now each time your Pi boots, C-Gate will start. To connect from a remote machine to Cgate: The IP address of the remote machine (the machine on which you are running C-Bus Toolkit) must be in /C-Gate2/config/access.txt. The access.txt file must then be loaded into memory using the Cgate command “ACCESS LOAD access.txt”. Currently I have it configured for IP addresses 192.168.0.2 to 192.168.0.6 inclusive. Now try logging into C-Gate from a your windows machine using C-Bus Toolkit. Under the file menu disconnect from the local repository and then select connect to remote c-gate using the fixed ip address you gave your Pi earlier. I have 36 C-Bus devices in our house and that database takes about eight seconds to load from the Pi. 8. Now to connect the Pi to C-Bus: To do this, need to sort out the serial port connection between the Pi and the Clipsal C-Bus serial interface. This is done with a utility that redirects a TCP socket to the serial port, “ser2sock”. This section comes from “cheekymonkey” on the cbus forum. First get the software wget http://www.nutech.com/images/fbfiles/files/ser2sock.c Then build it sudo cc -o ser2sock ser2sock.c Now move it to the right place sudo mv ser2sock /usr/local/bin/ Now create a startup script so that it runs at boot time sudo nano /etc/init.d/ser2sock Copy in the following code #! /bin/sh # /etc/init.d/ser2sock ### BEGIN INIT INFO # Provides: ser2sock # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Accept simultaneous tcp connections and fwd them to a serial port # Description: A simple script to start / stop the serial port network interface at boot / shutdown. ### END INIT INFO # Carry out specific functions when asked to by the system case "$1" in start) echo "Starting ser2sock" # run application you want to start /usr/local/bin/ser2sock -d -p 10001 -s /dev/ttyUSB0 -b 9600 ;; stop) echo "Stopping ser2sock" # kill application you want to stop killall ser2sock ;; *) echo "Usage: /etc/init.d/ser2sock {start|stop}" exit 1 ;; esac exit 0 Save the file and now set the correct permissions for it to execuite sudo chmod 755 /etc/init.d/ser2sock Now set it to run automatically at boot time sudo update-rc.d ser2sock defaults I used a USB to serial converter based on the prolific chip, it worked without problem. That should be it!