Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "Activate GNSS"
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-06-24 21:35:04
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Use TinyGSM library to initialize modem with APN */
- /* "airtelgprs.com", establish GSM connection, enable */
- /* GNSS module for location data capture, and display */
- /* all activity logs on Serial Monitor. */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* add #define TINY_GSM_MODEM_SIM7600 */
- /****** END SYSTEM REQUIREMENTS *****/
- /********* User code review feedback **********
- #### Feedback 1 ####
- - do nothing
- ********* User code review feedback **********/
- /****** DEFINITION OF LIBRARIES *****/
- #include <TinyGsmClient.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF Hardware Serial *****/
- #define modem Serial2 // TX_PIN: D17, RX_PIN: D16
- /***** SYSTEM REQUIREMENT 2 *****/
- #define TINY_GSM_MODEM_SIM7600
- /***** SYSTEM REQUIREMENT 1 *****/
- #define TINY_GSM_DEBUG Serial
- // Your GPRS credentials
- const char apn[] = "airtelgprs.com";
- const char gprsUser[] = "";
- const char gprsPass[] = "";
- // Initialize the TinyGSM modem instance
- TinyGsm modem(modem);
- TinyGsmClient client(modem);
- void setup(void)
- {
- // Set console baud rate
- Serial.begin(115200);
- delay(10);
- // Set GSM module baud rate
- modem.begin(115200);
- // Restart takes quite some time
- // To skip it, call init() instead of restart()
- Serial.println("Initializing modem...");
- modem.restart();
- // Display modem info
- String modemInfo = modem.getModemInfo();
- Serial.print("Modem Info: ");
- Serial.println(modemInfo);
- // Unlock your SIM card with a PIN if needed
- // modem.simUnlock("1234");
- // Connect to the GPRS network
- Serial.print("Connecting to APN: ");
- Serial.println(apn);
- if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
- Serial.println("Failed to connect to GPRS");
- while (true);
- }
- Serial.println("GPRS connected");
- // Enable GNSS
- Serial.println("Enabling GNSS...");
- modem.enableGPS();
- }
- void loop(void)
- {
- // Check if GNSS is enabled and get location data
- if (modem.isGPS()) {
- float lat, lon;
- if (modem.getGPS(&lat, &lon)) {
- Serial.print("Latitude: ");
- Serial.println(lat, 6);
- Serial.print("Longitude: ");
- Serial.println(lon, 6);
- } else {
- Serial.println("Failed to get GPS data");
- }
- } else {
- Serial.println("GNSS is not enabled");
- }
- delay(10000); // Wait for 10 seconds before the next loop
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement