Skip to content

Commit f5ba963

Browse files
author
Veijo Pesonen
committed
Adds check that AT firmware in use
1 parent 92beef7 commit f5ba963

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

ESP8266/ESP8266.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ ESP8266::ESP8266(PinName tx, PinName rx, bool debug, PinName rts, PinName cts)
5757
_parser.oob("UNLINK", callback(this, &ESP8266::_oob_socket_close_error));
5858
}
5959

60+
bool ESP8266::at_available()
61+
{
62+
_smutex.lock();
63+
bool ready = _parser.send("AT")
64+
&& _parser.recv("OK\n");
65+
_smutex.unlock();
66+
67+
return ready;
68+
}
69+
6070
int ESP8266::get_firmware_version()
6171
{
6272
int version;

ESP8266/ESP8266.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ class ESP8266
4343
public:
4444
ESP8266(PinName tx, PinName rx, bool debug=false, PinName rts=NC, PinName cts=NC);
4545

46+
/**
47+
* Check AT command interface of ESP8266
48+
*
49+
* @return true if ready to respond on AT commands
50+
*/
51+
bool at_available(void);
52+
4653
/**
4754
* Check firmware version of ESP8266
4855
*

ESP8266Interface.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ int ESP8266Interface::scan(WiFiAccessPoint *res, unsigned count)
239239

240240
bool ESP8266Interface::_get_firmware_ok()
241241
{
242-
if (_esp.get_firmware_version() != ESP8266_VERSION) {
242+
if (_esp.get_firmware_version() < ESP8266_VERSION) {
243243
debug("ESP8266: ERROR: Firmware incompatible with this driver.\
244-
\r\nUpdate to v%d - https://developer.mbed.org/teams/ESP8266/wiki/Firmware-Update\r\n",ESP8266_VERSION);
244+
\r\nUpdate at least to v%d - https://developer.mbed.org/teams/ESP8266/wiki/Firmware-Update\r\n",ESP8266_VERSION);
245245
return false;
246246
}
247247

@@ -267,6 +267,9 @@ bool ESP8266Interface::_disable_default_softap()
267267
nsapi_error_t ESP8266Interface::_init(void)
268268
{
269269
if (!_initialized) {
270+
if (!_esp.at_available()) {
271+
return NSAPI_ERROR_DEVICE_ERROR;
272+
}
270273
if (!_esp.stop_uart_hw_flow_ctrl()) {
271274
return NSAPI_ERROR_DEVICE_ERROR;
272275
}

0 commit comments

Comments
 (0)