@@ -50,6 +50,7 @@ ESP8266::ESP8266(PinName tx, PinName rx, bool debug, PinName rts, PinName cts)
50
50
_fail(false ),
51
51
_sock_already(false ),
52
52
_closed(false ),
53
+ _busy(false ),
53
54
_conn_status(NSAPI_STATUS_DISCONNECTED)
54
55
{
55
56
_serial.set_baud (ESP8266_DEFAULT_BAUD_RATE);
@@ -572,29 +573,33 @@ nsapi_error_t ESP8266::send(int id, const void *data, uint32_t amount)
572
573
return NSAPI_ERROR_PARAMETER;
573
574
}
574
575
575
- // May take a second try if device is busy
576
- for (unsigned i = 0 ; i < 2 ; i++) {
577
- _smutex.lock ();
578
- set_timeout (ESP8266_SEND_TIMEOUT);
579
- if (_parser.send (" AT+CIPSEND=%d,%lu" , id, amount)
580
- && _parser.recv (" >" )
581
- && _parser.write ((char *)data, (int )amount) >= 0
582
- && _parser.recv (" SEND OK" )) {
583
- // No flow control, data overrun is possible
584
- if (_serial_rts == NC) {
585
- while (_parser.process_oob ()); // Drain USART receive register
586
- }
587
- _smutex.unlock ();
588
- return NSAPI_ERROR_OK;
589
- }
590
- if (_error) {
591
- _error = false ;
576
+ _smutex.lock ();
577
+ set_timeout (ESP8266_SEND_TIMEOUT);
578
+ _busy = false ;
579
+ if (_parser.send (" AT+CIPSEND=%d,%lu" , id, amount)
580
+ && _parser.recv (" >" )
581
+ && _parser.write ((char *)data, (int )amount) >= 0
582
+ && _parser.recv (" SEND OK" )) {
583
+ // No flow control, data overrun is possible
584
+ if (_serial_rts == NC) {
585
+ while (_parser.process_oob ()); // Drain USART receive register
592
586
}
593
-
587
+ _smutex.unlock ();
588
+ return NSAPI_ERROR_OK;
589
+ }
590
+ if (_error) {
591
+ _error = false ;
592
+ }
593
+ if (_busy) {
594
594
set_timeout ();
595
595
_smutex.unlock ();
596
+ tr_debug (" returning WOULD_BLOCK" );
597
+ return NSAPI_ERROR_WOULD_BLOCK;
596
598
}
597
599
600
+ set_timeout ();
601
+ _smutex.unlock ();
602
+
598
603
return NSAPI_ERROR_DEVICE_ERROR;
599
604
}
600
605
@@ -963,6 +968,7 @@ void ESP8266::_oob_busy()
963
968
" ESP8266::_oob_busy() AT timeout\n " );
964
969
}
965
970
_busy = true ;
971
+ _parser.abort ();
966
972
}
967
973
968
974
void ESP8266::_oob_tcp_data_hdlr ()
0 commit comments