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:
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);