SHARE
TWEET

Untitled

a guest Apr 11th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void get_GPS()
  2. {
  3.     sendATCommand("AT+CGNSINF","OK", 1000);
  4.  
  5.     // condition for valid response
  6.     while (strstr(AT_Buffer, "+CGNSINF: 1,1") != NULL)
  7.     {
  8.         delay(3000);
  9.         strtok(AT_Buffer, ",");
  10.         strtok(NULL, ",");
  11.         strtok(NULL, ",");
  12.         strtok(NULL, ",");
  13.         strtok(NULL, ",");
  14.         strtok(NULL, ",");
  15.         Serial.println("\n");
  16.         Serial.println(strtok(NULL, ","));
  17.  
  18.         //sendATCommand("AT+CGNSINF", "OK", 1000);
  19.     }
  20. }
  21. uint8_t sendATCommand(char* ATcommand, const char *expectedResponse, unsigned long timeout)
  22. {
  23.     uint8_t x = 0, answer = 0;
  24.  
  25.     memset(AT_Buffer, '\0', AT_BufferLength);    // Initialice the string
  26.     delay(100);
  27.     while (Serial1.available() > 0) Serial1.read();    // Clean the input buffer
  28.     if (ATcommand[0] != '\0')
  29.     {
  30.         Serial1.println(ATcommand);    // Send the AT command
  31.     }
  32.  
  33.     unsigned long previous = millis();
  34.  
  35.     // this loop waits for the answer
  36.     do {
  37.  
  38.         if (Serial1.available() != 0) {    // if there are data in the UART input buffer, reads it and checks for the asnwer
  39.             AT_Buffer[x] = Serial1.read();
  40.             //Serial.print(AT_Buffer[x]);
  41.             x++;
  42.             if (strstr(AT_Buffer, expectedResponse) != NULL)    // check if the desired answer (OK) is in the response of the module
  43.             {
  44.                 answer = 1;
  45.                 break;
  46.             }
  47.  
  48.         }
  49.     } while ((millis() - previous < timeout));    // Waits for the asnwer with time out
  50.  
  51.     return answer;
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top