God is good. He will open up the right opportunity at the right time. 🙂
Today I went back to my Industrial Attachment Company to continue working on the Raspberry Pi web server. Previously I was using the serial port and now I have successfully convert the program to use socket with Ethernet port. Now it can communicate with Comfort Home Automation system!
My boss is very kind to help me set up a port in the company router so that I can access the web app from anywhere. Yay, tomorrow I can demo it to my Prof. 🙂
It’s so tiring today. I didn’t do much tonight, basically just wasted my whole night away.
Good night world.
When following some tutorials to test something on Raspberry Pi, there are some codes available online and they are a whole bunch of characters to type! There is a risk that you might type wrongly! So how to copy and paste those codes into Raspberry Pi terminal?
Here’s how I do it. I usually browse those tutorials using my laptop so I can just CTRL+C to copy those codes.
Then I start PuTTY to start SSH with Raspberry Pi. Unfortunately I can’t CTRL+V into the terminal. The right way to do it is to right click on the terminal. The codes are pasted right away. 😉
Also, notice that CTRL+C in the terminal will kill a process but if you select some texts and press CTRL+C, the texts will get copied and the process will get killed as well.
Some people say Shift+CTRL+C/V works but not for my case. 😦
When you are running and testing a web server (e.g cherrypy) on Raspberry Pi, and there is an error in your codes. You did not shutdown the server nor kill the application properly. You fixed the error and reload it. Tadaa! You get an error saying that the port is not freed and you do not know what to do! Solutions on the internet say “find the app Process ID (PID)”… but how exactly should you find it out of no where??
Or you are testing your new raspberry Pi camera. Opps it hangs and it is on forever. You cannot turn it off, you cannot use it for another test. How to kill it??
This will return you the PID number (4 digits) of that app (e.g 4908)
Raspberry Pi is now good to go for another test. 😉
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.
I always think that being thoughtful is something sweet and the least thing one can do as a loving spouse. But I am a person who deeply in need of appreciation. I will stop doing something that is deemed unappreciated. I am being realistic and yet I would fantasize about how a blissful life should look like. I want a simple yet fruitful and meaningful life. I want someone who could keep my mind occupied with all his merit points so that I will love him even more every single day. I want to feel needed and yet I need a strong sense of security. I like being proud for who I am with. I like to be praised by the one who matters most. I want to be hugged like a little child, to be pampered like a princess, and to be loved like no one else.
I dislike broken promises. I dislike sweet-talks that keep me waiting and pondering. I dislike false hopes. I dislike distrust. I dislike waiting time. I dislike the breaking of hopes, the shattering of dreams. I dislike being ignored. I dislike insensitivity. I dislike rejection.
Ethernet connection + python + data transmission?
Here are some reference links that might help in solving my problems with sending ASCII commands through the Ethernet port using Python script in Raspberry Pi.