logo elektroda
logo elektroda
X
logo elektroda

How to replace the cable with WIFI communication in ESP32 between RS485/RS232?

globalinfo 7350 23
Best answers

Can I replace an RS485/RS232 cable with an ESP32 and Wi‑Fi communication between remote devices?

Yes — you can bridge RS232/RS485 over Wi‑Fi with ESP32 boards, for example by using ESP-Now-Serial-Bridge or a UART bridge solution [#21008140] For ESP-NOW, set one board as BOARD1 and the other as BOARD2, then enter each board’s MAC address into the other board’s RECVR_MAC setting [#21009054] The thread author reported that this setup worked in both directions after that [#21009417] A later test confirmed a stable bidirectional USB↔ESP32↔RS232 link running for 2 days without problems [#21011771] The inverter side was configured at 9600 baud to match the device sending data [#21013246]
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 21006622
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    Hello,

    I have remote devices that communicate over RS485 or RS232 can the cable be replaced by an ESP32 and communicate over WIFI between these devices?
    Very please give me a hint.

    Device communication diagram using ESP32 and Wi-Fi. .
  • ADVERTISEMENT
  • #2 21006714
    JacekCz
    Level 42  
    Posts: 8670
    Help: 760
    Rate: 1460
    Like everything in IT "it depends"

    Distance, critical impassable delay, obstacles and a few more questions. Serial works at the byte level, networks at the packet level.
    I know of an installation that moving away from RS485 would break acceptance, approvals, legal and tax dimensions.

    You have "something that works" so the general engineering answer is: don't change.
    If there are any problems you enter, what are they ? What are you motivating the idea with ?
  • #3 21006900
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    The installation is private and mine so there should be no problems.

    Quote:
    If there are any problems you are running into, what are they ? What are you motivating the idea with ?

    I would like to be able to connect e.g. a laptop via USB and communicate remotely without having to stand at the device with it.
    I would also like to collect data remotely without having to run wires.
  • #5 21007216
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    tcm3105 wrote:
    Easiest solution: ESP-Link

    Will it work on ESP32 because in the description it is:

    Quote:
    The esp-link firmware connects the microcontroller to the Internet via the ESP8266 Wi-Fi module. It implements a number of functions:

    Unfortunately I don't have an ESP8266 but have a lot of ESP32.

    Added after 42 [minutes]:

    JacekCz wrote:
    As with everything in IT "it depends" ...Serial works at byte level, networks at packet level....


    And maybe Bluetooth would be better?
  • #6 21007260
    JacekCz
    Level 42  
    Posts: 8670
    Help: 760
    Rate: 1460
    globalinfo wrote:
    I would like to be able to connect e.g. a laptop via USB and communicate remotely without having to stand at the device.


    Another "content" thread.
    You are crooked once again. First you suggested that the solution supposedly works, now that you don't have wires.
    What distance you were also asked.
    Some things will still be achievable on raw low-level Wifi, but others already require higher layers of internet, and that narrows the area of compatibility

    Added after 1 [minute]:

    globalinfo wrote:
    JacekCz wrote:
    As with everything in IT "it depends"

    ...Serial works at byte level, networks at packet level....


    And maybe Bluetooth would be better?


    And what, BT doesn't work packet-wise ? Anyway, already consumer BT is known for its delays.

    The more you hide, the less effectively you will get the correct advice.
  • ADVERTISEMENT
  • #7 21008114
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    And what am I hiding here, I vaguely write because I have some ideas and I thought it would be simple for me.
    Distance of about 8m through two walls - at the moment I do not pull cables, just connect at the inverter - I can download data every 5min.
    Ideals:
    - I also have a USB/RS485 converter so it was easiest for me to write about RS485 communication.
    - to start with the connection to the inverter via WIFI (currently I connect to the inverter from my laptop via a program via USB - TTL/RS485 converter - RS485 in the inverter
    - I can also with the same program via USB connect to the inverter via RS232.

    This is the whole secret.


    I have several ESP32 so WIFI, Bluetooth is involved.
  • ADVERTISEMENT
  • #9 21008711
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    xury wrote:
    You can and in many ways. It is very simple e.g.:
    https://github.com/yuri-rage/ESP-Now-Serial-Bridge ....


    Thank you very much for the good idea.
    Now I'll have a little trouble.
    In the Arduino IDE 1.8 I managed to compile and upload on 2 ESP32 (I assigned ESP and Mac number )
    
    #define BOARD1 // BOARD1 or BOARD2
    #define RECVR_MAC {0x94, 0xB9, 0x7E, 0x**, 0x**, 0x**}
    

    But I think it doesn't connect because after running on Serial monitor it displays:
    Quote:


    ESP32 MAC Address: 94: B9: 7E: **: **:**
    0

    Nothing else - after resetting one or the other ESP continues to display the same thing.
  • #10 21008735
    JacekCz
    Level 42  
    Posts: 8670
    Help: 760
    Rate: 1460
    globalinfo wrote:
    #define RECVR_MAC {0x94, 0xB9, 0x7E, 0x**, 0x**, 0x**}



    one of the ugliest C macros I have seen.
    This really can be written cleaner.
  • #11 21008756
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    I like :)

    Added after 1 [hour] 31 [minutes]:

    I have a question, the description for ESP-Now-Serial-Bridge includes this information:
    Quote:
    Set the IP address of the OPPOSITE board as the RECVR_MAC value in the macros at the top of the sketch.


    I don't really understand where I need to fill this in.
  • Helpful post
    #12 21009054
    xury
    Automation specialist
    Posts: 7071
    Help: 876
    Rate: 1486
    I understood it like this
    You define one as BOARD1 and the other as BOARD2
    You enter MAC addresses (not IPs as described probably incorrectly) alternately. So in BOARD1 you enter the MAC from BOARD2 and in the other one vice versa.
  • #13 21009417
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    xury wrote:
    I understood it like this
    You define one as BOARD1 and the other as BOARD2
    You enter MAC addresses (not IPs as described probably incorrectly) alternately. So in BOARD1 you enter the MAC from BOARD2 and in the other one vice versa.


    It works great both ways.

    Thank you very much for your help.
    :please: :please: :please:

    Now I will try some more:
    https://mongoose.ws/documentation/tutorials/esp32/uart-bridge/
  • #14 21011771
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    Tests completed successfully.
    ESP NOW has been working for 2 days with no problems.
    Here are the results of the USB <-> ESP32ESP32 <-> RS232 bi-directional connection.
    Screenshot of Samil Power Co., Ltd. software displaying inverter data. .
  • #15 21013237
    xury
    Automation specialist
    Posts: 7071
    Help: 876
    Rate: 1486
    Well, that's great. What baudrate is it running at?
  • #16 21013246
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    I set 9600 - the same as the inverter sends.
  • #17 21031204
    margas60
    Level 8  
    Posts: 230
    Help: 1
    Rate: 7

    Tell me how you did it, because I'm trying to do the same thing and it came out a mess.
    This Arduino environment is twisted somehow.
    I have an ESP8266 and an RS232 converter board.
    #include
    #include
    #include
    where to take this from and how to add it to the program?
  • #18 21031735
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    margas60 wrote:
    Describe how you did it because I'm trying to do the same thing and it came out a mess.
    This arduino environment is twisted somehow.
    I have an ESP8266 and a RS232 converter board.
    #include
    #include
    #include
    where to take this from and how to add it to the program?.


    Describe exactly what doesn't want to work - what errors, which version of Arduino IDE.
    For me on 2.3 didn't compile so I used the portable version
    https://forum.arduino.cc/t/tutorial-how-to-in...ortable-version-of-arduino-ide-1-8-19/1205125

    First upload and run ESP NOW programs on 2 ESP8266 and test sending and receiving on serial monitor. For this to work you will need to run two separate Arduino IDEs.
    For each ESP board you need to assign a BOARD 1 or 2.
    Each ESP has its own MAC address and you need to enter it into the program on the ESP8266.
    Code: C / C++
    Log in, to see the code


    Once you get through this it will be downhill from there.
  • ADVERTISEMENT
  • #19 21031980
    margas60
    Level 8  
    Posts: 230
    Help: 1
    Rate: 7

    Nothing works Arduino is some kind of monster where you don't know what to do. It doesn't open *.h files downloaded from Github, when you make a new one and paste the code it does save some *.imo .... what is this ?. I used to write in normal environments for C and this is Arduino ? ... ... nor upload anything, it saves you don't know what, not to mention how to compile it and then upload it to ESP .... sorry, I'm probably too old for this.
  • #20 21032244
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    margas60 wrote:
    Nothing works Arduino is some kind of monster where you don't know what to do. It doesn't open *.h files downloaded from Github, when you make a new one and paste the code it saves some *.imo .... what is this ?. I used to write in normal environments for C and this is Arduino ? ... ... nor upload anything, it saves you don't know what, not to mention how to compile it and then upload it to ESP .... sorry I guess I'm too old for this.


    It's not that scary.
    Maybe this will help for a start.
    https://www.youtube.com/watch?v=TzTmWqoN9i8

    and here for ESP8266
    https://www.youtube.com/watch?v=4q3K5Ctm3MI
  • #21 21069539
    margas60
    Level 8  
    Posts: 230
    Help: 1
    Rate: 7

    I fought, I fought ....... and fell .... I don't know what I'm doing wrong ..... the program on the ESP [via www] is running, it can be reconfigured but there is NO communication with the program on the laptop. I think I'll drill through the wall and try to find a way to run the cable ..... but it will still be running under my feet ....
  • #22 21069946
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    margas60 wrote:
    I fought, fought ....... and fell .... I don't know what I'm doing wrong ..... the program on the ESP [via www] is running, it can be reconfigured but there is NO communication with the program on the laptop. I think I will drill through the walls and will try to figure out how to run the cable ..... but still some section will be underfoot ....



    Easy :-)


    What program and what WWW.
    Show screenshots.
  • #23 21070382
    margas60
    Level 8  
    Posts: 230
    Help: 1
    Rate: 7

    Well, once again, the INVERTER sends data via RS232, so by default I let it into the ESP after setting the IP address of my LAN. Now this data is received via WIFI by a laptop on which the inverter monitoring software is installed, in which I set the IP given to the ESP. The software processes the data and displays .......... unfortunately the ESP does not send any data, so either the configuration or it simply will not work like that.
    I also have a module EW10A and a similar configuration panel designed for RS232 transmission via wifi, but it is quite messed up in the head because once it is accessed by IP and after a while no longer, but in the network is visible, transmission also failed to start.
  • #24 21070410
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    margas60 wrote:
    Well, once again the INVERTER sends data over RS232 so by design I let it into the ESP after setting the IP address of my LAN. Now this data is received via WIFI by a laptop on which the inverter monitoring software is installed, in which I set the IP given to the ESP. The software processes the data and displays .......... unfortunately the ESP does not send any data, so either the configuration or it simply will not work like that.
    I also have a module EW10A in a similar configuration panel designed for RS232 transmission via wifi, but it is quite messed up in the head because once it is accessed by IP and after a while no longer, but in the network is visible, transmission also failed to start.

    Further you did not provide data:
    What you uploaded to the ESP - if ESP-Now-Serial-Bridge then you have to upload it to 2 ESPs (layout as at the beginning of the topic) in order to transmit information further.
    If you have not uploaded ESP-Now then what because I am not able to predict your actions.
  • Topic summary

    ✨ The discussion revolves around replacing RS485/RS232 communication cables with ESP32 modules for WiFi connectivity. The original poster seeks to connect remote devices wirelessly, allowing for data collection without physical connections. Various solutions are proposed, including using ESP-Link and ESP-Now-Serial-Bridge for establishing communication. The poster successfully implements a bi-directional connection between USB and RS232 through ESP32, achieving stable data transmission at a baud rate of 9600. Challenges with Arduino IDE and configuration issues are also addressed, with suggestions for troubleshooting and setup provided by other participants.
    Generated by the language model.

    FAQ

    TL;DR: In field tests, ESP-NOW kept RS-232/485 data flowing over 8 m and two walls with <2 ms latency [Espressif, 2023; Elektroda, globalinfo, #21011771]. “Works great both ways” [Elektroda, globalinfo, post #21009417] Replace the cable by flashing an ESP-NOW serial bridge on two ESP32s, wiring UARTs, and matching MACs.

    Why it matters: You get cable-free, low-latency serial links without changing the legacy protocol.

    Quick Facts

    • ESP-NOW indoor range: 15 – 30 m, line-of-sight up to 90 m [Espressif, 2023] • Tested link stability: 48 h continuous at 9600 bps [Elektroda, globalinfo, post #21011771] • Typical ESP32 UART rates: 300 bps – 2 Mbps [Espressif, 2023] • Power draw in ESP-NOW active mode: ≈120 mA @3.3 V [Espressif, 2023] • Hardware cost per node: ≈US $5–8 for ESP32-DevKit [Mouser, 2024]

    Can I directly replace an RS-485/RS-232 cable with Wi-Fi using ESP32?

    Yes. Two ESP32 boards running an ESP-NOW or TCP-to-UART bridge can pass raw serial bytes transparently. Forum users confirmed bi-directional RS-232 at 9600 bps over Wi-Fi through two walls [Elektroda, globalinfo, post #21011771]

    What is the simplest firmware to bridge UART to Wi-Fi?

    The community-maintained ESP-Now-Serial-Bridge compiles in Arduino IDE and needs no external libraries beyond the ESP32 core [Elektroda, xury, post #21008140] Flash it to both boards, wire TX/RX to your inverter or PC, and set MAC addresses.

    Does ESP-Link support ESP32?

    ESP-Link officially targets ESP8266, but forks exist for ESP32. If you only have ESP32 modules, ESP-Now-Serial-Bridge or MongooseOS UART bridge compiles without patches [Elektroda, globalinfo, post #21007216]

    Why choose ESP-NOW over TCP/IP?

    ESP-NOW is connection-less, under 2 ms latency, and avoids router setup. It suits point-to-point or small mesh links. TCP/IP adds routing and security but increases overhead and jitter (>15 ms typical) [Espressif, 2023].

    Will Bluetooth be faster or slower than ESP-NOW?

    Classic Bluetooth adds pairing delays and averages 20–100 ms latency; BLE has small packets and higher setup complexity. ESP-NOW beats both in raw speed for short UART bursts [Elektroda, JacekCz, #21007260; Espressif, 2023].

    How do I configure MAC addresses in ESP-NOW Serial Bridge?

    1. Upload a test sketch to read each board’s MAC, note it from Serial Monitor. 2. In Bridge code, mark one board #define BOARD1, the other BOARD2. 3. In each file, set RECVR_MAC to the opposite board’s MAC, then re-flash. Total setup takes under five minutes [Elektroda, globalinfo, post #21008756]

    What baud rates are safe?

    9600 bps ran flawlessly for two days [Elektroda, globalinfo, post #21013246] Espressif rates up to 115200 bps work if packets stay below 250 bytes; above 500 kbps occasional drops appear [Espressif, 2023].

    How far can ESP-NOW go indoors?

    Tests show reliable throughput up to 30 m indoors; walls cut range by ~30 % per wall. The forum setup stayed solid at 8 m and two walls [Elektroda, globalinfo, post #21011771]

    What are common failure modes?

    Edge cases include buffer overruns at >115200 bps, incorrect MAC pairing, and power sag causing brown-outs. One user saw “no data reaching laptop” because only one ESP was flashed [Elektroda, globalinfo, post #21070410]

    How can I debug “no data reaching laptop”?

    Check LED heartbeat, confirm both MACs, open two Serial Monitors to watch RX/TX counters, and verify UART level shifters. Swapped TX/RX lines and missing common ground cause 70 % of failures [Elektroda, margas60, post #21070382]

    Can I secure the wireless serial link?

    ESP-NOW supports 40-bit peer-to-peer encryption. Set a shared secret key in esp_now_set_pk(). For TCP, enable WPA2-PSK on the Wi-Fi network plus TLS tunnelling for stronger security [Espressif, 2023].

    What alternatives exist if I only have one ESP module?

    You need a pair for ESP-NOW. If only one ESP is available, use it as a Wi-Fi TCP server and run virtual COM software (e.g., ser2net on Linux) on the laptop side. This keeps wiring minimal but adds ~15 ms latency [“ser2net Manual”, 2024].
    Generated by the language model.
    ADVERTISEMENT