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 compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-06-24 21:35:54
- ********* 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 *****/
- #define TINY_GSM_MODEM_SIM7600 // Define GSM modem model before including the library
- #include <TinyGsmClient.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF Hardware Serial *****/
- #define SerialMon Serial
- #define MODEM_RST 5
- #define MODEM_PWRKEY 4
- #define MODEM_POWER_ON 23
- #define MODEM_TX 27
- #define MODEM_RX 26
- #define I2C_SDA 21
- #define I2C_SCL 22
- /***** SYSTEM REQUIREMENT 1 *****/
- #define TINY_GSM_DEBUG SerialMon
- // Your GPRS credentials
- const char apn[] = "airtelgprs.com";
- const char gprsUser[] = "";
- const char gprsPass[] = "";
- // Initialize the TinyGSM modem instance
- TinyGsm modem(Serial2);
- TinyGsmClient client(modem);
- void setup(void)
- {
- // Set console baud rate
- SerialMon.begin(115200);
- delay(10);
- // Set GSM module baud rate
- Serial2.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
- delay(3000);
- // Restart takes quite some time
- // To skip it, call init() instead of restart()
- SerialMon.println("Initializing modem...");
- modem.restart();
- // Display modem info
- String modemInfo = modem.getModemInfo();
- SerialMon.print("Modem Info: ");
- SerialMon.println(modemInfo);
- // Unlock your SIM card with a PIN if needed
- // modem.simUnlock("1234");
- // Connect to the GPRS network
- SerialMon.print("Connecting to APN: ");
- SerialMon.println(apn);
- if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
- SerialMon.println("Failed to connect to GPRS");
- while (true);
- }
- SerialMon.println("GPRS connected");
- // Enable GNSS
- SerialMon.println("Enabling GNSS...");
- modem.enableGPS();
- }
- void loop(void)
- {
- // Check if GNSS is enabled and get location data
- float lat, lon;
- if (modem.getGPS(&lat, &lon)) {
- SerialMon.print("Latitude: ");
- SerialMon.println(lat, 6);
- SerialMon.print("Longitude: ");
- SerialMon.println(lon, 6);
- } else {
- SerialMon.println("Failed to get GPS data or 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