Skip to content

Commit 471beb5

Browse files
author
Veijo Pesonen
committed
Adds handling of ERROR OOB
1 parent 3651eb1 commit 471beb5

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

ESP8266/ESP8266.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ESP8266::ESP8266(PinName tx, PinName rx, bool debug, PinName rts, PinName cts)
5959
_parser.oob("WIFI ", callback(this, &ESP8266::_oob_connection_status));
6060
_parser.oob("UNLINK", callback(this, &ESP8266::_oob_socket_close_err));
6161
_parser.oob("ALREADY CONNECTED", callback(this, &ESP8266::_oob_conn_already));
62+
_parser.oob("ERROR", callback(this, &ESP8266::_oob_err));
6263

6364
for(int i= 0; i < SOCKET_COUNT; i++) {
6465
_sock_i[i].open = false;
@@ -418,6 +419,10 @@ nsapi_error_t ESP8266::open_udp(int id, const char* addr, int port, int local_po
418419
"ESP8266::_open_udp: device refused to close socket");
419420
}
420421
}
422+
if (_error) {
423+
_error = false;
424+
done = false;
425+
}
421426
continue;
422427
}
423428
_sock_i[id].open = true;
@@ -460,6 +465,10 @@ nsapi_error_t ESP8266::open_tcp(int id, const char* addr, int port, int keepaliv
460465
"ESP8266::_open_tcp: device refused to close socket");
461466
}
462467
}
468+
if (_error) {
469+
_error = false;
470+
done = false;
471+
}
463472
continue;
464473
}
465474
_sock_i[id].open = true;
@@ -491,14 +500,19 @@ nsapi_error_t ESP8266::send(int id, const void *data, uint32_t amount)
491500
set_timeout(ESP8266_SEND_TIMEOUT);
492501
if (_parser.send("AT+CIPSEND=%d,%lu", id, amount)
493502
&& _parser.recv(">")
494-
&& _parser.write((char*)data, (int)amount) >= 0) {
503+
&& _parser.write((char*)data, (int)amount) >= 0
504+
&& _parser.recv("SEND OK")) {
495505
// No flow control, data overrun is possible
496506
if (_serial_rts == NC) {
497507
while (_parser.process_oob()); // Drain USART receive register
498508
}
499509
_smutex.unlock();
500510
return NSAPI_ERROR_OK;
501511
}
512+
if (_error) {
513+
_error = false;
514+
}
515+
502516
set_timeout();
503517
_smutex.unlock();
504518
}
@@ -824,12 +838,18 @@ void ESP8266::_oob_conn_already()
824838
_parser.abort();
825839
}
826840

841+
void ESP8266::_oob_err()
842+
{
843+
_error = true;
844+
_parser.abort();
845+
}
846+
827847
void ESP8266::_oob_socket_close_err()
828848
{
829-
if (_parser.recv("ERROR\n")) {
830-
_closed = true; // Not possible to pinpoint to a certain socket
831-
_parser.abort();
849+
if (_error) {
850+
_error = false;
832851
}
852+
_closed = true; // Not possible to pinpoint to a certain socket
833853
}
834854

835855
void ESP8266::_oob_socket0_closed()

ESP8266/ESP8266.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ class ESP8266
388388
void _oob_packet_hdlr();
389389
void _oob_connect_err();
390390
void _oob_conn_already();
391+
void _oob_err();
391392
void _oob_socket0_closed();
392393
void _oob_socket1_closed();
393394
void _oob_socket2_closed();
@@ -401,6 +402,7 @@ class ESP8266
401402
bool _fail;
402403
bool _sock_already;
403404
bool _closed;
405+
bool _error;
404406

405407
// Modem's address info
406408
char _ip_buffer[16];

0 commit comments

Comments
 (0)