Advertisement
pleasedontcode

"Activate GNSS" rev_64

Jun 24th, 2024
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Activate GNSS"
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-06-24 14:36:28
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Use TinyGSM library to initialize modem with APN */
  21.     /* "airtelgprs.com", establish GSM connection, enable */
  22.     /* GNSS module for location data capture, and display */
  23.     /* all activity logs on Serial Monitor. */
  24. /****** SYSTEM REQUIREMENT 2 *****/
  25.     /* add #define TINY_GSM_MODEM_SIM7600 */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <TinyGsmClient.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF Hardware Serial *****/
  36. #define modem Serial2 // TX_PIN: D17, RX_PIN: D16
  37.  
  38. /***** SYSTEM REQUIREMENT 2 *****/
  39. #define TINY_GSM_MODEM_SIM7600
  40.  
  41. /***** SYSTEM REQUIREMENT 1 *****/
  42. #define TINY_GSM_DEBUG Serial
  43.  
  44. // Your GPRS credentials
  45. const char apn[] = "airtelgprs.com";
  46. const char gprsUser[] = "";
  47. const char gprsPass[] = "";
  48.  
  49. // Initialize the TinyGSM modem instance
  50. TinyGsm modem(modem);
  51. TinyGsmClient client(modem);
  52.  
  53. void setup(void)
  54. {
  55.     // Set console baud rate
  56.     Serial.begin(115200);
  57.     delay(10);
  58.  
  59.     // Set GSM module baud rate
  60.     modem.begin(115200);
  61.  
  62.     // Restart takes quite some time
  63.     // To skip it, call init() instead of restart()
  64.     Serial.println("Initializing modem...");
  65.     modem.restart();
  66.  
  67.     // Display modem info
  68.     String modemInfo = modem.getModemInfo();
  69.     Serial.print("Modem Info: ");
  70.     Serial.println(modemInfo);
  71.  
  72.     // Unlock your SIM card with a PIN if needed
  73.     // modem.simUnlock("1234");
  74.  
  75.     // Connect to the GPRS network
  76.     Serial.print("Connecting to APN: ");
  77.     Serial.println(apn);
  78.     if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
  79.         Serial.println("Failed to connect to GPRS");
  80.         while (true);
  81.     }
  82.     Serial.println("GPRS connected");
  83.  
  84.     // Enable GNSS
  85.     Serial.println("Enabling GNSS...");
  86.     modem.enableGPS();
  87. }
  88.  
  89. void loop(void)
  90. {
  91.     // Check if GNSS is enabled and get location data
  92.     if (modem.isGPS()) {
  93.         float lat, lon;
  94.         if (modem.getGPS(&lat, &lon)) {
  95.             Serial.print("Latitude: ");
  96.             Serial.println(lat, 6);
  97.             Serial.print("Longitude: ");
  98.             Serial.println(lon, 6);
  99.         } else {
  100.             Serial.println("Failed to get GPS data");
  101.         }
  102.     } else {
  103.         Serial.println("GNSS is not enabled");
  104.     }
  105.  
  106.     delay(10000); // Wait for 10 seconds before the next loop
  107. }
  108.  
  109. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement