Yes it works!

I had stop doing the integration of Raspberry Pi with Comfort system since I completed my Industrial Attachment last June. It is until recently that my FYP requires me to demonstrate the extendability of Raspberry Pi to other home automation system that I come back to the office and retouch the project I left over.

I used the UART of Raspberry Pi to perform serial communication with Comfort system. My boss had been telling me that it would be better if we could use the Ethernet connection instead. I wasn’t very clear of how it should work because the boards and the serial connection have been haunting me for months. I did not even know what keywords to search for in Google.

Yesterday, when I came back to the office again, greet by the friendly smile of my ex-colleagues, sat on the same chair, facing the same laptop and oh hello RaspberryPiServer we meet again.😀

I had a fresher mind after the serial connection failed me and I find it tedious to borrow everything out from the office. I think it would be better if I can remotely access it and demonstrate that to my Profs. So I did a quick search on how to send netcat command in Python and these are some of the results that I found. Today I got a UCM Ethernet module and tested the connection using Comfigurator – works fine! Then using SSH in the terminal, i connect RPi to the UCM using netcat.

nc 10.0.0.70 1001 //nc followed by the IP address and port number

It is able to connect to UCM so I tried to log in by typing CTRL+V+C LI1234 CTRL+V+M and it returns LU01 which states log in success as user 1.

Next, I tried the following codes which I found here.

import socket
import time

def netcat(hostname, port, content):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((hostname, port))
s.sendall(content)
time.sleep(0.5)
s.shutdown(socket.SHUT_WR)

while 1:
data = s.recv(1024)
if data == "":
break
print "Received:", repr(data)
print "Connection closed."
s.close()

netcat ('10.0.0.70', 1001, "\x03LI%s\x0D"%passcode)

UCM replies LU01 - success!

UCM replies LU01 – success!

It is able to turn on the test light as well but when I tried to use the browser button to send command, it no longer work.:/ This is what i get:

[09/Jan/2014:14:26:53] HTTP Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cprequest.py", line 656, in respond
response.body = self.handler()
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/lib/encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cpdispatch.py", line 34, in __call__
return self.callable(*self.args, **self.kwargs)
File "eth_test2.py", line 243, in start
netcat ('10.0.0.70', 1001, "\x03O!0100\x0D")
File "eth_test2.py", line 227, in netcat
s.connect((hostname, port))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 111] Connection refused

[09/Jan/2014:14:26:53] HTTP
Request Headers:
Content-Length: 13
PRAGMA: no-cache
REFERER: http://10.0.0.132:8080/
HOST: 10.0.0.132:8080
CONNECTION: keep-alive
CACHE-CONTROL: no-cache
Remote-Addr: 10.0.0.190
ACCEPT: */*
USER-AGENT: Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0
X-REQUESTED-WITH: XMLHttpRequest
ACCEPT-LANGUAGE: en-US,en;q=0.5
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
ACCEPT-ENCODING: gzip, deflate

Update: eth_test4.py is now able to control the output test lights using the browser’s button.😀 – i separated the start and request function to have 2 separate netcat functions in them.

3 comments

  1. Thank you very much for posting your work. I have always wanted to correct the clock on our system and was inspired by your work. I managed to write a python script to syncronise the clock, and will set up a cron job to correct perhaps once a week.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s