Advertisement
pleasedontcode

"Activate GNSS" rev_65

Jun 24th, 2024
495
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 21:35:04
  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.  
  29. /********* User code review feedback **********
  30. #### Feedback 1 ####
  31. - do nothing
  32. ********* User code review feedback **********/
  33.  
  34. /****** DEFINITION OF LIBRARIES *****/
  35. #include <TinyGsmClient.h>
  36.  
  37. /****** FUNCTION PROTOTYPES *****/
  38. void setup(void);
  39. void loop(void);
  40.  
  41. /***** DEFINITION OF Hardware Serial *****/
  42. #define modem Serial2 // TX_PIN: D17, RX_PIN: D16
  43.  
  44. /***** SYSTEM REQUIREMENT 2 *****/
  45. #define TINY_GSM_MODEM_SIM7600
  46.  
  47. /***** SYSTEM REQUIREMENT 1 *****/
  48. #define TINY_GSM_DEBUG Serial
  49.  
  50. // Your GPRS credentials
  51. const char apn[] = "airtelgprs.com";
  52. const char gprsUser[] = "";
  53. const char gprsPass[] = "";
  54.  
  55. // Initialize the TinyGSM modem instance
  56. TinyGsm modem(modem);
  57. TinyGsmClient client(modem);
  58.  
  59. void setup(void)
  60. {
  61.     // Set console baud rate
  62.     Serial.begin(115200);
  63.     delay(10);
  64.  
  65.     // Set GSM module baud rate
  66.     modem.begin(115200);
  67.  
  68.     // Restart takes quite some time
  69.     // To skip it, call init() instead of restart()
  70.     Serial.println("Initializing modem...");
  71.     modem.restart();
  72.  
  73.     // Display modem info
  74.     String modemInfo = modem.getModemInfo();
  75.     Serial.print("Modem Info: ");
  76.     Serial.println(modemInfo);
  77.  
  78.     // Unlock your SIM card with a PIN if needed
  79.     // modem.simUnlock("1234");
  80.  
  81.     // Connect to the GPRS network
  82.     Serial.print("Connecting to APN: ");
  83.     Serial.println(apn);
  84.     if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
  85.         Serial.println("Failed to connect to GPRS");
  86.         while (true);
  87.     }
  88.     Serial.println("GPRS connected");
  89.  
  90.     // Enable GNSS
  91.     Serial.println("Enabling GNSS...");
  92.     modem.enableGPS();
  93. }
  94.  
  95. void loop(void)
  96. {
  97.     // Check if GNSS is enabled and get location data
  98.     if (modem.isGPS()) {
  99.         float lat, lon;
  100.         if (modem.getGPS(&lat, &lon)) {
  101.             Serial.print("Latitude: ");
  102.             Serial.println(lat, 6);
  103.             Serial.print("Longitude: ");
  104.             Serial.println(lon, 6);
  105.         } else {
  106.             Serial.println("Failed to get GPS data");
  107.         }
  108.     } else {
  109.         Serial.println("GNSS is not enabled");
  110.     }
  111.  
  112.     delay(10000); // Wait for 10 seconds before the next loop
  113. }
  114.  
  115. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement