WiFiNINA - WiFi.hostByName()

Description

Resolve the given hostname to an IP address

Syntax

WiFi.hostByName(hostname, result)

Parameters

  • hostname: Name to be resolved
  • result: IPAddress structure to store the returned IP address

Returns

  • 1 if hostname was successfully converted to an IP address, else the error code

Example

…

  while (status != WL_CONNECTED) {
        Serial.print("Attempting to connect to SSID: ");
        Serial.println(ssid);
        status = WiFi.begin(ssid, pass);
        delay(10000);
  }
  Serial.println("Connected to WiFi");
  printWifiStatus();

  Serial.println("\nStarting connection to server...");
  IPAddress result;
  int err = WiFi.hostByName(server, result) ;
  if(err == 1){
        Serial.print("IP address: ");
        Serial.println(result);
  } else {
        Serial.print("Error code: ");
        Serial.println(err);
  }

…