Skip to main content
void setup() {
sendCommand("AT+RST\r\n", 5000, DEBUG, "ready");
sendCommand("AT+CWSAP_CUR=\"mega\",\"password123\",10,3\r\n", 4000, DEBUG, "OK");
}


String sendCommand(String command, const int timeout, boolean debug, String *answer)
{
String response = "";

Serial1.print(command); // send the read character to the esp8266

long int time = millis();

while ((time + timeout) > millis())
{
    while (Serial1.available())
    {
        // The esp has data so display its output to the serial window 
        char c = Serial1.read(); // read the next character.
        response += c;
    }

    //Waiting for the right answer and breaking a while loop
    if (response.indexOf(*answer) > 0)
    {
        break;
    }

}
if (debug)
{
    Serial.print(response);
}

return response;
}
void setup() {
    sendCommand("AT+RST\r\n", 5000, DEBUG, "ready");
    sendCommand("AT+CWSAP_CUR=\"mega\",\"password123\",10,3\r\n", 4000, DEBUG, "OK");
}

String sendCommand(String command, const int timeout, boolean debug, String *answer)
{
    String response = "";

    Serial1.print(command); // send the read character to the esp8266

    long int time = millis();

    while ((time + timeout) > millis())
    {
        while (Serial1.available())
        {
            // The esp has data so display its output to the serial window 
            char c = Serial1.read(); // read the next character.
            response += c;
        }

        //Waiting for the right answer and breaking a while loop
        if (response.indexOf(*answer) > 0)
        {
            break;
        }

    }

    if (debug)
    {
        Serial.print(response);
    }

    return response;
}
void setup() {
sendCommand("AT+RST\r\n", 5000, DEBUG, "ready");
sendCommand("AT+CWSAP_CUR=\"mega\",\"password123\",10,3\r\n", 4000, DEBUG, "OK");
}


String sendCommand(String command, const int timeout, boolean debug, String *answer)
{
String response = "";

Serial1.print(command); // send the read character to the esp8266

long int time = millis();

while ((time + timeout) > millis())
{
    while (Serial1.available())
    {
        // The esp has data so display its output to the serial window 
        char c = Serial1.read(); // read the next character.
        response += c;
    }

    //Waiting for the right answer and breaking a while loop
    if (response.indexOf(*answer) > 0)
    {
        break;
    }

}
if (debug)
{
    Serial.print(response);
}

return response;
}
void setup() {
    sendCommand("AT+RST\r\n", 5000, DEBUG, "ready");
    sendCommand("AT+CWSAP_CUR=\"mega\",\"password123\",10,3\r\n", 4000, DEBUG, "OK");
}

String sendCommand(String command, const int timeout, boolean debug, String *answer)
{
    String response = "";

    Serial1.print(command); // send the read character to the esp8266

    long int time = millis();

    while ((time + timeout) > millis())
    {
        while (Serial1.available())
        {
            // The esp has data so display its output to the serial window 
            char c = Serial1.read(); // read the next character.
            response += c;
        }

        //Waiting for the right answer and breaking a while loop
        if (response.indexOf(*answer) > 0)
        {
            break;
        }

    }

    if (debug)
    {
        Serial.print(response);
    }

    return response;
}
Source Link
luuxiii
  • 11
  • 1
  • 1
  • 2

How to pass a string pointer to a function

I'm working on a project, where I wish to use pointers. I had a very quick overview of using pointers in C in collage, but I don't know how to use them.

I want that function uses input String (answer) as pointer.

Calling function in setup block

void setup() {
sendCommand("AT+RST\r\n", 5000, DEBUG, "ready");
sendCommand("AT+CWSAP_CUR=\"mega\",\"password123\",10,3\r\n", 4000, DEBUG, "OK");
}


String sendCommand(String command, const int timeout, boolean debug, String *answer)
{
String response = "";

Serial1.print(command); // send the read character to the esp8266

long int time = millis();

while ((time + timeout) > millis())
{
    while (Serial1.available())
    {
        // The esp has data so display its output to the serial window 
        char c = Serial1.read(); // read the next character.
        response += c;
    }

    //Waiting for the right answer and breaking a while loop
    if (response.indexOf(*answer) > 0)
    {
        break;
    }

}
if (debug)
{
    Serial.print(response);
}

return response;
}