Example to connect to wifi automatically or start smartconfig if it is not connected
Revision 3:d52701d66b62, committed 2019-05-12
- Comitter:
- Thrillex13
- Date:
- Sun May 12 16:40:02 2019 +0000
- Parent:
- 2:77388e8f0697
- Commit message:
- Primera version donde solo se se inicializa el wifi y se inicia startsmartconfig en caso de que no este conectado al wifi
Changed in this revision
| ESP8266.cpp | Show annotated file Show diff for this revision Revisions of this file |
| ESP8266.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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
--- a/ESP8266.h Sun Dec 28 21:58:49 2014 +0000 +++ b/ESP8266.h Sun May 12 16:40:02 2019 +0000 @@ -24,6 +24,7 @@ void SendCMD(char * s); void Reset(void); void RcvReply(char * r, int to); +void RcvSingleReply(char * r); void GetList(char * l); void Join(char * id, char * pwd); void GetIP(char * ip); @@ -34,6 +35,9 @@ void GetConnStatus(char * st); void StartServerMode(int port); void CloseServerMode(void); +//Funciones que yo he agregado +void StartSmartConfig(void); +void DisableEcho(void); private: Serial comm;