Skip to content

Commit

Permalink
Adds check that AT firmware in use
Browse files Browse the repository at this point in the history
  • Loading branch information
Veijo Pesonen committed Sep 7, 2018
1 parent 92beef7 commit f5ba963
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
10 changes: 10 additions & 0 deletions ESP8266/ESP8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ ESP8266::ESP8266(PinName tx, PinName rx, bool debug, PinName rts, PinName cts)
_parser.oob("UNLINK", callback(this, &ESP8266::_oob_socket_close_error));
}

bool ESP8266::at_available()
{
_smutex.lock();
bool ready = _parser.send("AT")
&& _parser.recv("OK\n");
_smutex.unlock();

return ready;
}

int ESP8266::get_firmware_version()
{
int version;
Expand Down
7 changes: 7 additions & 0 deletions ESP8266/ESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ class ESP8266
public:
ESP8266(PinName tx, PinName rx, bool debug=false, PinName rts=NC, PinName cts=NC);

/**
* Check AT command interface of ESP8266
*
* @return true if ready to respond on AT commands
*/
bool at_available(void);

/**
* Check firmware version of ESP8266
*
Expand Down
7 changes: 5 additions & 2 deletions ESP8266Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ int ESP8266Interface::scan(WiFiAccessPoint *res, unsigned count)

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

Expand All @@ -267,6 +267,9 @@ bool ESP8266Interface::_disable_default_softap()
nsapi_error_t ESP8266Interface::_init(void)
{
if (!_initialized) {
if (!_esp.at_available()) {
return NSAPI_ERROR_DEVICE_ERROR;
}
if (!_esp.stop_uart_hw_flow_ctrl()) {
return NSAPI_ERROR_DEVICE_ERROR;
}
Expand Down

0 comments on commit f5ba963

Please sign in to comment.