Last active
February 8, 2018 09:16
-
-
Save ianleeder/3ff84c1564e94a371e53f41d83fdcb9f to your computer and use it in GitHub Desktop.
ESP8266 DNS lookup failure example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <ESP8266HTTPClient.h> | |
#define WIFI_SSID "MySSID" | |
#define WIFI_KEY "MyKey" | |
void setup() { | |
Serial.begin(115200); | |
delay(500); | |
Serial.println(); | |
Serial.println("Initialising wifi"); | |
WiFi.begin(WIFI_SSID, WIFI_KEY); | |
while((WiFi.status() != WL_CONNECTED)) { | |
delay(100); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.println("WiFi connected"); | |
testGet(); | |
//testDnsLookup(); | |
WiFi.disconnect(); | |
} | |
void testGet() { | |
HTTPClient http; | |
http.begin("http://www.google.com"); | |
long startTime = millis(); | |
int httpCode = http.GET(); | |
Serial.printf("[Get] [%dms] First try code %d, error message: %s\n", millis() - startTime, httpCode, http.errorToString(httpCode).c_str()); | |
httpCode = http.GET(); | |
Serial.printf("[Get] [%dms] Second try code %d, error message: %s\n", millis() - startTime, httpCode, http.errorToString(httpCode).c_str()); | |
} | |
void testDnsLookup() { | |
Serial.println("Starting lookup"); | |
long startTime = millis(); | |
IPAddress serverIP; | |
WiFi.hostByName("www.google.com", serverIP); | |
Serial.printf("[DNS] [%dms] Finished lookup", millis() - startTime); | |
} | |
void loop() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment