Skip to content

Commit 64e5e78

Browse files
committed
Get firmware version occurs after reset
Firmware version pinned to macro. Check for compatibility occurs at Interface level.
1 parent a7016f7 commit 64e5e78

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

ESP8266/ESP8266.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ ESP8266::ESP8266(PinName tx, PinName rx, bool debug)
2424
_parser.debugOn(debug);
2525
}
2626

27-
bool ESP8266::check_firmware_version()
27+
int ESP8266::get_firmware_version()
2828
{
2929
_parser.send("AT+GMR");
30-
int8_t version = 0;
31-
bool success = _parser.recv("SDK version: %d", &version) && _parser.recv("OK");
32-
return success && (version == 2);
30+
int version;
31+
if(_parser.recv("SDK version:%d", &version) && _parser.recv("OK")) {
32+
return version;
33+
} else {
34+
// Older firmware versions do not prefix the version with "SDK version: "
35+
return -1;
36+
}
37+
3338
}
3439

3540
bool ESP8266::startup(int mode)
@@ -39,8 +44,7 @@ bool ESP8266::startup(int mode)
3944
return false;
4045
}
4146

42-
bool success = reset()
43-
&& _parser.send("AT+CWMODE_CUR=%d", mode)
47+
bool success = _parser.send("AT+CWMODE_CUR=%d", mode)
4448
&& _parser.recv("OK")
4549
&& _parser.send("AT+CIPMUX=1")
4650
&& _parser.recv("OK");

ESP8266/ESP8266.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class ESP8266
3030
/**
3131
* Check firmware version of ESP8266
3232
*
33-
* @return true only if ESP8266 firmware > v2
33+
* @return integer firmware version or -1 if firmware query command gives outdated response
3434
*/
35-
bool check_firmware_version(void);
35+
int get_firmware_version(void);
3636

3737
/**
3838
* Startup the ESP8266

ESP8266Interface.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616

1717
#include <string.h>
1818
#include "ESP8266Interface.h"
19+
#include "mbed_debug.h"
1920

2021
// Various timeouts for different ESP8266 operations
2122
#define ESP8266_CONNECT_TIMEOUT 15000
2223
#define ESP8266_SEND_TIMEOUT 500
2324
#define ESP8266_RECV_TIMEOUT 0
2425
#define ESP8266_MISC_TIMEOUT 500
2526

27+
// Firmware version
28+
#define ESP8266_VERSION 2
29+
2630
// ESP8266Interface implementation
2731
ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug)
2832
: _esp(tx, rx, debug)
@@ -46,20 +50,26 @@ int ESP8266Interface::connect(const char *ssid, const char *pass, nsapi_security
4650

4751
int ESP8266Interface::connect()
4852
{
53+
_esp.setTimeout(ESP8266_CONNECT_TIMEOUT);
54+
55+
if(!_esp.reset()) {
56+
return NSAPI_ERROR_DEVICE_ERROR;
57+
}
58+
4959
_esp.setTimeout(ESP8266_MISC_TIMEOUT);
5060

51-
if(!_esp.check_firmware_version()) {
52-
debug("ERROR: Firmware incompatible with this driver.\
53-
\r\nUpdate to v2.0.0 - https://developer.mbed.org/teams/ESP8266/wiki/Firmware-Update\r\n");
61+
if(_esp.get_firmware_version() != ESP8266_VERSION) {
62+
debug("ESP8266: ERROR: Firmware incompatible with this driver.\
63+
\r\nUpdate to v%d - https://developer.mbed.org/teams/ESP8266/wiki/Firmware-Update\r\n",ESP8266_VERSION);
5464
return NSAPI_ERROR_DEVICE_ERROR;
5565
}
5666

5767
_esp.setTimeout(ESP8266_CONNECT_TIMEOUT);
58-
68+
5969
if (!_esp.startup(3)) {
6070
return NSAPI_ERROR_DEVICE_ERROR;
6171
}
62-
72+
6373
if (!_esp.dhcp(true, 1)) {
6474
return NSAPI_ERROR_DHCP_FAILURE;
6575
}

ESP8266Interface.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define ESP8266_INTERFACE_H
1919

2020
#include "mbed.h"
21-
#include "mbed_debug.h"
2221
#include "ESP8266.h"
2322

2423

0 commit comments

Comments
 (0)