platformio / platform-espressif8266

Espressif 8266: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/espressif8266
Apache License 2.0
330 stars 219 forks source link

Set DNS method #270

Closed BrotherV closed 2 years ago

BrotherV commented 2 years ago

SetDNS method

Description

I have a problem with WiFiClientSecure, it can't make a connection to HTTPS and HTTP servers (port 443 and 80). I know that I have to set the DNS server IP, however, since we have many nodes that connect to a router, dedicating a static IP for each one is not a good solution. All of them have the same code and the IP must be set dynamically by the router. The point is, I want to set the DNS server IP manually but there is not such a command for this purpose. I've read about the Arduino WiFi shield and it has a command to set one or two DNS servers without setting static IP. I want to know is it possible to add this command to the library?!!

 WiFi.setDNS(dns1);     or    WiFi.setDNS(dns1, dns2); 

Example

#include <Arduino.h>

// Network Configurations
#define WLAN_SSID     "YOUR_WIRELESS_SSID"
#define WLAN_PASSWORD "YOUR_PASSWORD"

// the IP address for the shield:
IPAddress dns1(8, 8, 8, 8);  //Google dns
IPAddress dns2(8, 8, 4, 4);  //Alternate dns

void setup() {

    WiFi.mode(WIFI_STA);
    WiFi.begin(WLAN_SSID, WLAN_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }

    Serial.println();
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());

    // print your WiFi IP address:
    WiFi.setDNS(dns1);              //WiFi.setDNS(dns1, dns2); 
    Serial.print("Dns configured.");

}

void loop() {}
valeros commented 2 years ago

This repo is not the right place for such questions, please forward to https://github.com/esp8266/Arduino