Hi guys,
I need a little help.
I drive an ESP01S by an Arduino Uno with AT commands( no ESP library). The sketch is below and works fine but in same cases the statement "while(SSerial.available()>0){g=SSerial.read();Serial.print(g);" don't return all data.
I try to explain with an example:
AT+CIFSR
serial.print return only this ( I see it on serial monitor):
+CIFSR:APIP,"192.168.4.1"
+CIFSR:APMAC,"52:02:91:79:
but the correct one should be ( when I connect ESP on serial adapterCH340G):
AT+CIFSR
+CIFSR:APIP,"192.168.4.1"
+CIFSR:APMAC,"52:02:91:79:27:7e"
+CIFSR:STAIP,"192.168.43.93"
+CIFSR:STAMAC,"50:02:91:79:27:7e"
How can I edit the sketch for capture all data ( maybe an issue due to serialbuffer size?)
#include <SoftwareSerial.h>
char g ;
SoftwareSerial SSerial(10, 11); // RX, TX
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
SSerial.begin(9600);//porta myseriale per debug
while(!SSerial);
while(!Serial);
//SSerial.println("connesso");
Serial.println("connesso");
Serial.print("verifico connessione ESP: ");
SSerial.print("AT\r\n");
delay(500);
while(SSerial.available()){ g=SSerial.read();Serial.print(g);}
delay(1500);
Serial.println();
Serial.print("verifico MODE= ");
SSerial.println("AT+CWMODE?");
delay(1500);
while(SSerial.available()>0){g=SSerial.read();Serial.print(g);}
Serial.println("Reti WIFI disponibili: ");
SSerial.print("AT+CWLAP\r\n");
//Serial.println();
delay(5000);
while(SSerial.available()>0){g=SSerial.read();Serial.print(g);}
Serial.println();
Serial.println("Connessione alla rete ASUS: ");
SSerial.print("AT+CWJAP=\"ASUS OFFICE\",\"3ec326ab0ad8\"\r\n");
delay(5000);
while(SSerial.available()>0){g=SSerial.read();Serial.print(g);}
Serial.println();
SSerial.print("AT+CIFSR\r\n");
delay(5000);
while(SSerial.available()>0){g=SSerial.read();Serial.print(g);}
Serial.println();
//while(SSerial.available()>0){ g=SSerial.read();Serial.print(g);}
////delay(2000);
Serial.println("Settaggio client: ");
SSerial.print("AT+CIPMUX=1\r\n");
delay(1500);
while(SSerial.available()>0){g=SSerial.read();Serial.print(g);}
Serial.println("Settaggio porta server: ");
SSerial.print("AT+CIPSERVER=1,80\r\n");
delay(1500);
while(SSerial.available()>0){g=SSerial.read();Serial.print(g);}
SSerial.print("AT+GMR\r\n");
delay(1000);
while(SSerial.available()>0){g=SSerial.read();Serial.print(g);}
//delay(2000);
//Serial.println("Indirizzi IP: ");
//delay(2000);
//SSerial.print("AT+CIFSR");
//delay(2000);
//while(SSerial.available()>0){g=SSerial.read();Serial.print(g);}
}
void loop() {
// put your main code here, to run repeatedly:
}
If the condition inside the while-loop is no longer true the while-loop will be exited.
Almost regardless of what you want to do all in all with your arduino using the AT-firmware of an ESP01S is a big hassle.
If you can afford to buy a ESP32-nodeMCU I recommend this.
Then you can do all the coding for
reading in sensors and switches,
showing data on a display
sending data over WiFi to whatever you want
with a single microcontroller because the WiFi is onboard.
If you insist using the Arduino and the ESP01 you will have to write code that checks if the received characters end as expected
and
if the end-character is not yet received within a timeout to handle this situation of not having received the expected answer.
All this checking for the expected answer with timeouts
reduces to a simple function-call if you use an ESP32 stand-alone
Hi StefanL38, thanks for your answer. I agree with your idea, but i want to "play" again with ESP01S and AT command, I think is instructive for myself...so yesterday I verified that softwareserial was in overflow ( I use the overflow method). Now i try to risolve this. Any idea?( maybe with a char array?)Thanks a lot