pleasedontcode

Bluetooth GPS rev_01

Aug 8th, 2025
700
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: Bluetooth GPS
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-08-08 07:12:51
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* a wanna send my gps location form my mobile to esp */
  21.     /* 32 via Bluetooth using app "nRF connect" */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /* START CODE */
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <BluetoothSerial.h> // Include the BluetoothSerial library for Bluetooth communication
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /****** GLOBAL OBJECTS *****/
  33. BluetoothSerial SerialBT; // Create a BluetoothSerial object
  34.  
  35. void setup(void)
  36. {
  37.   // Initialize serial communication for debugging
  38.   Serial.begin(115200);
  39.   Serial.println("ESP32 Bluetooth GPS Receiver");
  40.  
  41.   // Initialize Bluetooth serial with device name
  42.   if (!SerialBT.begin("ESP32_GPS")) {
  43.     Serial.println("An error occurred initializing Bluetooth");
  44.   } else {
  45.     Serial.println("Bluetooth initialized. Waiting for connections...");
  46.   }
  47. }
  48.  
  49. void loop(void)
  50. {
  51.   // Check if Bluetooth client is connected
  52.   if (SerialBT.hasClient()) {
  53.     // Check if data is available from Bluetooth
  54.     if (SerialBT.available()) {
  55.       String incomingData = SerialBT.readStringUntil('\n'); // Read incoming data until newline
  56.       Serial.print("Received GPS Data: ");
  57.       Serial.println(incomingData);
  58.      
  59.       // Here you can add code to process the GPS data
  60.       // For example, parse latitude and longitude if data is formatted accordingly
  61.     }
  62.   }
  63.   delay(20); // Small delay to prevent overwhelming the CPU
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment