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)
Revision:
33:276cb279df57
Parent:
30:c19f1e61063b
Child:
34:9c26a3dcdc1f
--- a/ESP8266Interface.cpp	Tue Feb 02 22:22:11 2016 +0000
+++ b/ESP8266Interface.cpp	Mon Feb 22 23:56:33 2016 +0000
@@ -24,18 +24,6 @@
 
 int32_t ESP8266Interface::init(void)
 {
-    if (!esp8266.startup()) {
-        return -1;
-    }
-    if (!esp8266.reset()) {
-        return -1;
-    }
-    if (!esp8266.wifiMode(3)) {
-        return -1;
-    }
-    if (!esp8266.multipleConnections(true)) {
-        return -1;
-    }
     return 0;
 }
 
@@ -52,12 +40,18 @@
 int32_t ESP8266Interface::connect(const char *ap, const char *pass_phrase, wifi_security_t security, uint32_t timeout_ms)
 {
     esp8266.setTimeout(timeout_ms);
-    if (!esp8266.dhcp(1, true)) {
+    if (!esp8266.startup(3)) {
+        return -1;
+    }
+    if (!esp8266.dhcp(true, 1)) {
         return -1;
     }
     if (!esp8266.connect(ap, pass_phrase)) {
         return -1;
     }
+    if (!esp8266.isConnected()) {
+        return -1;
+    }
     return 0;
 }
 
@@ -77,9 +71,10 @@
 
 char *ESP8266Interface::getIPAddress(void)
 {
-    if(!esp8266.getIPAddress(ip)) {
-        return NULL;
-    }
+    const char *src = esp8266.getIPAddress();
+    if (!src) return 0;
+    
+    strcpy(ip, src);
     return ip;
 }
 
@@ -207,8 +202,8 @@
 int32_t ESP8266Socket::open()
 {
 
-    string sock_type = (SOCK_UDP == _type) ? "UDP" : "TCP";
-    if (!_driver->openSocket(sock_type, _id, _port, _addr)) {
+    const char *sock_type = (SOCK_UDP == _type) ? "UDP" : "TCP";
+    if (!_driver->open(sock_type, _id, _addr, _port)) {
         return -1;
     }
     return 0;
@@ -218,7 +213,7 @@
 int32_t ESP8266Socket::send(const void *data, uint32_t amount, uint32_t timeout_ms)
 {
     _driver->setTimeout((int)timeout_ms);
-    if(!_driver->sendData(_id, data, amount)) {
+    if(!_driver->send(_id, data, amount)) {
         return -1;
     }
     return 0;
@@ -227,7 +222,7 @@
 uint32_t ESP8266Socket::recv(void *data, uint32_t amount, uint32_t timeout_ms)
 {
     _driver->setTimeout((int)timeout_ms);
-    return _driver->recv(data, amount);
+    return _driver->recv(_id, data, amount);
 }
 
 int32_t ESP8266Socket::close() const