Vehicle Tracking Device based on SIM 808

I’m building a vehicle tracking device with an Arduino + Elecro SIM808 which is based on the project here It’s set the D7, D8 and the onModulePin is D9, I think. Anytime I run the following code, all I see is AT AT AT AT AT. I’ve pinned down the problem to the SendATCommand function. Is there something wrong with it? How do I make this work?

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); // Clean response buffer
    delay(100); // Delay to be sure no passed commands interfere
    while( Serial.available() > 0);    // Wait for clean input buffer
    Serial.println(ATcommand);    // Send the AT command 
    previous = millis();
    // this loop waits for the answer
        // if there are data in the UART input buffer, reads it and checks for the asnwer
        if(Serial.available() != 0){    
            response[x] =;
            // check if the desired answer is in the response of the module
            if (strstr(response, expected_answer) != NULL){
                answer = 1;
    // Waits for the answer with time out
    } while((answer == 0) && ((millis() - previous) < timeout));    
    return answer;

Is there something wrong with it?

Yes, indeed. It's missing setup() and loop().

How do I make this work?

Fix the problems that exist in the code you didn't post.