logo elektroda
logo elektroda
X
logo elektroda

TCP-IP / RS485 ESP8266 converter

dktr  54 34110 Cool? (+25)
📢 Listen (AI):

TL;DR

  • An ESP8266-based TCP/IP to RS232/RS485 converter creates remote serial ports for Linux and Windows over LAN or Internet.
  • It extends UARTtransparentbridge code with MAX485 support and is programmed in Arduino IDE.
  • On Linux, socat creates a virtual UART at /dev/espS0, and the build uses an ESP8266 with a MAX485 transceiver.
  • The converter was tested with an ORNO OR-WE-504 indicator.
Generated by the language model.


Simple TCPIP / RS485 converter.
The device allows you to create a remote port rs232 / rs485 in linux and windows systems and allows communication with devices via lan / internet. The project is based on UARTtransparentbridge code, but MAX485 support has been added to it. ESP8266 programmed in ArduinoIDE, source code and "schematic" attached.
On linux, after booting the device, just use 'socat':
Code: Text
Log in, to see the code

When this command is issued, a virtual UART will be created in / dev / espS0.

Tested on the ORNO OR-WE-504 indicator.

Attachments:
  • es-rs485.zip (114.4 KB) You must be logged in to download this attachment.

About Author
dktr
dktr wrote 929 posts with rating 702 , helped 45 times. Live in city Ostróda. Been with us since 2003 year.

Comments

george2002 25 Nov 2017 04:10

Is it something like esp-link? https://hackaday.io/page/1304-virtual-serial-port-tunnel-to-use-with-esp-link because esp-link has a lot of options, only the RS485 support is probably not implemented... [Read more]

dktr 25 Nov 2017 11:02

Yes, it will be the same as ESPlink, in 1200,2400,9600 it works fine but requires changes in the code - serial.begin () I have nothing else with rs485 except this orno indicator, I polled the counter all... [Read more]

jajen 26 Nov 2017 21:28

Does this converter work at 3.3v with esp? It shouldn't because they're at 5v. [Read more]

levy^ 26 Nov 2017 22:15

it should work, but at much shorter distances [Read more]

george2002 26 Nov 2017 23:06

It is enough to replace it with the MAX3485 and everything in accordance with the art and ranges ;) [Read more]

ditomek 27 Nov 2017 08:41

On what basis do you calculate the time needed to control the RE / DE signal? Doesn't cut anything with longer thongs? [Read more]

byrrt 27 Nov 2017 08:57

Not supporting RS485 (DE signal) is not a problem: https://obrazki.elektroda.pl/5164797400_1511769306_thumb.jpg Proven - works, also in many production devices. Added after 1 [minutes]: ... [Read more]

ditomek 27 Nov 2017 11:21

on the first post, re_de is controlled from the ESP pin, so the diagram you pasted later does not make sense. By the way, I use a similar one myself in my projects. I am asking this because in arduino... [Read more]

piterek-23 27 Nov 2017 21:32

And how to select elements when UART works at the 3V3 level? MAX485 to MAX3485, what about the rest? [Read more]

byrrt 28 Nov 2017 13:06

what about the rest? stays the same ... [Read more]

piterek-23 28 Nov 2017 13:24

I meant the transistor and resistors because the entire power supply will change from 5V to 3V3. If nothing needs to be changed that's great, but I preferred to ask. Thanks, I'll be testing soon... [Read more]

uzi18 17 Jan 2018 19:14

There is an esp-link latka with rs485 support, you have to look at repo / issue [Read more]

piterek-23 10 Feb 2018 23:07

Gentlemen, everything works great, but ... but there is a small problem ... If, for example, I reset the router, ESP loses the connection and can not reconnect - just do ESP reset and everything is OK... [Read more]

uzi18 11 Feb 2018 02:02

Are you talking about the software from 1 post? [Read more]

piterek-23 11 Feb 2018 05:10

Yes. [Read more]

dktr 12 Feb 2018 21:00

I made a fix, after breaking the wifi connection, the program waits for reconnection and resumes work. [Read more]

jajen 15 Feb 2018 12:06

Hello, I also use this converter. I get an error compiling this new version es-rs485: 19: error:'earchwifi 'was not declared in this scope How can I fix it? [Read more]

dktr 15 Feb 2018 20:04

I think I broke something and I didn't attach this file, but the one from this attachment compiles without error. Another thing is that ESP itself will reconnect to the network and will work, but... [Read more]

jajen 15 Feb 2018 20:37

Already ok. New version of arduin ide helped. Thanks [Read more]

FAQ

TL;DR: "54 % flash used, all the results are correct" [Elektroda, dktr, #17264295; #16847583]. 1200–9600 baud verified, MAX3485 lets 3.3 V reach full RS-485 length. Inline Wi-Fi auto-reconnect added in v2.

Why it matters: this open-source bridge lets any PC or PLC talk Modbus-RTU over Wi-Fi with parts that cost under €5.

Quick Facts

• Verified baud rates: 1 200, 2 400, 9 600 bps [Elektroda, dktr, post #16847583] • Flash footprint: 238 kB (≈54 % of 434 kB) on generic ESP-12 F [Elektroda, dktr, post #17264295] • Typical current draw: 80–170 mA for ESP-12 F @ 3.3 V (ESP8266 Datasheet) • MAX485 requires 5 V; MAX3485 works 3.0–3.6 V, 52 mA max (Maxim DS3999) • socat command: pty,link=/dev/espS0,raw tcp::8888 [Elektroda, dktr, post #16846354]

What exactly does the ESP8266 TCP-IP/RS485 converter do?

The sketch opens a Wi-Fi TCP server (default port 8888), wraps every byte received on UART0, and forwards it unchanged to the RS-485 transceiver; the reverse path works identically. Your PC sees a virtual serial port created by socat and speaks Modbus-RTU as if a local COM port were present [Elektroda, dktr, post #16846354]

I see “ESP8266WiFi.h: No such file”. What’s missing?

The ESP8266 core libraries are absent. Install the ESP8266 platform through Arduino Board Manager or use PlatformIO’s “framework-arduinoespressif8266” [Elektroda, dktr, post #20320111]

How does the new auto-reconnect work after Wi-Fi loss?

Version 2 waits until Wi-Fi reconnects, then restarts the TCP listener. The MCU stays online, but any socat process must be relaunched from the host side [Elektroda, dktr, post #17032661]

Is there a Windows replacement for socat?

Yes—com0com + hub4com or the free “tty2tcp” utility create a virtual COM port and forward it to the ESP’s IP:8888 endpoint. Operation is identical to the Linux socat string (tty2tcp Manual).

How should I wire DE/RE on a Wemos D1 mini?

Connect RO→D7 (GPIO13), DI→D5 (GPIO14) and tie MAX3485 DE+RE to D2 (GPIO4). Ensure a 10 kΩ pull-down keeps DE low during reset to avoid bus collisions [Elektroda, pela222, post #21101804]

Do I need line termination and bias resistors?

At lengths under 3 m termination rarely improves signals, but once terminators were added the transistor-only DE trick showed severe undershoot [Elektroda, byrrt, post #17047739] Use 120 Ω at both ends plus 680 Ω pull-ups/downs for reliable multi-node buses (Maxim AN1090).

Can the bridge carry Modbus-RTU transparently?

Yes. Send a raw RTU frame over the TCP socket; the ESP adds no header. One user reads a WE-504 power meter by pointing Perl-MBclient directly at 192.168.1.87:8888 [Elektroda, zychzbig, post #21153086]

What happens if socat crashes during long polling?

The ESP keeps its socket open. Frames pile up until the TCP stack resets, causing a visible 1-2 s pause and dropped Modbus queries—an edge case fixed by auto-restarting socat every minute via a shell script [Elektroda, piterek-23, post #17043584]

Any quick test method without real RS-485 hardware?

Loop the ESP’s UART TX to RX and open two terminal windows on the virtual port: characters typed in one echo in the other, proving full duplex operation over Wi-Fi.
Generated by the language model.
%}