Takehisa Oneta / ESP8266Interface

Dependencies:   ESP8266

Dependents:   HelloESP8266Interface_mine

Fork of ESP8266Interface by NetworkSocketAPI

Files at this revision

API Documentation at this revision

Comitter:
sarahmarshy
Date:
Mon Jul 27 15:17:18 2015 +0000
Parent:
23:fd0f3197c30b
Child:
26:6e36dd3cec3f
Commit message:
DnsQuery support

Changed in this revision

DnsQuery.lib Show annotated file Show diff for this revision Revisions of this file
ESP8266.lib Show annotated file Show diff for this revision Revisions of this file
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DnsQuery.lib	Mon Jul 27 15:17:18 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/sarahmarshy/code/DnsQuery/#5d978992a518
--- a/ESP8266.lib	Thu Jul 23 21:25:30 2015 +0000
+++ b/ESP8266.lib	Mon Jul 27 15:17:18 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/NetworkSocketAPI/code/ESP8266/#80048194de79
+http://developer.mbed.org/teams/NetworkSocketAPI/code/ESP8266/#1ee70fa0fdea
--- a/ESP8266Interface.cpp	Thu Jul 23 21:25:30 2015 +0000
+++ b/ESP8266Interface.cpp	Mon Jul 27 15:17:18 2015 +0000
@@ -140,6 +140,18 @@
         return -1;
     }
 }
+void ESP8266Interface::getHostByName(const char *name, char* hostIP)
+{
+    SocketInterface* sock = this->allocateSocket(SOCK_UDP);
+    IPADDRESS_t ip;
+    DnsQuery dns(sock);
+    dns.gethostbyname(name, ip);
+    sock->close();
+    this->deallocateSocket(sock);
+    char* resolved = ip.string_format();
+    memcpy(hostIP, resolved, strlen(resolved)+1);
+    printf("IP:%s\n",resolved);
+}   
 
 ESP8266Socket::ESP8266Socket(uint32_t handle, ESP8266 *driver, socket_protocol_t type, uint8_t id)
 : driver(driver), _id(id)
@@ -204,7 +216,7 @@
         sock_type = "TCP";
         
     if (!driver->openSocket(sock_type, _id, _port, _addr)){
-        return -1;//opening socket not succesful
+        return -1;//opening socket not successful
     }
     return 0;
         
@@ -231,7 +243,7 @@
 {
     
     if (!driver->close(_id)){
-        return -1;//closing socket not succesful
+        return -1;//closing socket not successful
     }
     return 0;
 }
@@ -244,4 +256,5 @@
 uint8_t ESP8266Socket::getID()
 {
     return _id;   
-}
\ No newline at end of file
+}
+ 
\ No newline at end of file
--- a/ESP8266Interface.h	Thu Jul 23 21:25:30 2015 +0000
+++ b/ESP8266Interface.h	Mon Jul 27 15:17:18 2015 +0000
@@ -19,6 +19,7 @@
 
 #include "WiFiInterface.h"
 #include "ESP8266.h"
+#include "DnsQuery.h"
 
 /** ESP8266Socket class.
     This is a ESP8266 implementation of a socket that implements the SocketInterface class.
@@ -70,6 +71,7 @@
     virtual int32_t isConnected(void) ;
     virtual SocketInterface *allocateSocket(socket_protocol_t socketProtocol) ;
     virtual int deallocateSocket(SocketInterface *socket) ;
+    void getHostByName(const char *name, char* hostIP);
     
 private:
     ESP8266 esp8266;