WNC14A2A LTE Interface

Dependencies:   WncControllerK64F

Fork of WNC14A2AInterface by Avnet

Revision:
7:9340bc9e8d64
Parent:
6:7fd9e590c4e7
Child:
9:23587afd52fe
--- a/WNC14A2AInterface.cpp	Wed Apr 19 15:19:05 2017 +0000
+++ b/WNC14A2AInterface.cpp	Wed Apr 19 17:52:08 2017 +0000
@@ -327,27 +327,33 @@
 {
     nsapi_error_t ret = NSAPI_ERROR_OK;
     char ipAddrStr[25];
+    int  t_socket = 0;  //use a temporary socket place holder
 
     debugOutput(_debugUart,(char*)"+ENTER gethostbyname()()\n+CURRENTLY:\n");
     debugOutput(_debugUart,(char*)"+URL = %s\n+IP  = %s\n+PORT= %d\n", name, address->get_ip_address(), address->get_port());
     memset(ipAddrStr,0x00,sizeof(ipAddrStr));
     
-    if (!_pwnc || m_active_socket == -1) 
+    if (!_pwnc) 
         return (_errors = NSAPI_ERROR_NO_SOCKET);
+        
+    if (m_active_socket != -1)      //we might have been called before a socket was opened
+        t_socket = m_active_socket; //if so, do nothing with the active socket index
 
     //Execute DNS query.  
-    if( !_pwnc->resolveUrl(m_active_socket, name) )  
+    if( !_pwnc->resolveUrl(t_socket, name) )  
         return (_errors = NSAPI_ERROR_DEVICE_ERROR);
 
     //Now, get the IP address that the URL was resolved to
-    if( !_pwnc->getIpAddr(m_active_socket, ipAddrStr) )
+    if( !_pwnc->getIpAddr(t_socket, ipAddrStr) )
         return (_errors = NSAPI_ERROR_DEVICE_ERROR);
 
-    _sockets[m_active_socket].url=name;
-    _sockets[m_active_socket].addr.set_ip_address(ipAddrStr);
     address->set_ip_address(ipAddrStr);
+    debugOutput(_debugUart,(char*)"+resolveUrl returned IP=%s\n",ipAddrStr);
+    if( t_socket == m_active_socket ) {
+        _sockets[m_active_socket].url=name;
+        _sockets[m_active_socket].addr.set_ip_address(ipAddrStr);
+        }
 
-    debugOutput(_debugUart,(char*)"+resolveUrl returned IP=%s\n",ipAddrStr);
     debugOutput(_debugUart,(char*)"+EXIT gethostbyname()\n+URL = %s\n+IP  = %s\n+PORT= %d\n\n", 
                 _sockets[m_active_socket].url.c_str(), address->get_ip_address(), 
                 address->get_port());