So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By kmehranh
#64542 I'm trying to transmit 20 frames (each frame size is 307,200 pixels) of a video sequence via UART. I'm using 2 ESP8266 WiFi modules using TCP connection in MATLAB.
To start, I tried sending a sample data 10 times in a for loop. Here is the code:
Code: Select allclc
clear all
delete(instrfindall); % Close serial ports
TestString = char(' Test string: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 '); % data to send

TerminationTerm = 'CR/LF';
TimeOut = .01;
Baud = 115200;

server = serial('COM4','baudrate',Baud);
server.Terminator = TerminationTerm;
server.Timeout = TimeOut;
server.InputBufferSize = 2048;
fopen(server);
fprintf(server,('ATE0')); % Echo off in ESP8266 module
fprintf(server,('AT+CWMODE=3')); %set the module as a client and also an access point.
fprintf(server,('AT+CIPSTO=1')); %set the time out
fprintf(server,('AT+CIPMUX=1')); %set multiple connection
fprintf(server,('AT+CIPSERVER=1,333')); %Open server on port 333

client = serial('COM6','baudrate',Baud);
client.Terminator = TerminationTerm;
client.Timeout = TimeOut;
client.OutputBufferSize = 2048;
fopen(client);
fprintf(client,('ATE0')); %Echo off
fprintf(client,('AT+CWMODE=3'));%set the module as a client and also an access point
fprintf(client,('AT+CIPMUX=1'));%set multiple connection
fprintf(client,('AT+CIPCLOSE=5'));%Close all TCP connections
pause(.1)
flushinput(client);
fprintf(client,('AT+CIPSTART=2,"TCP","192.168.7.7",333'));%Start TCP connection on channel 2 and port 333, CLient cooncts to Server
pause(.1)
fprintf(client,('AT+CIPSTO=1')); %set time out

for counter =  1:10
    flushinput(server);
    flushinput(client);
    fprintf(client,('AT+CIPSEND=2,65'));% Send 65 Bytes on channel 2
    fprintf(client,TestString);% send data
    counter
    fgets(server);
    flushinput(client);
    fgets(client);
    Response = (fgets(server))
end

delete(instrfindall);


But the data isn't sent in all iterations. What should I do?
Results for iterations 6-10:

Code: Select allcounter =

     6

Warning: Unexpected Warning: A timeout occurred before the Terminator was reached.
Warning: Unexpected Warning: A timeout occurred before the Terminator was reached.
Warning: Unexpected Warning: A timeout occurred before the Terminator was reached.

Response =

     ''



counter =

     7

Warning: Unexpected Warning: A timeout occurred before the Terminator was reached.

Response =

+IPD,0,65: Test string: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20


counter =

     8

Warning: Unexpected Warning: A timeout occurred before the Terminator was reached.

Response =

+IPD,0,65: Test string: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20


counter =

     9

Warning: Unexpected Warning: A timeout occurred before the Terminator was reached.

Response =

+IPD,0,65: Test string: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20


counter =

    10

Warning: Unexpected Warning: A timeout occurred before the Terminator was reached.
Warning: Unexpected Warning: A timeout occurred before the Terminator was reached.
Warning: Unexpected Warning: A timeout occurred before the Terminator was reached.

Response =

     ''
User avatar
By daniel_ezsbc
#64560 It's hard to debug code by simply reading it but it appears that your loop that starts with for counter = 1:10 assumes that the ESP8266 can buffer the data during the time it takes to get the data onto the WiFi. This may not be true and you can inadvertently overflow the buffers in the 8266. I suggest you put some delay between the transmit commands and see if the problem goes away. Also, the time taken to send the data with TCP/IP is not fixed because of retries. UDP is more predictable since it doesn't do re-transmits.
User avatar
By picstart
#64564 The AT commands are often a handshaking concept. The user types something in via an AT command and the device responds then the user types something more. It is asynchronous in nature.
It is not that the input it can't be automated it is just hard to synchronize.
Most code is synchronized by posting a request and then getting a callback and explains the popularity of Lua or Arduino code or C with embedded SDK calls.
Many started with the AT stuff but gave it up as soon as code synchronizable via callbacks was developed.
User avatar
By kmehranh
#64586
daniel_ezsbc wrote:It's hard to debug code by simply reading it .


Thanks, Before the loop, initialization for TCP connection is made and in the loop the data is sent, I have added delays but it doesn't make any sense. I don't have access to ESP modules today, I'll try the UDP as soon as possible and post the results here.
Do you know what is the max transfer bit rate?