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.
def netcat(hostname, port, content):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
data = s.recv(1024)
if data == "":
print "Received:", repr(data)
print "Connection closed."
netcat ('10.0.0.70', 1001, "\x03LI%s\x0D"%passcode)
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
File "/usr/lib/python2.7/socket.py", line 224, in meth
error: [Errno 111] Connection refused
USER-AGENT: Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0
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.