Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,32 @@ void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback
int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult) {
ip_addr_t addr;
aResult = static_cast<uint32_t>(0);

if(aResult.fromString(aHostname)) {
// Host name is a IP address use it!
DEBUG_WIFI_GENERIC("[hostByName] Host: %s is a IP!\n", aHostname);
return 1;
}

DEBUG_WIFI_GENERIC("[hostByName] request IP for: %s\n", aHostname);
err_t err = dns_gethostbyname(aHostname, &addr, &wifi_dns_found_callback, &aResult);
if(err == ERR_OK) {
aResult = addr.addr;
} else if(err == ERR_INPROGRESS) {
esp_yield();
// will return here when dns_found_callback fires
if(aResult != 0) {
err = ERR_OK;
}
}

if(err != 0) {
DEBUG_WIFI_GENERIC("[hostByName] Host: %s lookup error: %d!\n", aHostname, err);
} else {
DEBUG_WIFI_GENERIC("[hostByName] Host: %s IP: %s\n", aHostname, aResult.toString().c_str());
}

return (aResult != 0) ? 1 : 0;
return (err == ERR_OK) ? 1 : 0;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@

#include "ESP8266WiFiType.h"

#ifdef DEBUG_ESP_WIFI
#ifdef DEBUG_ESP_PORT
#define DEBUG_WIFI_GENERIC(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
#endif
#endif

#ifndef DEBUG_WIFI_GENERIC
#define DEBUG_WIFI_GENERIC(...)
#endif

typedef void (*WiFiEventCb)(WiFiEvent_t event);

typedef struct {
Expand Down