2

I am trying to make an HTTP request over WiFi from an ESP32, but upon connecting to the host, this error is displayed in serial console

[ 21036][E][WiFiGeneric.cpp:1230] hostByName(): DNS Failed for httpbin.org

The code is as follows (PlatformIO C++ using the Arduino framework)

const char *ssid = "Nebula's iPhone";
const char *password = "password";
const char *host = "httpbin.org";

...

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_OFF);
  delay(1000);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (!WiFi.isConnected()) {
    delay(100);
  }
  WiFi.config(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask(),
              IPAddress(1, 1, 1, 1), IPAddress(8, 8, 8, 8));
}

...

void makeRequest() {
  httpsClient.connect(host, 443); // Fails here
}

hcheung
  • 3,377
  • 3
  • 11
  • 23
Nebula
  • 91
  • 2
  • 3
  • 2
    Have you try the [WiFiClientStaticIP](https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiClientStaticIP/WiFiClientStaticIP.ino) example? The `WiFi.config()` needs to be setup before calling `WiFi.begin()`. – hcheung May 06 '22 at 01:17

0 Answers0