bportaluri / WiFiEsp

Arduino WiFi library for ESP8266 modules
GNU General Public License v3.0
550 stars 210 forks source link

WiFi.setDns(IPAddress dns_server1) #183

Open badre2911 opened 5 years ago

badre2911 commented 5 years ago

client.connect does not work with a hostname with firmware 1.6.2 SDK 2.2.1, I added the WiFi.setDNS method (IPAddress dns_server1) now it work with firmware below.

AT+GMR AT version:1.6.2.0(Apr 13 2018 11:10:59) SDK version:2.2.1(6ab97e9) compile time:Jun 7 2018 19:34:27 Bin version(Wroom 02):1.6.2 OK

on file WiFiEsp.h at line 96 uncomment line below // NOT IMPLEMENTED void setDNS(IPAddress dns_server1);

On file WiFiEsp.cpp add function after function void WiFiEspClass::config(IPAddress ip) at line 82 void WiFiEspClass::setDNS(IPAddress dns_server1) { EspDrv::setDNS(dns_server1); }

On file EspDrv.h at line 255 add declaration below /*

On file EspDrv.cpp before function char* EspDrv::getFwVersion() add function below void EspDrv::setDNS(IPAddress dns_server1) { LOGDEBUG(F("> setDNS"));

char buf[16]; sprintf_P(buf, PSTR("%d.%d.%d.%d"), dns_server1[0], dns_server1[1], dns_server1[2], dns_server1[3]);

int ret = sendCmd(F("AT+CIPDNS_CUR=1,\"%s\""), 2000, buf); delay(500);

if (ret==TAG_OK) { LOGINFO1(F("IP DNS set"), buf); } }

that's all.

example using WiFi.setDNS()

IPAddress IPDns(192,168,2,25); //Add line below after WiFi.init(&Serial1) WiFi.setDNS(IPDns);

JAndrassy commented 5 years ago

why don't you create a pull request?

badre2911 commented 5 years ago

sorry, I do not know how to do with github, I've never done this kind of manipulation

ozwe100 commented 1 year ago

There is a small bug in the function void EspDrv::setDNS(IPAddress dns_server1) , here is the fixed function that worked for me:

void EspDrv::setDNS(IPAddress dns_server1) { LOGDEBUG(F("> setDNS"));

char buf[16]; sprintf_P(buf, PSTR("%d.%d.%d.%d"), dns_server1[0], dns_server1[1], dns_server1[2], dns_server1[3]);

int ret = sendCmd(F("AT+CIPDNS_CUR=1 ,%s"), 2000, buf); delay(500);

if (ret==TAG_OK) { LOGINFO1(F("IP DNS set"), buf); } }

*** The line in bold is the one I fixed.