Christopher Haster / ESP8266Interface

Dependencies:   ESP8266

Fork of ESP8266Interface by NetworkSocketAPI

Branch:
api-changes
Revision:
43:7c010b1db697
Parent:
42:4bf09cadf328
Child:
44:7ac7eb406603
diff -r 4bf09cadf328 -r 7c010b1db697 ESP8266Interface.cpp
--- a/ESP8266Interface.cpp	Wed Feb 24 22:25:19 2016 -0600
+++ b/ESP8266Interface.cpp	Wed Feb 24 23:14:45 2016 -0600
@@ -64,21 +64,21 @@
     wifi_security_t)
 {
     if (!_esp.startup(3)) {
-        return -1;
+        return NS_ERROR_DEVICE_ERROR;
     }
 
     if (!_esp.dhcp(true, 1)) {
-        return -1;
+        return NS_ERROR_DHCP_FAILURE;
     }
 
     if (!_esp.connect(ap, pass_phrase)) {
-        return -1;
+        return NS_ERROR_NO_CONNECTION;
     }
 
     _ip_address = _esp.getIPAddress();
     _mac_address = _esp.getMACAddress();
     if (!_ip_address || !_mac_address) {
-        return -1;
+        return NS_ERROR_NO_ADDRESS;
     }
 
     return 0;
@@ -87,7 +87,7 @@
 int32_t ESP8266Interface::disconnect()
 {
     if (!_esp.disconnect()) {
-        return -1;
+        return NS_ERROR_DEVICE_ERROR;
     }
 
     return 0;
@@ -151,7 +151,7 @@
     const char *proto = (_proto == SOCK_UDP) ? "UDP" : "TCP";
 
     if (!_esp->open(proto, _id, ip, port)) {
-        return -1;
+        return NS_ERROR_TIMEOUT;
     }
 
     return 0;
@@ -169,7 +169,7 @@
 int32_t ESP8266Socket::send(const void *data, uint32_t amount)
 {
     if (!_esp->send(_id, data, amount)) {
-        return -1;
+        return NS_ERROR_TIMEOUT;
     }
 
     return 0;
@@ -177,7 +177,12 @@
 
 int32_t ESP8266Socket::recv(void *data, uint32_t amount)
 {
-    return _esp->recv(_id, data, amount);
+    int32_t size = _esp->recv(_id, data, amount);
+    if (size < 0) {
+        return NS_ERROR_TIMEOUT;
+    }
+
+    return size;
 }
 
 int ESP8266Socket::getID() const {