Consulting Services
ArticlesEmbedded C & MCU

WiFi-UART Serial Bridge Using ESP8266 or ESP32

Hardware debugging and programming via UART/Serial connection has always been something so vital to hardware developers and even other team players like QA engineers. In certain circumstances, the device that needs to be debugged or programmed is not reachable by wires. I remember how QA engineers in my previous job had to come up with a Bluetooth adapter to bridge the serial debugging information of the tested products because it was fixed inside the car dashboard and can’t be reached out. In this article, it’s time to make some serial data fly over the air!

Serial Bridge Using ESP8266

One of the most well-known (appeared on Hackaday’s blog) and well-designed projects to make ESP8266 as a WiFi-UART bridge is jeelabs’s esp-link. Actually, this project is far beyond being a simple serial bridge as it also manages MQTT client pub/sub and REST HTTP requests in order to connect the MCU to the internet. Moreover, it can be used to flash the attached MCU. Esp-link has a very handy web interface stored inside the ESP.

esp link web

To make the test, we will use ESP8266 development board, specifically NodeMCU.

Prepare The Software

First, we need to download one of the release images of the project from releases page. The compressed file (A .tgz file is beside the download word in bold) should have 5 bin files :blank.bin, boot_v1.x.bin, esp_init_data_default.bin, user1.bin and user2.bin.  The ESP8266 board should be connect after downloading one of the available download tools like: Flash download tool from Espressif or Nodemcu flasher.

Now, follow the flashing guidelines available in Readme file according to your ESP8266 edition and set the bin files addresses according to your module memory size.

nodemcu tool

You can simply make the Flash download tool from Espressif find it for you by connecting it and pressing “start” to get the required specification from the boot message.

esp download tool

Alternatively, you can read the boot message using a serial console with 76600 baud.

esp8266 boot

After flashing the image files successfully, you should see a new WiFi network.

Connect to it and type this IP address into the browser http://192.168.4.1 . Now, you should see the home page.

Prepare The Hardware

To test the serial bridge code, we will achieve the following connection: TX0 from ESP with RX of the device and RX0 with TX of the device that sends serial information and needed to be bridged via WiFi. For the sake of the test, the device here would be a USB-TTL cable (USB-UART converter) and the data will be sent and received from a console (PUTTY for instance).

Image Courtesy of ElecFreaks

Now, let’s see some serial data fly over the air!

Esp-link tx

Esp-link rx

Finally, I think a considered amount of time is needed to explore the other options of this amazing project!

Serial Bridge Using ESP8266 (Simpler)

The previous project could be too complicated to do the simple job of converting Serial connection to a WiFi connection. So I decided to port a project described in the rest of this article written in Arduino. The ported code works on ESP8266 and can be download from here:

The explanation in the next section should be followed to know who to use it but with ESP8266, where simply by using a specific IP/Port via a Tellnet connection, the Serial data can be reached out.

Serial Bridge Using ESP32

A project via Github presents a WiFi to Serial bridge for the 3 UART ports available in ESP32. This project is written using Arduino IDE and supports ESP32 as an access point (AP) that broadcasts a specific WiFi network with predefined SSID and password in the code or a station. However, every UART port on ESP32 is accessible after making a WiFi connection with ESP32 via a specific IP and port.

Let’s prepare the needed software and hardware to test this project.

Prepare The Software

As the project uses Arduino SDK with ESP32 core, then we need to add Arduino core for the ESP32 to the Arduino environment. The official documentation of ESP32 core from Espressif has an installation guide, but the easiest way to add this core is to download the repo as a zip file then decompress it in the following directory:

(Windows) \Documents\Arduino\hardware\espressif\esp32
(Linux) folder is named “Sketchbook” and it is typically located in /home/

The next step is to get the compilation tool-chain xtensa-esp32-elf by executing one of the get.exe or get.py files available in the tools folder according to your machine type.

To test this all together, open the Arduino IDE and check the Tools>boards menu

ESP32 Arduino core boards

Now, testing the compilation of a simple program is needed also. The following test code can be used.

#define PIN_LED 1 // built_in  
void setup() 
{   
pinMode(PIN_LED, OUTPUT);  
}   
void loop() 
{   
digitalWrite(PIN_LED, HIGH);   
delay(1000);   
digitalWrite(PIN_LED, LOW);   
delay(1000);  
}

Prepare The Hardware

ESP32 has many different development boards. The one used here is Goouuu-ESP32 Development Board

Image Source: Aliexpress

And has the following pinout:

esp32 pinmap

Image Source: Espressif Github Repo

To test the serial bridge code, we will do the following connection: TX0 from ESP with RX of the device and RX0 with TX of the device that sends the serial information and needed to be bridged via WiFi. For the sake of the test, the device here would be a USB-TTL cable (USB-UART converter) and data will be sent and received from a console (PUTTY for instance).

Now download the Arduino code from Github and upload it to ESP32. Choose from Tools>boards>ESP Dev Module. Many things can be configured before uploading the code to ESP32 like choosing the working mode as a station or an access point and many other things.

#define MODE_AP // phone connects directly to ESP

//#define MODE_STA // ESP connects to WiFi router

If no changes are done, the bridge will broadcast a WiFi network with SSID “LK8000” and password “Flightcomputer”. Connect to the WiFi network and open the Putty program then use the following setups: one for the Serial connection for the USB-UART converter.

ESP32 putty serial

And another to connect to the WiFi server using one of the following IP/Port according to the used UART port.

  • 192.168.4.1:8880  for UART0
  • 192.168.4.1:8881  for UART1
  • 192.168.4.1:8882  for UART2

Now, open the two consoles and try the magic!

wifi serial esp32

Note: Telnet connection can be done from a smartphone by using Telnet client application like Termius or any other working application.

Telnet mobileExample

Do you need to know more about ESP32? Read this series “All About ESP32”.

Yahya Tawil

Embedded Hardware Engineer interested in open hardware and was born in the same year as Linux. Yahya is the editor-in-chief of Atadiat and believes in the importance of sharing free, practical, spam-free and high quality written content with others. His experience with Embedded Systems includes developing firmware with bare-metal C and Arduino, designing PCB&schematic and content creation.

18 Comments

  1. Hello.

    Is it possible to use it for such a chain: UART ESP32-1 ESP32-2 UART.
    I would like to connect two devices via wi-fi and send \ receive data.

  2. Hi!
    Thank you very much for this. How do I use this to display my programatically generated debug serial messages from my sketch?
    Typing in the wifi and COM terminal windows work as expected, but the messages that my sketch sends to the COM terminal is not mirrored in the wifi putty connection.

    Is there any way to display those messages over the wifi terminal?

  3. Hi,
    I tried something like that but I blocked on some limitation.. I need to connect UART @1,2Mbps and send A LOT OF DATA in continue!
    So my data are OK @ 250kbps but @ 1,2Mbps there is a lot of errors :/
    Anybody did try that ?
    What can I do to make it better ?
    Maybe on IDF ?
    Thanks for your help,

  4. Hi. I tried your project on ESP32. In config.h changed the speed to 115200. There was a problem when transmitting large amounts of data . The first 12 kB file is transmitted normally. Then, after a pause, the same file is transmitted with errors. The further you go , the more mistakes you make . Then it stops transmitting even single bytes at all. It looks like the memory is filling up somewhere and not being cleared. I couldn ‘t figure out the code myself. Can you help? A very necessary device

  5. Hi.
    I am trying to use the simple version (not ESP-LINK) but it does not compile when i uncomment the UDP definition
    //#define PROTOCOL_TCP
    #define PROTOCOL_UDP
    It gives me the below error
    /home/hendrix/paparazzi/wifi-serial/wifi-serial.ino: In function ‘void loop()’:
    wifi-serial:175:13: error: ‘TCPClient’ was not declared in this scope
    if (TCPClient[num][cln])
    ^
    wifi-serial:199:14: error: ‘TCPClient’ was not declared in this scope
    if(TCPClient[num][cln])
    ^
    Using library ESP8266WiFi at version 1.0 in folder: /home/hendrix/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/libraries/ESP8266WiFi
    exit status 1
    ‘TCPClient’ was not declared in this scope

    Basically i am trying to build a transparent serial connection in order to connect to a datalink server that can use UDP instead of the normal serial port like /dev/ttyUSB0.
    Chris

  6. Hai, great project. I am very interested in the WiFi-Serial ESP8266 code however the file is empty/invalid! Can you update this please? Thank you for your kindness 😉 Kind regards, Erwin.

    1. Thank you very much for reporting this. It is fixed now. The download manager blocked .ino files after last update.

  7. Hello
    Loaded the simple version in a nodemcu
    What is the password to use (because it is not password free at the moment)?

    1. found out that the password was: 123456789 . Made the wifi connection with the AP.
      Gott it working: putty terminal on a PC com-port (serial setting) and TCP telnet terminal on the wifi side (Serial_wifi 192.168.4.1:8880). Could send and receive ascii characters vice versa.
      In the Arduino scetch I also entered my home network SSID and Password before compiling and uploading. But i did not see the unit appear on my home network.
      How to accomplish that?
      Also: how can I upload and download files via this setup?

  8. Hello,
    I have EEG data available via a UART interface. I need to use the ESP Wifi to read data from UART and send it via WiFi Direct to a PC. I need to be able to copy the data and then use an application. Do I need a special application on the ESP device as well as the PC to effect this ? Or a regular TCP socket application will work ?

    Thanks & Regards,
    Sn

  9. In “Serial Bridge Using ESP8266 (Simpler)” I downloaded wifi-serial.ino and tested it with success. But wifi-serial waits until there is a newline before it send the string to the serial out. My question: is there a way to do this on character base?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button