mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Fixed DNS issue
This commit is contained in:
parent
a984979b11
commit
84403e2512
@ -175,4 +175,9 @@ uint8_t WiFiClass::status()
|
|||||||
return WiFiDrv::getConnectionStatus();
|
return WiFiDrv::getConnectionStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WiFiClass::hostByName(const char* aHostname, IPAddress& aResult)
|
||||||
|
{
|
||||||
|
return WiFiDrv::getHostByName(aHostname, aResult);
|
||||||
|
}
|
||||||
|
|
||||||
WiFiClass WiFi;
|
WiFiClass WiFi;
|
||||||
|
@ -159,6 +159,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
uint8_t status();
|
uint8_t status();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Resolve the given hostname to an IP address.
|
||||||
|
* param aHostname: Name to be resolved
|
||||||
|
* param aResult: IPAddress structure to store the returned IP address
|
||||||
|
* result: 1 if aIPAddrString was successfully converted to an IP address,
|
||||||
|
* else error code
|
||||||
|
*/
|
||||||
|
int hostByName(const char* aHostname, IPAddress& aResult);
|
||||||
|
|
||||||
friend class WiFiClient;
|
friend class WiFiClient;
|
||||||
friend class WiFiServer;
|
friend class WiFiServer;
|
||||||
};
|
};
|
||||||
|
@ -21,22 +21,12 @@ WiFiClient::WiFiClient(uint8_t sock) : _sock(sock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int WiFiClient::connect(const char* host, uint16_t port) {
|
int WiFiClient::connect(const char* host, uint16_t port) {
|
||||||
/* TODO Add DNS wifi spi function to resolve DNS */
|
IPAddress remote_addr;
|
||||||
#if 0
|
if (WiFi.hostByName(host, remote_addr))
|
||||||
// Look up the host first
|
{
|
||||||
int ret = 0;
|
return connect(remote_addr, port);
|
||||||
DNSClient dns;
|
}
|
||||||
IPAddress remote_addr;
|
return 0;
|
||||||
|
|
||||||
dns.begin(Ethernet.dnsServerIP());
|
|
||||||
ret = dns.getHostByName(host, remote_addr);
|
|
||||||
if (ret == 1) {
|
|
||||||
return connect(remote_addr, port);
|
|
||||||
} else {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int WiFiClient::connect(IPAddress ip, uint16_t port) {
|
int WiFiClient::connect(IPAddress ip, uint16_t port) {
|
||||||
|
@ -376,4 +376,66 @@ int32_t WiFiDrv::getRSSINetoworks(uint8_t networkItem)
|
|||||||
return networkRssi;
|
return networkRssi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t WiFiDrv::reqHostByName(const char* aHostname)
|
||||||
|
{
|
||||||
|
WAIT_FOR_SLAVE_SELECT();
|
||||||
|
|
||||||
|
// Send Command
|
||||||
|
SpiDrv::sendCmd(REQ_HOST_BY_NAME_CMD, PARAM_NUMS_1);
|
||||||
|
SpiDrv::sendParam((uint8_t*)aHostname, strlen(aHostname), LAST_PARAM);
|
||||||
|
|
||||||
|
//Wait the reply elaboration
|
||||||
|
SpiDrv::waitForSlaveReady();
|
||||||
|
|
||||||
|
// Wait for reply
|
||||||
|
uint8_t _data = 0;
|
||||||
|
uint8_t _dataLen = 0;
|
||||||
|
uint8_t result = SpiDrv::waitResponseCmd(REQ_HOST_BY_NAME_CMD, PARAM_NUMS_1, &_data, &_dataLen);
|
||||||
|
|
||||||
|
SpiDrv::spiSlaveDeselect();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int WiFiDrv::getHostByName(IPAddress& aResult)
|
||||||
|
{
|
||||||
|
uint8_t _ipAddr[WL_IPV4_LENGTH];
|
||||||
|
IPAddress dummy(0xFF,0xFF,0xFF,0xFF);
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
WAIT_FOR_SLAVE_SELECT();
|
||||||
|
// Send Command
|
||||||
|
SpiDrv::sendCmd(GET_HOST_BY_NAME_CMD, PARAM_NUMS_0);
|
||||||
|
|
||||||
|
//Wait the reply elaboration
|
||||||
|
SpiDrv::waitForSlaveReady();
|
||||||
|
|
||||||
|
// Wait for reply
|
||||||
|
uint8_t _dataLen = 0;
|
||||||
|
if (!SpiDrv::waitResponseCmd(GET_HOST_BY_NAME_CMD, PARAM_NUMS_1, _ipAddr, &_dataLen))
|
||||||
|
{
|
||||||
|
WARN("error waitResponse");
|
||||||
|
}else{
|
||||||
|
aResult = _ipAddr;
|
||||||
|
result = (aResult != dummy);
|
||||||
|
}
|
||||||
|
SpiDrv::spiSlaveDeselect();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int WiFiDrv::getHostByName(const char* aHostname, IPAddress& aResult)
|
||||||
|
{
|
||||||
|
uint8_t retry = 10;
|
||||||
|
if (reqHostByName(aHostname))
|
||||||
|
{
|
||||||
|
while(!getHostByName(aResult) && --retry > 0)
|
||||||
|
{
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
WiFiDrv wiFiDrv;
|
WiFiDrv wiFiDrv;
|
||||||
|
@ -31,6 +31,10 @@ private:
|
|||||||
*/
|
*/
|
||||||
static void getNetworkData(uint8_t *ip, uint8_t *mask, uint8_t *gwip);
|
static void getNetworkData(uint8_t *ip, uint8_t *mask, uint8_t *gwip);
|
||||||
|
|
||||||
|
static uint8_t reqHostByName(const char* aHostname);
|
||||||
|
|
||||||
|
static int getHostByName(IPAddress& aResult);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -181,6 +185,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
static uint8_t getEncTypeNetowrks(uint8_t networkItem);
|
static uint8_t getEncTypeNetowrks(uint8_t networkItem);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Resolve the given hostname to an IP address.
|
||||||
|
* param aHostname: Name to be resolved
|
||||||
|
* param aResult: IPAddress structure to store the returned IP address
|
||||||
|
* result: 1 if aIPAddrString was successfully converted to an IP address,
|
||||||
|
* else error code
|
||||||
|
*/
|
||||||
|
static int getHostByName(const char* aHostname, IPAddress& aResult);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern WiFiDrv wiFiDrv;
|
extern WiFiDrv wiFiDrv;
|
||||||
|
@ -45,6 +45,8 @@ enum {
|
|||||||
GET_IDX_SSID_CMD = 0x31,
|
GET_IDX_SSID_CMD = 0x31,
|
||||||
GET_IDX_RSSI_CMD = 0x32,
|
GET_IDX_RSSI_CMD = 0x32,
|
||||||
GET_IDX_ENCT_CMD = 0x33,
|
GET_IDX_ENCT_CMD = 0x33,
|
||||||
|
REQ_HOST_BY_NAME_CMD= 0x34,
|
||||||
|
GET_HOST_BY_NAME_CMD= 0x35,
|
||||||
|
|
||||||
// All command with DATA_FLAG 0x40 send a 16bit Len
|
// All command with DATA_FLAG 0x40 send a 16bit Len
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user