Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hpssjellis/5ffad74751a224bb9f528f54cd4afba6 to your computer and use it in GitHub Desktop.
Save hpssjellis/5ffad74751a224bb9f528f54cd4afba6 to your computer and use it in GitHub Desktop.

Revisions

  1. @recyclerobot recyclerobot revised this gist Aug 16, 2014. 1 changed file with 6 additions and 9 deletions.
    15 changes: 6 additions & 9 deletions Arduino AT command function
    Original file line number Diff line number Diff line change
    @@ -4,16 +4,14 @@ int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeou
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100); // Initialice the string
    memset(response, '\0', 100); // Clean response buffer

    delay(100);
    delay(100); // Delay to be sure no passed commands interfere

    while( Serial.available() > 0) Serial.read(); // Clean the input buffer
    while( Serial.available() > 0) Serial.read(); // Wait for clean input buffer

    Serial.println(ATcommand); // Send the AT command


    x = 0;
    previous = millis();

    // this loop waits for the answer
    @@ -23,13 +21,12 @@ int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeou
    response[x] = Serial.read();
    x++;
    // check if the desired answer is in the response of the module
    if (strstr(response, expected_answer) != NULL)
    {
    if (strstr(response, expected_answer) != NULL){
    answer = 1;
    }
    }
    // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < timeout));
    // Waits for the answer with time out
    } while((answer == 0) && ((millis() - previous) < timeout));

    return answer;
    }
  2. @recyclerobot recyclerobot created this gist Aug 16, 2014.
    35 changes: 35 additions & 0 deletions Arduino AT command function
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout){

    uint8_t x=0, answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100); // Initialice the string

    delay(100);

    while( Serial.available() > 0) Serial.read(); // Clean the input buffer

    Serial.println(ATcommand); // Send the AT command


    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{
    // if there are data in the UART input buffer, reads it and checks for the asnwer
    if(Serial.available() != 0){
    response[x] = Serial.read();
    x++;
    // check if the desired answer is in the response of the module
    if (strstr(response, expected_answer) != NULL)
    {
    answer = 1;
    }
    }
    // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < timeout));

    return answer;
    }