Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TinyGPS++.h>
- #include <String.h>
- #include <SoftwareSerial.h>
- static const int RXPin = 4, TXPin = 3;
- static const int RXD = 9, TXD = 10;
- static const int TPL = 12;
- static const uint32_t GPSBaud = 9600;
- // The TinyGPS++ object
- TinyGPSPlus gps;
- // The serial connection to the GPS device
- SoftwareSerial serialGps(RXPin, TXPin);
- SoftwareSerial BLE(RXD, TXD);
- void setup(){
- Serial.begin(9600);
- serialGps.begin(GPSBaud);
- BLE.begin(GPSBaud);
- digitalWrite(TPL, LOW);
- }
- void loop(){
- // This sketch displays information every time a new sentence is correctly encoded.
- while (serialGps.available() > 0){
- gps.encode(serialGps.read());
- // if (gps.location.isUpdated()){
- double latitude = gps.location.lat();
- double longitude = gps.location.lng();
- char lokacijaLat [sizeof(gps.location.lat())];
- char lokacijaLng [sizeof(gps.location.lng())];
- memcpy(lokacijaLat,&latitude, sizeof(latitude));
- memcpy(lokacijaLng, &longitude, sizeof(longitude));
- char *con = concat(lokacijaLat, lokacijaLng);
- BLE.write(con);
- Serial.print(con);
- digitalWrite(TPL, HIGH);
- //}
- }
- }
- char concat(char a[], char b[]){
- int lena = strlen(a);
- int lenb = strlen(b);
- char con[lena+1+lenb];
- con[0] = a;
- con[lena] = " ";
- con[lena+1] = b;
- return con;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement