Skip to content

Commit fed9046

Browse files
committed
Added MDNS functions
1 parent 57bcc23 commit fed9046

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

ESP8266.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ bool ESP8266::stopServer(void)
263263
return stopTCPServer();
264264
}
265265

266+
bool ESP8266::enableMDNS(String hostname, String servername, uint32_t port)
267+
{
268+
return sATCMDNS(true, hostname, servername, port);
269+
}
270+
271+
bool ESP8266::disableMDNS(void)
272+
{
273+
return sATCMDNS(false, "", "", 0);
274+
}
275+
266276
bool ESP8266::send(const uint8_t *buffer, uint32_t len)
267277
{
268278
return sATCIPSENDSingle(buffer, len);
@@ -741,4 +751,25 @@ bool ESP8266::sATCIPSTO(uint32_t timeout)
741751
m_puart->println(timeout);
742752
return recvFind("OK");
743753
}
754+
bool ESP8266::sATCMDNS(bool enable, String hostname, String servername, uint32_t port)
755+
{
756+
String data;
757+
if (enable) {
758+
rx_empty();
759+
m_puart->print("AT+MDNS=1,\"");
760+
m_puart->print(hostname);
761+
m_puart->print("\",\"");
762+
m_puart->print(servername);
763+
m_puart->print("\",");
764+
m_puart->println(port);
765+
} else {
766+
rx_empty();
767+
m_puart->println("AT+MDNS=0");
768+
}
769+
data = recvString("OK", "ERROR");
770+
if (data.indexOf("OK") != -1 || data.indexOf("no change") != -1) {
771+
return true;
772+
}
773+
return false;
774+
}
744775

ESP8266.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,25 @@ class ESP8266 {
338338
*/
339339
bool stopServer(void);
340340

341+
/**
342+
Enable MDNS
343+
344+
@param hostname - MDNS host name.
345+
@param servername - MDNS server name.
346+
@param port - MDNS server port.
347+
@retval true - success.
348+
@retval false - failure.
349+
*/
350+
bool enableMDNS(String hostname, String servername, uint32_t port);
351+
352+
/**
353+
Disable MDNS
354+
355+
@retval true - success.
356+
@retval false - failure.
357+
*/
358+
bool disableMDNS(void);
359+
341360
/**
342361
* Send data based on TCP or UDP builded already in single mode.
343362
*
@@ -463,6 +482,7 @@ class ESP8266 {
463482
bool sATCIPMUX(uint8_t mode);
464483
bool sATCIPSERVER(uint8_t mode, uint32_t port = 333);
465484
bool sATCIPSTO(uint32_t timeout);
485+
bool sATCMDNS(bool enable, String hostname, String servername, uint32_t port);
466486

467487
/*
468488
* +IPD,len:data

0 commit comments

Comments
 (0)