3

I have connected a device with the raspberry pi on serial port. I can talk to the device from within the raspberry pi (works fine). I am using a dongle to connect raspberry pi to the internet. I can SSH the RPi remotely on port 22.

Now I want to talk to this device (connected on serial port) remotely. This means, I want to be able to open a socket on port 10001 to talk to the device (socket programming). How do I configure raspberry pi so that anything coming on port 10001 goes to the device on serial port. How to map external port 10001 to internal serial port COM5.

  • Do you have some sort of PPP (Point-to-Point Protocol) running on the serial connection? Do understand that you can only port forward to something that has the IP (internet protocol) stack, like a PPP connection between the Pi and what is on the other side of the serial port. If you don't have the IP protocol over that serial, you will have to create some sort of interpreter to accept your IP data and pass it some other way (that is not IP) to the serial connection. – Marco Poli May 2 '14 at 11:23
  • The device is connected on port_name = /dev/ttyUSB0. I want to dedicate a port number to this port name so that I can create a socket for this port. My raspberry Pi has an IP address and device is directly connected on serial port – AL̲̳I May 2 '14 at 11:49
  • I do have ppp installed on my raspberry pi because to connect the dongle I am using sakis3g (raspberry-at-home.com/installing-3g-modem). Is there a way I can change the ppp configuration to forward all traffic on port 10001 to the serial port (i.e. device connect) ? – AL̲̳I May 2 '14 at 12:35
3

You should be able to achieve this with ser2net, without any programming. I've done this successfully with a MAX3232 based serial port. You can install the package directly:

sudo apt-get install ser2net

Once installed edit the configuration file /etc/ser2net.conf. Delete or comment out the existing configuration lines and add something like this:

10001:raw:0:/dev/ttyUSB0:9600 8DATABITS NONE 1STOPBIT -XONXOFF -RTSCTS

This listens on TCP port 10001. You will probably need to adjust the serial parameters but the configuration file is quite well documented. After changing the file restart ser2conf:

/etc/init.d/ser2conf restart

Now anything received on TCP port 10001 will be sent out of the serial port and vice-versa.

I haven't tried this with a USB device but I have tested it successfully with the built-in UART and a MAX3232 device (after disabling ttyAMA0 as a console device; see https://www.abelectronics.co.uk/raspberrypi-serialportusage/info.aspx).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.