Difference in esp-01 and esp-12e while implementing serial to wifi bridge

Akshay Deshmukh
Posts: 1
Joined: Sun Feb 25, 2018 1:36 am

Difference in esp-01 and esp-12e while implementing serial to wifi bridge

Postby Akshay Deshmukh » Sun Feb 25, 2018 1:49 am

I am having a project where I use ESP8266 as a serial-to-wifi bridge. I send data serially from a python code running on windows7 to esp8266(esp-01) which it sends to a wifi client running on windows7 again. While sending a pdf file (79 KBs) in a similar fashion, I (due to limiting RAM), opted for a method where i receive serially chunks of file and send it to wifi immediately after receiving. This keeps on happening inside the loop until all the bytes of file are successfully transferred from serial to wifi. Doing this, initially esp8266(esp-01) was loosing some bytes sometimes. I figured there is somehow a mismatch between wifi transfer speed and serial baudrate which results in overflow of serial buffer and thus, loss of few bytes rendering final output file corrupt. So, I reduced baudrate from 500000 to 250000 and things worked fine confirming my theory. The issue is when I am running same code in esp8266(esp-12e), the baudrate 250000 is not enough and it still looses bytes. Further, reducing baudrate to 115200 makes things work almost fine (9 times success and one time lost bytes) while with 9600 baudrate file transfer is 100% success. But baudrate below 250000 is already slower as per my requirement.
My questions are:
1- Is my theory correct? Theory that serially data is coming too fast while receiving it and sending to wifi immediately takes some time, combined with a little slower wifi speed is resulting in overflow of serial buffer sometimes and thus, loss of bytes. (decreasing of baudrate did worked in both hardwares which sort of proves this point but I am not sure)

2- Why the same code do not work fine in esp-12e? Is there any difference in there wifi controller or handling or something else? I created a hotspot in both hardwares and checked their speed which is same (54 Mbps), so it may not be wifi speed but then what?

3- How to overcome this?

A simple version of code i used for testing is as follows:

python code on windows7 (python 3.6):

Code: Select all

import serial
import time

ser = serial.Serial('COM4', 250000, timeout=300)
with open("C:/Users/aatibui/Desktop/current/output.pdf", "rb") as f:
   read_done = f.read()


ESP8266 code:

Code: Select all

#include <ESP8266WiFi.h>

const char* ssid = "atomic";
const char* password = "int1234";

WiFiServer server(23);
WiFiClient client;

void setup() {

  WiFi.begin(ssid, password);

  Serial.print("\nConnecting to ");

  while (WiFi.status() != WL_CONNECTED) delay(500);

  Serial.print("Ready! Use 'telnet ");
  Serial.println(" 23' to connect");


void loop() {
  if (server.hasClient()) {
    if (!client || !client.connected()) {
      if (client) client.stop();
      client = server.available();
      while (client.connected()) {
        while (Serial.available()) {
          size_t len = Serial.available();
          uint8_t sbuf[len];
          Serial.readBytes(sbuf, len);

Wifi Client code (jdk7):

Code: Select all

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Arrays;
import java.io.DataInputStream;

public class ClientArduinoFile_1 {
     public static final int BUFFER_SIZE = 20*1024;
     private byte[] buffer;
     public ClientArduinoFile_1() {
          buffer = new byte[BUFFER_SIZE];

     public void startClient() throws Exception {
          Socket socket = new Socket("", 23);
        BufferedInputStream in =
               new BufferedInputStream(socket.getInputStream());

        BufferedOutputStream out =
               new BufferedOutputStream(new FileOutputStream("C:/Users/aatibui/Desktop/test123.pdf"));
          int len = 0;
        int counter = 0;
        int bytes = 0;
          while ((len = in.read(buffer)) > 0) {
            System.out.print("bytes: "+len);
            bytes += len;
            System.out.print(" ; total: "+bytes);
            out.write(buffer, 0, len);
               System.out.print(" # ");
               System.out.println("reached end of file");

     public static void main(String[] args) throws Exception {
          ClientArduinoFile_1 test = new ClientArduinoFile_1();


The circuit diagram of connection for esp-01 and esp-12e:
ckt dia.jpeg

Her Mary
Posts: 476
Joined: Mon Oct 27, 2014 11:09 am

Re: Difference in esp-01 and esp-12e while implementing serial to wifi bridge

Postby Her Mary » Tue Feb 27, 2018 2:57 pm

Maybe you can test it with enabling UART hardware flow control, connect the CTS and RTS, enable it by command AT+UART.

Who is online

Users browsing this forum: No registered users and 3 guests