Example to connect to wifi automatically or start smartconfig if it is not connected
Diff: ESP8266.cpp
- Revision:
- 3:d52701d66b62
- Parent:
- 2:77388e8f0697
--- a/ESP8266.cpp Sun Dec 28 21:58:49 2014 +0000
+++ b/ESP8266.cpp Sun May 12 16:40:02 2019 +0000
@@ -82,6 +82,24 @@
AddChar(r, 0x00);
}
+// Receive reply until no character is received after a given timeout in miliseconds
+void ESP8266::RcvSingleReply(char * r) {
+ bool ended = 0;
+ char c;
+
+ strcpy(r, "");
+ while(!ended) {
+ if(comm.readable()) {
+ c = comm.getc();
+ AddChar(r, c);
+ }
+ if(c == 0x0D) {
+ ended = 1;
+ }
+ }
+ //AddChar(r, 0x00);
+}
+
// Gets the AP list. Parameter: the string to receive the list
void ESP8266::GetList(char * l) {
char rs[15];
@@ -147,7 +165,8 @@
char cmd[15];
strcpy(cmd, "AT+CIPSTATUS");
SendCMD(cmd);
- RcvReply(st, 2000);
+ RcvSingleReply(st);
+ //RcvReply(st, 2000);
}
// Starts server mode. Parameter: port to be used
@@ -165,4 +184,18 @@
char rs[20];
strcpy(rs, "AT+CIPSERVER=0");
SendCMD(rs);
+}
+
+// Starts SmartConfig
+void ESP8266::StartSmartConfig(void){
+ char rs[20];
+ strcpy(rs, "AT+CWSTARTSMART=1");
+ SendCMD(rs);
+}
+
+//Disable Echo
+void ESP8266::DisableEcho(void) {
+ char cmd[15];
+ strcpy(cmd, "ATE0");
+ SendCMD(cmd);
}
\ No newline at end of file