Skip to content

Commit f7ee8c2

Browse files
author
Architecting
committed
Merge pull request #29 from jonathandreyer/master
Add feature for get operation mode and define default pattern with #define
2 parents c5edd2b + 464da4f commit f7ee8c2

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

ESP8266.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ bool ESP8266::setOprToStationSoftAP(uint8_t pattern1,uint8_t pattern2)
161161
}
162162
}
163163

164+
uint8_t ESP8266::getOprMode(uint8_t pattern1)
165+
{
166+
uint8_t mode;
167+
if (!qATCWMODE(&mode,pattern1)) {
168+
return 0;
169+
} else {
170+
return mode;
171+
}
172+
}
173+
164174
String ESP8266::getNowConecAp(uint8_t pattern)
165175
{
166176
String ssid;

ESP8266.h

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
#include "SoftwareSerial.h"
3030
#endif
3131

32-
#define VERSION_18 0X18
33-
#define VERSION_22 0X22
32+
#define VERSION_18 0X18
33+
#define VERSION_22 0X22
34+
#define DEFAULT_PATTERN 3
3435

3536
/**
3637
* You can modify the macro to choose a different version
@@ -153,7 +154,7 @@ class ESP8266 {
153154
* @retval false - failure.
154155
*
155156
*/
156-
bool setOprToStation(uint8_t pattern1=3,uint8_t pattern2=3);
157+
bool setOprToStation(uint8_t pattern1=DEFAULT_PATTERN,uint8_t pattern2=DEFAULT_PATTERN);
157158

158159
/**
159160
* Get the model values list.
@@ -170,7 +171,7 @@ class ESP8266 {
170171
* @retval true - success.
171172
* @retval false - failure.
172173
*/
173-
bool setOprToSoftAP(uint8_t pattern1=3,uint8_t pattern2=3);
174+
bool setOprToSoftAP(uint8_t pattern1=DEFAULT_PATTERN,uint8_t pattern2=DEFAULT_PATTERN);
174175

175176
/**
176177
* Set operation mode to station + softap.
@@ -180,7 +181,18 @@ class ESP8266 {
180181
* @retval true - success.
181182
* @retval false - failure.
182183
*/
183-
bool setOprToStationSoftAP(uint8_t pattern1=3,uint8_t pattern2=3);
184+
bool setOprToStationSoftAP(uint8_t pattern1=DEFAULT_PATTERN,uint8_t pattern2=DEFAULT_PATTERN);
185+
186+
/**
187+
* Get the operation mode.
188+
* @param pattern1 -1, send "AT+CWMODE_DEF?",-2,send "AT+CWMODE_CUR?",-3,send "AT+CWMODE?".
189+
*
190+
* @retval 0 - failure.
191+
* @retval 1 - mode Station.
192+
* @retval 2 - mode AP.
193+
* @retval 3 - mode AP + station.
194+
*/
195+
uint8_t getOprMode(uint8_t pattern1=DEFAULT_PATTERN);
184196

185197
/**
186198
* Search available AP list and return it.
@@ -197,7 +209,7 @@ class ESP8266 {
197209
* @param pattern -1, send "AT+CWJAP_DEF?",-2,send "AT+CWJAP_CUR?",-3,send "AT+CWJAP?".
198210
* @return the ssid of AP connected now.
199211
*/
200-
String getNowConecAp(uint8_t pattern=3);
212+
String getNowConecAp(uint8_t pattern=DEFAULT_PATTERN);
201213

202214
/**
203215
* Join in AP.
@@ -209,7 +221,7 @@ class ESP8266 {
209221
* @retval false - failure.
210222
* @note This method will take a couple of seconds.
211223
*/
212-
bool joinAP(String ssid, String pwd,uint8_t pattern=3);
224+
bool joinAP(String ssid, String pwd,uint8_t pattern=DEFAULT_PATTERN);
213225

214226
/**
215227
* Leave AP joined before.
@@ -232,15 +244,15 @@ class ESP8266 {
232244
* @retval false - failure.
233245
* @note This method should not be called when station mode.
234246
*/
235-
bool setSoftAPParam(String ssid, String pwd, uint8_t chl = 7, uint8_t ecn = 4,uint8_t pattern=3);
247+
bool setSoftAPParam(String ssid, String pwd, uint8_t chl = 7, uint8_t ecn = 4,uint8_t pattern=DEFAULT_PATTERN);
236248

237249
/**
238250
* get SoftAP parameters.
239251
*
240252
* @param pattern -1 send "AT+CWSAP_DEF?" -2 send "AT+CWSAP_CUR?" -3 send "AT+CWSAP?".
241253
* @note This method should not be called when station mode.
242254
*/
243-
String getSoftAPParam(uint8_t pattern=3);
255+
String getSoftAPParam(uint8_t pattern=DEFAULT_PATTERN);
244256

245257
/**
246258
* Get the IP list of devices connected to SoftAP.
@@ -257,7 +269,7 @@ class ESP8266 {
257269
* @return the state of DHCP.
258270
*
259271
*/
260-
String getDHCP(uint8_t pattern=3);
272+
String getDHCP(uint8_t pattern=DEFAULT_PATTERN);
261273

262274
/**
263275
* Set the state of DHCP.
@@ -267,7 +279,7 @@ class ESP8266 {
267279
* @retval true - success.
268280
* @retval false - failure.
269281
*/
270-
bool setDHCP(uint8_t mode, uint8_t en, uint8_t pattern=3);
282+
bool setDHCP(uint8_t mode, uint8_t en, uint8_t pattern=DEFAULT_PATTERN);
271283

272284
/**
273285
* make boot automatically connected.
@@ -283,7 +295,7 @@ class ESP8266 {
283295
* @return mac address.
284296
* @note This method should not be called when ap mode.
285297
*/
286-
String getStationMac(uint8_t pattern=3);
298+
String getStationMac(uint8_t pattern=DEFAULT_PATTERN);
287299

288300
/**
289301
* Set the station's MAC address.
@@ -292,15 +304,15 @@ class ESP8266 {
292304
* @retval true - success.
293305
* @retval false - failure.
294306
*/
295-
bool setStationMac(String mac,uint8_t pattern=3);
307+
bool setStationMac(String mac,uint8_t pattern=DEFAULT_PATTERN);
296308

297309
/**
298310
* Get the station's IP.
299311
* @param pattern -1 send "AT+CIPSTA_DEF?" -2 send "AT+CIPSTA_CUR?" -3 send "AT+CIPSTA?".
300312
* @return the station's IP.
301313
* @note This method should not be called when ap mode.
302314
*/
303-
String getStationIp(uint8_t pattern=3);
315+
String getStationIp(uint8_t pattern=DEFAULT_PATTERN);
304316

305317
/**
306318
* Set the station's IP.
@@ -312,7 +324,7 @@ class ESP8266 {
312324
* @retval false - failure.
313325
* @note This method should not be called when ap mode.
314326
*/
315-
bool setStationIp(String ip,String gateway,String netmask,uint8_t pattern=3);
327+
bool setStationIp(String ip,String gateway,String netmask,uint8_t pattern=DEFAULT_PATTERN);
316328

317329
/**
318330
* Get the AP's IP.
@@ -321,7 +333,7 @@ class ESP8266 {
321333
* @note This method should not be called when station mode.
322334
*
323335
*/
324-
String getAPIp(uint8_t pattern=3);
336+
String getAPIp(uint8_t pattern=DEFAULT_PATTERN);
325337

326338
/**
327339
* Set the AP IP.
@@ -331,7 +343,7 @@ class ESP8266 {
331343
* @retval false - failure.
332344
* @note This method should not be called when station mode.
333345
*/
334-
bool setAPIp(String ip,uint8_t pattern=3);
346+
bool setAPIp(String ip,uint8_t pattern=DEFAULT_PATTERN);
335347

336348
/**
337349
* start smartconfig.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ will be useful for Arduino lovers.
3737
bool setOprToSoftAP (void) : Set operation mode to softap.
3838
3939
bool setOprToStationSoftAP (void) : Set operation mode to station + softap.
40+
41+
uint8_t getOprMode(void) : Get the operation mode.
4042
4143
String getAPList (void) : Search available AP list and return it.
4244

0 commit comments

Comments
 (0)