To start, I tried sending a sample data 10 times in a for loop. Here is the code:
clc
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:
counter =
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 =
''