Socket interface for ESP8266. Implements the NetworkSocketAPI. Requires device to use the Espressif Firmware.

Dependencies:   ESP8266

Dependents:   ESP8266InterfaceTests HelloESP8266Interface

Fork of ESP8266Interface by NetworkSocketAPI

Note

This library assumes your ESP8266 is running the Espressif Firmware. For instructions on how to update your ESP8266 to use the correct firmware see the Firmware Update Wiki Page.

Currently the ESP8266Interface LIbrary has the following Abilities:

Working

  • TCP Client
  • UDP Client
  • Transparent mode (single connection of 1 type at a time)
  • Station Mode (connects to AP)

To be implimented

  • TCP Server
  • UDP Server
  • Multi Connection Mode (able to have up to 5 sockets at a time)
  • AP Mode (Make ESP Chip act like access point)
  • DNS Support (currently websites must be looked up by IP)
  • Error Recovery

Nice but not necessary

  • colorized text for ESP AT Commands in Command line (easier to differentiate from other text)
Branch:
api-changes
Revision:
43:7c010b1db697
Parent:
42:4bf09cadf328
Child:
44:7ac7eb406603
--- 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 {