Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void get_GPS()
- {
- sendATCommand("AT+CGNSINF","OK", 1000);
- // condition for valid response
- while (strstr(AT_Buffer, "+CGNSINF: 1,1") != NULL)
- {
- delay(3000);
- strtok(AT_Buffer, ",");
- strtok(NULL, ",");
- strtok(NULL, ",");
- strtok(NULL, ",");
- strtok(NULL, ",");
- strtok(NULL, ",");
- Serial.println("\n");
- Serial.println(strtok(NULL, ","));
- //sendATCommand("AT+CGNSINF", "OK", 1000);
- }
- }
- uint8_t sendATCommand(char* ATcommand, const char *expectedResponse, unsigned long timeout)
- {
- uint8_t x = 0, answer = 0;
- memset(AT_Buffer, '\0', AT_BufferLength); // Initialice the string
- delay(100);
- while (Serial1.available() > 0) Serial1.read(); // Clean the input buffer
- if (ATcommand[0] != '\0')
- {
- Serial1.println(ATcommand); // Send the AT command
- }
- unsigned long previous = millis();
- // this loop waits for the answer
- do {
- if (Serial1.available() != 0) { // if there are data in the UART input buffer, reads it and checks for the asnwer
- AT_Buffer[x] = Serial1.read();
- //Serial.print(AT_Buffer[x]);
- x++;
- if (strstr(AT_Buffer, expectedResponse) != NULL) // check if the desired answer (OK) is in the response of the module
- {
- answer = 1;
- break;
- }
- }
- } while ((millis() - previous < timeout)); // Waits for the asnwer with time out
- return answer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement