charleslinquist
Posts: 112
Joined: Wed Sep 05, 2012 12:43 pm

telnet to serial

Wed Sep 04, 2019 8:08 pm

I need a program that will run in a Raspberry that contacts a remote telnet server via name or ip and port, and after it connects, transfer that connection to serial0 so I can use an RS-232 connection from then on

All the similar programs I have found make the Raspberry the telnet host, and remote devices connect to it and use the Raspberry's serial port..

I need the reverse. The Raspberry needs to be the telnet client, which then connects to a specific host.

I have tried to write such a program in Python, but it does not work properly.

Andyroo

Re: telnet to serial

Wed Sep 04, 2019 8:16 pm

How about using the telnet package?

Code: Select all

sudo apt install telnet
Manual is https://linux.die.net/man/1/telnet
or installed locally and accessible with:
man telnet

trejan
Posts: 1092
Joined: Tue Jul 02, 2019 2:28 pm

Re: telnet to serial

Wed Sep 04, 2019 10:08 pm

socat will do it. You need to look up the exact set of options to do it though. It'll be something like

socat TCP:192.168.1.2:1234 FILE:/dev/ttyAMA0,b115200,raw,echo=0,min=0

charleslinquist
Posts: 112
Joined: Wed Sep 05, 2012 12:43 pm

Re: telnet to serial

Thu Sep 05, 2019 12:15 am

When I try

socat - TCP:35.160.169.47:23 /dev/serial0,b115200

I get the response "exactly 2 addresses required, (there are 4)

I can't follow the examples well enough to get this to work.

charleslinquist
Posts: 112
Joined: Wed Sep 05, 2012 12:43 pm

Re: telnet to serial

Thu Sep 05, 2019 12:31 am

Doing better.

I'm getting some output with

socat TCP:35.160.169.47:23 FILE:/dev/serial0,b115200

Now I just have to fine-tune the parameters.

User avatar
HermannSW
Posts: 1758
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: telnet to serial

Thu Sep 05, 2019 9:27 am

Perhaps not what you want, but you can connect to Raspberry serial via USB2TTY:
https://www.raspberrypi.org/forums/view ... 3&t=156541

You can then use minicom or screen tools to login to Raspberry and "telnet" on Raspberry to connect to target.

I learned that it is important to get 5V from USB, but use USB2TTY with 3.3V setting in addtion for serial:
Image


That was first attempt, not good because of 5V to serial:
Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

charleslinquist
Posts: 112
Joined: Wed Sep 05, 2012 12:43 pm

Re: telnet to serial

Thu Sep 05, 2019 2:39 pm

Thanks for your reply. Your approach won't work for me. I have an unusual application. I need to essentially make a unlimited length RS-232 connection. I have RS-232 devices on each end that cannot deal with any extraneous characters. The connection needs to be "self-healing", that is when the connection is broken, it must be seamlessly re-established without user intervention. I believe I can achieve that with socat.

blimpyway
Posts: 201
Joined: Mon Mar 19, 2018 1:18 pm

Re: telnet to serial

Fri Sep 06, 2019 8:48 pm

Despite this is an PI forum. I had good experience using ESP8266 with esp-link firmware to get a TCP to serial connection..

https://github.com/jeelabs/esp-link`

PS however it is a port listener it doesn't actively open sockets to remote servers.

charleslinquist
Posts: 112
Joined: Wed Sep 05, 2012 12:43 pm

Re: telnet to serial

Fri Sep 06, 2019 9:37 pm

I am successfully running SER2NET in a Raspberry (Raspberry #1). That works great for connecting the Raspberry's serial port to the net. That Raspberry has a static ip. I need to use another Raspberry (#2) to automatically telnet to Raspberry #1 - in effect, to connect their serial ports together. The network connection between #1 and #2 can easily "break" and I need it to re-establish connection after an interruption with no user intervention. I realize that data will be lost during the disconnect, but that is OK. I don't have to deal with logins and passwords because the Raspberry's are both running VPN software.

Return to “Networking and servers”