Arduino ESP32 Based (Ethernet-WIF) TCP/IP Serial Device

I have a fully functioning TCP/IP Serial device using the LILYGO® POE ESP32-WROOM development board as my starting point. T-Internet-POE – LILYGO®

Basically, I am able to connect my serial ASCII device via a "Local" TCP/IP with Ethernet or WIFI. I am using a freeware application called TeraTermPro to test the local
TCP/IP device. All is well to this point.
image

However, I have a request from someone who wants to connect (10) of my devices to a network and wants to assign all of these devices with the local servers IP address and port 6767. He is currently using the Lantronix xPort device which has a locally assigned device IP address and also includes a "tunnel" IP address and port number which is what he uses to enter the local servers IP address and port 6767.

I am looking for advice on how to connect multiple of my Arduino ESP32 devices to a local server assigning each device the same local server IP address and port # 6767.

Do the Arduino libraries support "tunnel" modes?
Any help would be greatly appreciated..

I'm struggling to understand what you have and what you are asking.

The port number is easy, if you want to use port 6767 then just modify your code to use port 6767.

I think what you are describing, but it's far from clear, is that you have multiple sites, with one site that has a server, which can be considered central to all the other sites. The sites are linked by VPNs. Is this correct? If no please clarify.

Ok, here is the reply I received from Lantronix describing the "Tunnel" mode I am trying to implement with my Arduino ESP32 based design. I hope this helps describes the issue better. I appreciate any and all the advice, thank you all..

Thank you for contacting Lantronix Technical Support.

There are two modes of operation in Xpico/xPort: Tunnel Connect and Tunnel Accept. The difference between these two modes is the direction of the connection initiation. In Tunnel Accept mode, the connection is initiated by the remote client, while in Tunnel Connect mode, the connection is initiated by the Xpico/xPort device.

In Tunnel Accept mode, the Xpico/xPort device listens for incoming connections from a remote client. Once a connection is established, the device can communicate with the client through the tunnel.

In Tunnel Connect mode, the Xpico/xPort device initiates a connection to a remote server through a tunnel. Once the tunnel is established, the device can communicate with the server as if it were directly connected to it. In Tunnel Connect Mode, Xpico/xPort acts as a TCP Client. The application running on the PC acts as a TCP Server and listens on a particular port number. This can be tested with terminal emulation programs like Hercules Setup Utility, Teraterm, and Putty.

For example, let's assume there's a serial device connected to Xpico/xPort serial port and you want to send data to a PC running Hercules Setup Utility. In order to do that, you would select the Tunnel Connect mode and enter the IP address of the PC where Hercules is running and the port number listening (in our case it's 12345). So whenever the serial device sends data, it sends it to the Hercules Setup Utility. You can run your application instead of Hercules Setup Utility.

Regarding your question about the "Tunnel 1" IP address and port number, they are actually the "Remote" IP address and "Remote" IP Port number of the remote server where Xpico/xPort initiates the connection attempt and sends the data.

By default, Xpico/xPort will assign itself an IP address in the range 169.254.x.x if it does not get an IP address from a DHCP server (router). To find Lantronix device servers, the PC running Device Installer (DI) should have an IP address in the same range as the Xpico/xPort that you are trying to discover.

IPAddress remoteHost(xxx,xxx,xxx,xxx);  // IP address of the remote service
uint16_t portNumber = 21;               // FTP standard port number
WiFiClient client;
    if (client.connect(remoteHost, portNumber)) {
           // here you are connected, you can use the documented FTP protocol to discuss with the service
    }

I could be wrong, however, I believe I can ADD a "Remote Host and Port" to my existing project ? I am not sure if this is the solution, or how to implement it?

I can confirm now, that the mode I need to implement is "Tunnel Connect" mode.

So, at least now I understand what I need, I just don't know how to implement it using the Arduino ESP32?

In Tunnel Connect mode, the Xpico/xPort device initiates a connection to a remote server through a tunnel. Once the tunnel is established, the device can communicate with the server as if it were directly connected to it. In Tunnel Connect Mode, Xpico/xPort acts as a TCP Client. The application running on the PC acts as a TCP Server and listens on a particular port number. This can be tested with terminal emulation programs like Hercules Setup Utility, Teraterm, and Putty.

you mix 3 things into one here

  1. accessing a server in Internet from Arduino in local network.
  2. accessing the Arduino in local network from Internet over the Internet router
  3. doing 1 or 3 over a special dispatcher server. it is useful for 2), but not for 1).

they call "tunnel connect" when the dispatcher forwards the connection from the device to Internet. this is not very useful, since every device from local network can access the Internet.

they call it Tunnel Accept if the access to the device is thru the dispatcher. this is useful because you have only allow on router access from Internet to the dispatcher and not every device.

EDIT: I wrote this before you added your previous comment

The only useful information I can provide is that you can change the port to whatever you need by changing the value of portNumber as required.

@Juraj has given you a better answer than I can. The information he has given is beyond my understanding. The best I can offer is that I think you need a VPN and to suggest that your router could be configured to create one. However, typical routers provided with domestic internet connections do not generally support VPNs and even if they do I have such a poor understanding of what you are trying to do that I might be telling you something irrelevant and wrong.

What you are asking for is too far outside my expertise for me to be properly helpful, sorry. I hope someone else can help.

Hi Juraj,

Thank you for your reply.

Ok, I have confirmed that the user is configuring the Lantronix xPort
with the "Tunnel Connect" option.

Below is a description, from the user, on how their application configures the
Lantronix xPort. I am trying to find a way to program the Arduino ESP32 to function
in an equivalent way.

USER:
For all locally hosted installations, we use the local server's IP and the default port of 6767 .

If we are using ISCorp, then we use ISCorps public IP address and the local specific port number.

That is all we change.

So, using the Lantronix xPort in "Tunnel Connect" Mode, they enter in the local server's IP address and the default port of 6767 for locally hosted installations.

When using ISCorp, then we use ISCorps public IP address and the local specific port number.

So, the Arduino ESP32 Ethernet device plugs into the Ethernet network using DHCP dynamic mode and is connected and given a local device IP address, then it needs to
create a "Tunnel Connect" type of IP address and port number using the local server's IP address and the default port 6767, or it needs to use the ISCorps public IP address and a locally specific port number.

Apparently, this is how the Lantronix xPort operates.

The only Arduino ESP32 code I found so far, refers to adding a "RemoteHost, and port number", I am not sure if that would work or not.

For the "Tunnel Connect" mode, I am just not sure what code to use?

WiFiClient.h
    IPAddress remoteIP() const;
    IPAddress remoteIP(int fd) const;
    uint16_t remotePort() const;
    uint16_t remotePort(int fd) const;
IPAddress remoteHost(xxx,xxx,xxx,xxx);  // IP address of the remote service
uint16_t portNumber = 21;               // FTP standard port number
WiFiClient client;
    if (client.connect(remoteHost, portNumber)) {
           // here you are connected, you can use the documented FTP protocol to discuss with the service
    }

sorry I am confused.
do you really ask about the most basic thing one can do with an Arduino WiFi library?
connect to a server and send or get some data?
so then see the WiFiClient example of the ESP8266 WiFi library

Hi Juraj,

I haven't found anything in the libraries using the term "Tunnel Connect", so I am just asking the more advanced programmers, how I could implement the "Tunnel Connect"
option.

The Lantronix xPort uses both, a local device IP address and also a "Tunnel Connect" IP address at the same time. I am not sure of the ESP32 is capable of that.

I just looking for advice

every device has a an iP address.
by "using local IP" you mean "have a server"?
and by "using remote IP" you mean "connect to other device"?

"tunnel connect" is just a marketing name from Lantronix .

Hi Juraj,

Thank you so much, I seriously appreciate the advice, I was confused by the terminology.
I probably should have done a better job describing things myself.

My device is a simple Ethernet or WIFI pinpad with LCD display.

A user can configure the Ethernet settings for my device using the WIFI SoftAP and, when the user saves their settings, the ESP32 resets itself and reboots in Ethernet mode using the users settings. Currently, I only support DHCP and STATIC IP modes.

Problem:
One of my users wants it operate the same as the Lantronix device they are using now.

The Lantronix device connects to the local Ethernet using DHCP and then "also" uses, what Lantronix refers to, as a "Tunnel IP and port number" at the same time.

My user currently configures (10) or more of the Lantronix xPort devices to their local server's IP and the default port of 6767, or they enter the ISCorps public IP address and the local specific port number.

So, all (10) devices share the same IP address and port number.

The user enters into the Lantronix "Tunnel IP and port fields" their local server's IP and the default port of 6767, or they enter the ISCorps public IP address and the local specific port number.

What I am still a little confused about is, how I would implement that same functionality using the Arduino ESP32 ?

Can I connect to the local Ethernet using DHCP, and also connect to the local server's IP and the default port of 6767, or the ISCorps public IP address and the local specific port number at the same time like Lantronix does?

I apologize in advance if these questions seem ignorant.

I still don't understand what is the problem, but I have a feeling you ask something very obvious me. Did you look at the WiFiClient example?

Do you understand the basics of how a LAN and WAN work? Like @Juraj I am not clear what you are asking, but I think part of the problem for you is a fundamental lack of basic understanding of a LAN. Without that knowledge explaining anything else won't help much.

This worries me:

You cannot have more than one device on a LAN with the same IP address. Think of a street where all the houses have exactly the same address: how would that work? How would deliveries get to the right house? They would not.

Hi Perry,

I confirmed with Lantronix technical support that, yes, their xPort device
initiates a DHCP dynamic local IP connection when it is plugged into an Ethernet Network, this allows the device access to the network.

Then the device initiates a 2nd remote IP and remote port that actually handles the TCP connection and data send/receive. Lantronix refers to this as a "Tunnel Port".

So, you are correct that each device needs a unique local IP, however, my user explained to me that they are indeed currently using the 10 or more Lantronix xPort devices and all of them are programmed to connect directly to either the local server's IP address and default port of 6767, or to the ISCorps public IP address and the local specific port number.

Each device has a unique HEADER ID byte that it sends with any data it has to transmit. The application receives packets, and it can tell which device the data came from based on that unique header ID byte. Each device is set up to only respond to data from the host application when the HEADER matches it's own ID byte.

Thank you for the information. I don't know if it is because you are up against the limits of my knowledge or if the explanation isn't good enough, but either way I don't know what to say to help. Hopefully @Juraj can be more helpful.

Hi Perry,

Thank you very much for all of your help...
I am still not sure how to get the ESP32 to perform the same way as the
Lantronix xPort device does. It may not be possible with the existing libraries
I am using and may require me to hire someone to custom program the libraries?

Sounds to me like you just need to give your end users a way to configure their server ip and port..
The Lantronix is a serial to ethernet bridge, sounds like it raises a webserver for configuring the device, got 2 mode from what you described it can act as a server or a client, their use of the word tunnel is confusing the subject..
Sounds like you need client mode, connecting to their server..

Now, just my opinion, dhcp'ing and having the end user try to figure out assigned ip with no display could be an issue, you could allow for config through the usb serial..
Maybe on boot, spit out current config and prompt for changes..

Otherwise, yes, you need a webserver that configures the client connection parameters, server ip and port..

for esp32, look at the preferences lib for saving and restoring values..
Esp32 Preferences..

good luck.. ~q