I have a web application that will constantly post some queries and get replies from a device through the serial port on Raspberry Pi. Like this:

 def login (self, **data):
    passcode = data.get("passcode", None)
    print "logging in using passcode %s"%passcode ,type(passcode)

    import serial
    import time
    #open connection
    serialport=serial.Serial ("/dev/ttyAMA0", 9600, timeout=0.5)
    #write in user sign in code

    print reply, type(reply)
    #check if log in success
    if not "00" in reply[0]:
        if "FE" in reply[0]:
    print state
    return state

Currently I am using direct 3 wires (gnd, txd, rxd) from Raspberry Pi to the device's (gnd, rxd, txd). The serial port of Raspberry Pi is /dev/ttyAMA0 and say the device has an IP of i could send netcat command one at a time like this:

nc 1001
^CLI1234^M  //this is an example of the serial command sent to the device from Raspberry Pi terminal

How should i do it with socat? I don't want to change the script but just to manipulate some configuration in socat (or something else) that would forward the command to the device's IP. I want to get rid of the 3 wires connected to R-Pi UART. i hardly find examples on socat that would suit this requirement (or may be i don't know what keyword i should use). Please enlighten me :) Thanks a lot!

  • Uhm, you have a device connected to the UART using the three wires, and now you want to remove it and still be able to use the disconnected device? Can you clarify on that? (e.g. how is the device currently connected to the RPi and how do you currently access the RPi to use that program?) – Lekensteyn May 16 '13 at 8:24
  • @Lekensteyn yes, the device is currently connected to R-Pi through the 3 wires (gnd-gnd, txd-rxd, rxd-txd) and now i want to remove them but to utilise the ethernet cables of them (which both of them are in the same LAN). the server running on R-Pi is cherrypy. hope that clarifies :) – yvonnezoe May 16 '13 at 8:27
  • Wait, your device in question has an Ethernet connection? And now you want to communicate over TCP with that device, without modifying that python script? Isn't it just easier to adjust that python script to perform TCP? – Lekensteyn May 16 '13 at 8:42
  • @Lekensteyn oh it is easier? sorry i'm clueless for both. :( it seems to me that a lot of codes have to be modified. how should i do it that way? – yvonnezoe May 16 '13 at 8:48
  • Yvonne, have a look on stackoverflow.com and the Python manuals for doing TCP programming in Python. Consult the documentation of your device that is currently hooked to the UART for more details on what protocol is to be used. – Lekensteyn May 16 '13 at 19:45