Skip to content

Commit a7016f7

Browse files
committed
Ensures ES8266 firmware version up to date
If ESP8266 firmware version is less that v2.0.0, then we print a debug message and return an error from the connect function.
1 parent abd4594 commit a7016f7

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

ESP8266/ESP8266.cpp

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

27+
bool ESP8266::check_firmware_version()
28+
{
29+
_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);
33+
}
34+
2735
bool ESP8266::startup(int mode)
2836
{
2937
//only 3 valid modes

ESP8266/ESP8266.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ class ESP8266
2727
public:
2828
ESP8266(PinName tx, PinName rx, bool debug=false);
2929

30+
/**
31+
* Check firmware version of ESP8266
32+
*
33+
* @return true only if ESP8266 firmware > v2
34+
*/
35+
bool check_firmware_version(void);
36+
3037
/**
3138
* Startup the ESP8266
3239
*

ESP8266Interface.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ int ESP8266Interface::connect(const char *ssid, const char *pass, nsapi_security
4646

4747
int ESP8266Interface::connect()
4848
{
49+
_esp.setTimeout(ESP8266_MISC_TIMEOUT);
50+
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");
54+
return NSAPI_ERROR_DEVICE_ERROR;
55+
}
56+
4957
_esp.setTimeout(ESP8266_CONNECT_TIMEOUT);
50-
58+
5159
if (!_esp.startup(3)) {
5260
return NSAPI_ERROR_DEVICE_ERROR;
5361
}

ESP8266Interface.h

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

2020
#include "mbed.h"
21+
#include "mbed_debug.h"
2122
#include "ESP8266.h"
2223

2324

0 commit comments

Comments
 (0)