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)

Files at this revision

API Documentation at this revision

Comitter:
Christopher Haster
Date:
Tue May 10 14:31:58 2016 -0500
Parent:
56:34829ec3a3da
Commit message:
Minor documentation changes

Changed in this revision

ESP8266Interface.cpp Show annotated file Show diff for this revision Revisions of this file
ESP8266Interface.h Show annotated file Show diff for this revision Revisions of this file
diff -r 34829ec3a3da -r 2ad35ade7a83 ESP8266Interface.cpp
--- a/ESP8266Interface.cpp	Thu Apr 21 06:11:08 2016 -0500
+++ b/ESP8266Interface.cpp	Tue May 10 14:31:58 2016 -0500
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+ 
 
 #include "ESP8266Interface.h"
 
@@ -31,9 +32,9 @@
 }
 
 int ESP8266Interface::connect(
-    const char *ap, 
-    const char *pass_phrase, 
-    nsapi_security_t)
+    const char *ssid,
+    const char *pass,
+    nsapi_security_t security)
 {
     _esp.setTimeout(ESP8266_CONNECT_TIMEOUT);
 
@@ -45,7 +46,7 @@
         return NSAPI_ERROR_DHCP_FAILURE;
     }
 
-    if (!_esp.connect(ap, pass_phrase)) {
+    if (!_esp.connect(ssid, pass)) {
         return NSAPI_ERROR_NO_CONNECTION;
     }
 
@@ -87,7 +88,7 @@
 {
     // Look for an unused socket
     int id = -1;
-
+ 
     for (int i = 0; i < ESP8266_SOCKET_COUNT; i++) {
         if (!_ids[i]) {
             id = i;
@@ -95,16 +96,16 @@
             break;
         }
     }
-
+ 
     if (id == -1) {
         return NSAPI_ERROR_NO_SOCKET;
     }
-
+    
     struct esp8266_socket *socket = new struct esp8266_socket;
     if (!socket) {
         return NSAPI_ERROR_NO_SOCKET;
     }
-
+    
     socket->id = id;
     socket->proto = proto;
     socket->connected = false;
@@ -203,4 +204,3 @@
 void ESP8266Interface::socket_attach(void *handle, void (*callback)(void *), void *data)
 {
 }
-
diff -r 34829ec3a3da -r 2ad35ade7a83 ESP8266Interface.h
--- a/ESP8266Interface.h	Thu Apr 21 06:11:08 2016 -0500
+++ b/ESP8266Interface.h	Tue May 10 14:31:58 2016 -0500
@@ -23,15 +23,15 @@
 #define ESP8266_SOCKET_COUNT 5
 
 /** ESP8266Interface class
- *  Implementation of the NetworkStack for LWIP
+ *  Implementation of the NetworkStack for the ESP8266
  */
 class ESP8266Interface : public NetworkStack, public WiFiInterface
 {
 public:
     /** ESP8266Interface lifetime
-     * @param tx TX pin
-     * @param rx RX pin
-     * @param debug Enable debugging
+     * @param tx        TX pin
+     * @param rx        RX pin
+     * @param debug     Enable debugging
      */
     ESP8266Interface(PinName tx, PinName rx, bool debug = false);
 
@@ -137,7 +137,7 @@
      *  @param address      The remote SocketAddress
      *  @param data         The packet to be sent
      *  @param size         The length of the packet to be sent
-     *  @return the         number of written bytes on success, negative on failure
+     *  @return             The number of written bytes on success, negative on failure
      *  @note This call is not-blocking, if this call would block, must
      *        immediately return NSAPI_ERROR_WOULD_WAIT
      */
@@ -150,7 +150,7 @@
      *                      If a packet is too long to fit in the supplied buffer,
      *                      excess bytes are discarded
      *  @param size         The length of the buffer
-     *  @return the         number of received bytes on success, negative on failure
+     *  @return             The number of received bytes on success, negative on failure
      *  @note This call is not-blocking, if this call would block, must
      *        immediately return NSAPI_ERROR_WOULD_WAIT
      */
@@ -163,7 +163,7 @@
      *  @note Callback may be called in an interrupt context.
      */
     virtual void socket_attach(void *handle, void (*callback)(void *), void *data);
-
+    
 private:
     ESP8266 _esp;
     bool _ids[ESP8266_SOCKET_COUNT];