Skip to content

Commit baf91de

Browse files
author
神农民
authored
Merge pull request itead#68 from tobiasschaber/feature/enableDHCP
added function to enable or disable DHCP usage
2 parents 75bcf8a + 6659c92 commit baf91de

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

ESP8266.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ bool ESP8266::joinAP(String ssid, String pwd)
147147
return sATCWJAP(ssid, pwd);
148148
}
149149

150+
bool ESP8266::enableClientDHCP(uint8_t mode, boolean enabled)
151+
{
152+
return sATCWDHCP(mode, enabled);
153+
}
154+
150155
bool ESP8266::leaveAP(void)
151156
{
152157
return eATCWQAP();
@@ -533,6 +538,28 @@ bool ESP8266::sATCWJAP(String ssid, String pwd)
533538
return false;
534539
}
535540

541+
bool ESP8266::sATCWDHCP(uint8_t mode, boolean enabled)
542+
{
543+
String strEn = "0";
544+
if (enabled) {
545+
strEn = "1";
546+
}
547+
548+
549+
String data;
550+
rx_empty();
551+
m_puart->print("AT+CWDHCP=");
552+
m_puart->print(strEn);
553+
m_puart->print(",");
554+
m_puart->println(mode);
555+
556+
data = recvString("OK", "FAIL", 10000);
557+
if (data.indexOf("OK") != -1) {
558+
return true;
559+
}
560+
return false;
561+
}
562+
536563
bool ESP8266::eATCWLAP(String &list)
537564
{
538565
String data;

ESP8266.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ class ESP8266 {
132132
*/
133133
bool joinAP(String ssid, String pwd);
134134

135+
136+
/**
137+
* Enable DHCP for client mode.
138+
*
139+
* @param mode - server mode (0=soft AP, 1=station, 2=both
140+
* @param enabled - true if dhcp should be enabled, otherwise false
141+
*
142+
* @note This method will enable DHCP but only for client mode!
143+
*/
144+
bool enableClientDHCP(uint8_t mode, boolean enabled);
145+
135146
/**
136147
* Leave AP joined before.
137148
*
@@ -435,6 +446,7 @@ class ESP8266 {
435446
bool qATCWMODE(uint8_t *mode);
436447
bool sATCWMODE(uint8_t mode);
437448
bool sATCWJAP(String ssid, String pwd);
449+
bool sATCWDHCP(uint8_t mode, boolean enabled);
438450
bool eATCWLAP(String &list);
439451
bool eATCWQAP(void);
440452
bool sATCWSAP(String ssid, String pwd, uint8_t chl, uint8_t ecn);

0 commit comments

Comments
 (0)