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:
44:7ac7eb406603
Parent:
43:7c010b1db697
Child:
45:538e5ce2f0d3
--- a/ESP8266Interface.cpp	Wed Feb 24 23:14:45 2016 -0600
+++ b/ESP8266Interface.cpp	Thu Feb 25 03:25:00 2016 -0600
@@ -37,8 +37,8 @@
     virtual int32_t open(const char *ip, uint16_t port);
     virtual int32_t close();
 
-    virtual int32_t send(const void *data, uint32_t len);
-    virtual int32_t recv(void *data, uint32_t len);
+    virtual int32_t send(const void *data, uint32_t size);
+    virtual int32_t recv(void *data, uint32_t size);
 
 private:
     ESP8266 *_esp;
@@ -166,23 +166,26 @@
     return 0;
 }
 
-int32_t ESP8266Socket::send(const void *data, uint32_t amount)
+int32_t ESP8266Socket::send(const void *data, uint32_t size)
 {
-    if (!_esp->send(_id, data, amount)) {
+    if (!_esp->send(_id, data, size)) {
         return NS_ERROR_TIMEOUT;
     }
 
     return 0;
 }
 
-int32_t ESP8266Socket::recv(void *data, uint32_t amount)
+int32_t ESP8266Socket::recv(void *data, uint32_t size)
 {
-    int32_t size = _esp->recv(_id, data, amount);
-    if (size < 0) {
-        return NS_ERROR_TIMEOUT;
+    _esp->setTimeout(0);
+
+    int32_t recv = _esp->recv(_id, data, size);
+
+    if (recv < 0) {
+        return 0;
     }
 
-    return size;
+    return recv;
 }
 
 int ESP8266Socket::getID() const {