roboremo/ESP8266-WiFi-UART-Bridge

How fast can it transparent?

while0l1 opened this issue · 9 comments

How fast can it transparent?And will it lost data when sending a big data(10+k)?

#define bufferSize 8192

Olny 8 k buffer ...
If change this in file...

#define bufferSize 8192

Olny 8 k buffer ...
If change this in file...
I want to send photos from stm32 to PC through 8266, and I've set the buffer to 1024×30, but I found some data will lost if I don't pause the stm32 after sending one photo. (My baudrate is 256000)

You want 1024 x 30 =30kb If you sent 6 packet of 5k? Στις Δευ, 15 Απρ 2019, 16:19 ο χρήστης while0l1 notifications@github.com έγραψε:

#define bufferSize 8192 Olny 8 k buffer ... If change this in file... I want to send photos from stm32 to PC through 8266, and I've set the buffer to 1024×30, but I found some data will lost if I don't pause the stm32 after sending one photo. (My baudrate is 256000) — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#2 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AcyDJIjl4E8ubfIxUMLQbrngjt6rKbEqks5vhHx6gaJpZM4cupOc .

You want 1024 x 30 =30kb If you sent 6 packet of 5k? Στις Δευ, 15 Απρ 2019, 16:19 ο χρήστης while0l1 notifications@github.com έγραψε:

#define bufferSize 8192 Olny 8 k buffer ... If change this in file... I want to send photos from stm32 to PC through 8266, and I've set the buffer to 1024×30, but I found some data will lost if I don't pause the stm32 after sending one photo. (My baudrate is 256000) — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#2 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AcyDJIjl4E8ubfIxUMLQbrngjt6rKbEqks5vhHx6gaJpZM4cu

You want 1024 x 30 =30kb If you sent 6 packet of 5k? Στις Δευ, 15 Απρ 2019, 16:19 ο χρήστης while0l1 notifications@github.com έγραψε:

#define bufferSize 8192 Olny 8 k buffer ... If change this in file... I want to send photos from stm32 to PC through 8266, and I've set the buffer to 1024×30, but I found some data will lost if I don't pause the stm32 after sending one photo. (My baudrate is 256000) — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#2 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AcyDJIjl4E8ubfIxUMLQbrngjt6rKbEqks5vhHx6gaJpZM4cupOc .

I've tried this way, and it works. But it will be more complex for stm32 to pack the data. I thought TCP is fast enough to transmit the data. Maybe I was wrong. :(

Thx for sharing this bridge code, unfortunately the current implementation has some issue with performance and lose of data during transmission, if the data that needs to be bridged is bigger than some kilobytes (>30kB). Over the weekend I played with various baud rates and various buffer sizes, but I had no luck transferring the data in a safe way. My setup consists of a esp8266 d1 mini and should be used as a bridge to get access to a remote tty of a PI via picocom. Additionally some file transfers via zmodem (rz, sz) would come handy to transfer files of some mega bytes in size.
Then I found some other implementation here and I took the algorithm that is used there and adapted it to yours regarding the names of variables. A closer look on the methods used there:

  • copy whole buffers instead of looping over each byte (esp internal serial HW buffer only 128 bytes in size + some SW buffer 256 bytes (default))
  • no delay required after reading from serial (which also could force serial buffer overflows and loose of data)

With those changes transferrates up to 230400 bps without loosing bytes work fine on the esp d1 mini.

Below the changes that are needed (else path of the preprocessor hash-if's).

macro used below


#ifndef min
#define min(x,y)  ((x)<(y)?(x):(y))
#endif

additional variables used


uint16_t bytesIn1 = 0;
uint16_t bytesIn2 = 0;

reading from tcp socket and passing over to serial:


#if 0
	while (client.available()) {
		buf1[i1] = (uint8_t)client.read(); // read char from client (RoboRemo app)
		if (i1 < bufferSize - 1) i1++;
	}
	// now send to UART:
	Serial.write(buf1, i1);
	i1 = 0;
#else
	i1 = 0;
	while ((i1 = client.available()) > 0) {
		bytesIn1 = client.readBytes(buf1, min(sizeof(buf1), i1));
		if (bytesIn1 > 0) {
			Serial.write(buf1, bytesIn1);
		}
	}
#endif

reading from serial and passing over to tcp socket:


#if 0
	while (1) {
		if (Serial.available()) {
			buf2[i2] = (char)Serial.read(); // read char from UART
		if (i2 < bufferSize - 1) i2++;
		} else {
			//delayMicroseconds(packTimeoutMicros);
			delay(packTimeout);
			if (!Serial.available()) {
				break;
			}
		}
	}

	// now send to WiFi:
	client.write((char*)buf2, i2);
	i2 = 0;
#else
	i2 = 0;
	while ((i2 = Serial.available()) > 0) {
		bytesIn2 = Serial.readBytes(buf2, min(sizeof(buf2), i2));
		if (bytesIn2 > 0) {
			client.write((uint8_t*)buf2, bytesIn2);
		}
	}
#endif

UDP could be changed in a similar way.