B4R Question ESP to ESP Serial and Astream

rodmcm

Active Member
Licensed User
I am having trouble with a simple ESP to ESP serial comms. The enclosed is a cut down from a larger project passing 200 int values (MV) from one ESP to another.. To demonstrate the problem I am passing these one at a time. At a high baud rate the best I can do is 27 reads of 200 sends. (Serail2.zip is the sender and Serial1.zip the receiver programs)

Each send is via a SendArray(20) with SendArray(0) being a key (3 in this case) to the type of data being sent

Played with changes to the #StackBufferSize, MaxBufferSize and baud rate with little effect.

Of note in Capture 1 the buffer length changes from 23 to 24 and then fails on the be(60) call

Any help appreciated.. I've been on this simple thing for ages.

(As a footnote the reason I am using two ESP is one to transmit WIFI and one as a straight processor with I2C involved.. If I use WIFI and I2C in one ESP I get continuous crashes!)


Two other clarifications please.

a) Is there another way of coding ser.ConvertArraytoBytes) for say SendArray(20) rather than

Serial1_astream.write(ser.ConvertArrayToBytes(Array(SendArray(0),SendArray(1),SendArray(2),SendArray(3),SendArray(4),SendArray(5),SendArray(6),SendArray(7),SendArray(8),SendArray(9),SendArray(10),SendArray(11),SendArray(12),SendArray(13),SendArray(14),SendArray(15),SendArray(16),SendArray(17),SendArray(18),SendArray(19))))

b
) I realize I can pack more variables into SendArray(20) to reduce the number of sends for 200 variables but is there a more efficient way of sending 200 variables
 

Attachments

  • Capture.JPG
    Capture.JPG
    27.2 KB · Views: 209
  • Capture1.JPG
    Capture1.JPG
    22.4 KB · Views: 199
  • Serial1.zip
    1.3 KB · Views: 218
  • Serial2.zip
    1.4 KB · Views: 214

rodmcm

Active Member
Licensed User
Thanks for that
The problem turned out to be the size of the serial buffer, changed as per attached


B4X:
    #if C
//HardwareSerial Serial1(1); // Second Hardware Port        ' Pins i/o 25 (RXD2) and i/o 26 (TXD2)
void SerialNative1(B4R::Object* unused)
{
HardwareSerial Serial1(1);  // Nextion Port
#define SERIAL1_RXPIN 25
#define SERIAL1_TXPIN 26

  ::Serial1.begin(57600, SERIAL_8N1, SERIAL1_RXPIN, SERIAL1_TXPIN);
  ::Serial1.setRxBufferSize(1024);
b4r_main::_serialnative1->wrappedStream = &::Serial1;
}
#End If
 
Upvote 0
Top