Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include <TinyGPS++.h>
  2. #include <String.h>
  3. #include <SoftwareSerial.h>
  4.  
  5. static const int RXPin = 4, TXPin = 3;
  6. static const int RXD = 9, TXD = 10;
  7. static const int TPL = 12;
  8. static const uint32_t GPSBaud = 9600;
  9.  
  10. // The TinyGPS++ object
  11. TinyGPSPlus gps;
  12.  
  13. // The serial connection to the GPS device
  14. SoftwareSerial serialGps(RXPin, TXPin);
  15. SoftwareSerial BLE(RXD, TXD);
  16.  
  17. void setup(){
  18.   Serial.begin(9600);
  19.   serialGps.begin(GPSBaud);
  20.   BLE.begin(GPSBaud);
  21.   digitalWrite(TPL, LOW);
  22. }
  23.  
  24. void loop(){
  25.   // This sketch displays information every time a new sentence is correctly encoded.
  26.   while (serialGps.available() > 0){
  27.     gps.encode(serialGps.read());
  28.    // if (gps.location.isUpdated()){
  29.       double latitude = gps.location.lat();
  30.       double longitude = gps.location.lng();
  31.       char lokacijaLat [sizeof(gps.location.lat())];
  32.       char lokacijaLng [sizeof(gps.location.lng())];
  33.       memcpy(lokacijaLat,&latitude, sizeof(latitude));
  34.       memcpy(lokacijaLng, &longitude, sizeof(longitude));
  35.       char *con = concat(lokacijaLat, lokacijaLng);
  36.       BLE.write(con);
  37.       Serial.print(con);
  38.       digitalWrite(TPL, HIGH);
  39.      
  40.     //}
  41.   }
  42. }
  43.  
  44. char concat(char a[], char b[]){
  45.    int lena = strlen(a);
  46.    int lenb = strlen(b);
  47.    char con[lena+1+lenb];
  48.    con[0] = a;
  49.    con[lena] = " ";
  50.    con[lena+1] = b;
  51.    return con;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement