Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ESP8266
Fork of ESP8266Interface by
Diff: ESP8266Interface.cpp
- Branch:
- api-changes
- Revision:
- 45:538e5ce2f0d3
- Parent:
- 44:7ac7eb406603
- Child:
- 46:6b1bd1268074
--- a/ESP8266Interface.cpp Thu Feb 25 03:25:00 2016 -0600
+++ b/ESP8266Interface.cpp Thu Feb 25 03:32:37 2016 -0600
@@ -16,6 +16,12 @@
#include "ESP8266Interface.h"
+// Various timeouts for different ESP8266 operations
+#define ESP8266_CONNECT_TIMEOUT 15000
+#define ESP8266_SEND_TIMEOUT 500
+#define ESP8266_RECV_TIMEOUT 0
+#define ESP8266_MISC_TIMEOUT 5000
+
/** ESP8266Socket class
* Implementation of the SocketInterface for the ESP8266
@@ -63,6 +69,8 @@
const char *pass_phrase,
wifi_security_t)
{
+ _esp.setTimeout(ESP8266_CONNECT_TIMEOUT);
+
if (!_esp.startup(3)) {
return NS_ERROR_DEVICE_ERROR;
}
@@ -86,6 +94,8 @@
int32_t ESP8266Interface::disconnect()
{
+ _esp.setTimeout(ESP8266_MISC_TIMEOUT);
+
if (!_esp.disconnect()) {
return NS_ERROR_DEVICE_ERROR;
}
@@ -148,6 +158,8 @@
int32_t ESP8266Socket::open(const char *ip, uint16_t port)
{
+ _esp->setTimeout(ESP8266_MISC_TIMEOUT);
+
const char *proto = (_proto == SOCK_UDP) ? "UDP" : "TCP";
if (!_esp->open(proto, _id, ip, port)) {
@@ -159,8 +171,10 @@
int32_t ESP8266Socket::close()
{
+ _esp->setTimeout(ESP8266_MISC_TIMEOUT);
+
if (!_esp->close(_id)) {
- return -1;
+ return NS_ERROR_TIMEOUT;
}
return 0;
@@ -168,6 +182,8 @@
int32_t ESP8266Socket::send(const void *data, uint32_t size)
{
+ _esp->setTimeout(ESP8266_SEND_TIMEOUT);
+
if (!_esp->send(_id, data, size)) {
return NS_ERROR_TIMEOUT;
}
@@ -177,7 +193,7 @@
int32_t ESP8266Socket::recv(void *data, uint32_t size)
{
- _esp->setTimeout(0);
+ _esp->setTimeout(ESP8266_RECV_TIMEOUT);
int32_t recv = _esp->recv(_id, data, size);
