I am working on a project in which I use arduino uno and ESP8266ex as wifi module on it. The connections of wires:
Arduino 5V --> 3.3V Regulator --> ESP: CH_PD (with 10k resistor) and VCC Arduino GND --> 3.3V Regulator --> ESP: GND and RST (reset is connected via a button and resistance) Arduino RX --> ESP TX Arduino TX --> Voltage divider (2k 1k resistors) --> ESP RX 5uF Capacitor --> Voltage regulator to prevent ESP to reset itself.
Now let me explain the problem I am having. I have two codes working on which I use ESP8266 as wifi module for arduino uno. In my first program I sent commands by hand:
#define ard_rx_esp_tx 2
#define ard_tx_esp_rx 3
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(ard_rx_esp_tx, ard_tx_esp_rx); // RX | TX
void setup()
{
int i = 0;
Serial.begin(9600); // communication with the host computer
while (!Serial);
// Start the software serial for communication with the ESP8266
ESPserial.begin(9600);
Serial.println("");
Serial.println(F("Remember to to set Both NL & CR in the serial monitor."));
Serial.println(F("Ready"));
Serial.println(F(""));
Serial.println(F("start"));
delay(1000);
}
void loop()
{
if ( ESPserial.available() ) {
char c = ESPserial.read();
Serial.print(c);
}
if ( Serial.available() ) {
ESPserial.write( Serial.read() );
}
}
I succeeded to open TCP connection with a server, to send a GET request which has a long (over 600 chars) and handle all the long response via SoftwareSerial read() function and print them all to the serial monitor. In short, this code can handle 600+ char response of a server which is:
The aim is to send these AT commands via "SoftwareSerial.print()" and put the whole response in a character array to parse its API-KEY. The code I have written for this so far:
#define ard_rx_esp_tx 2
#define ard_tx_esp_rx 3
char response[625];
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(ard_rx_esp_tx, ard_tx_esp_rx); // RX | TX
int i;
void setup()
{
Serial.begin(9600); // communication with the host computer
while (!Serial);
// Start the software serial for communication with the ESP8266
ESPserial.begin(9600);
Serial.println("");
Serial.println(F("Remember to to set Both NL & CR in the serial monitor."));
Serial.println(F("Ready"));
Serial.println(F(""));
Serial.println(F("start"));
delay(1000);
ESPserial.println("AT+CIPSTART=\"TCP\",\"domainname\",80");
delay(5000);
i = 0;
while ( ESPserial.available() ) {
response[i] = ESPserial.read();
i++;
}
response[i++] = '\0';
Serial.println(response);
for (i = 0; i < 625; i++) {
response[i] = '\0';
}
ESPserial.println("AT+CIPSEND=107");
delay(5000);
i = 0;
while ( ESPserial.available() ) {
response[i] = ESPserial.read();
i++;
}
response[i++] = '\0';
Serial.println(response);
for (i = 0; i < 625; i++) {
response[i] = '\0';
}
ESPserial.println("GET request to the server which has length 107 as indicated");
delay(5000);
i = 0;
while ( ESPserial.available() ) {
response[i] = ESPserial.read();
i++;
}
response[i++] = '\0';
Serial.println(response);
for (i = 0; i < 625; i++) {
response[i] = '\0';
}
}
void loop() {
// put your main code here, to run repeatedly:
}
Which prints the response before at the end of the "setup()" scope. Let me also put the photo of the output:
In conclusion the problem is that: SoftwareSerial has 64 byte buffer which can be increased up to 256 bytes and when I increase it the program is able to print 256 chars this time, however, in my first code, in which I sent AT commands manually, it can handle whole response in spite of its 64 bytes buffer and is able to print it to the serial monitor. In the second one I could not handle and store the whole response into a char array.
I hope I could explain my problem and pointed out at where exactly I am on my process with details.
What do you suggest me to do. What can I do while handling this big response and putting it into a character array? How can I handle whole response which stays on ESP8266ex' buffer initially and read by Arduino RX pin via SoftwareSerial class in which the function read() has 64 bytes array and can be increased up to 256 but no more?