Sending continuous phone (Android) precise gps location updates over bluetooth

I want to use my android phone to sent continuos precise GPS updates over bluetooth to mu arduino. I have gps coordinates going over bluetooth but the seem to stop and do not change . I have blocks which i can show the entire code included

Arduino code
// Imports
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>
#include <Servo.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include "./Definitions.h"

// GPS
TinyGPSPlus gps;
#define GPS_BAUD 9600

//Bluetooth
bluetoothSerial.begin(9600);
//Blynk.begin(bluetoothSerial, auth);
}

// Testing
void testDriveNorth() {
float heading = geoHeading();
int testDist = 5;
Serial.println(heading);

while(!(heading < 5 && heading > -5)) {
drive(testDist, heading);
heading = geoHeading();
Serial.println(heading);
delay(500);
}

stop();
}

void loop()
{
// Read all serial data available, as fast as possible
while (bluetoothSerial.available()) {

String a = bluetoothSerial.readString(); // Read the incoming data from Bluetooth

Serial.println(a); // Print the received data for debugging

// Split the received data into latitude and longitude

int commaIndex = a.indexOf(',');

 if (commaIndex != -1) {

String latitudeStr = a.substring(0, commaIndex);

String longitudeStr = a.substring(commaIndex+1);

// Convert the latitude and longitude strings to float values

float lat = latitudeStr.toFloat();

float lon = longitudeStr.toFloat();

// Now you have the latitude and longitude as separate variables (latitude and longitude)

}
// Reset for the next packet

started = false;

ended = false;

index = 0;

inData[index] = '\0';

GeoLoc phoneLoc;

phoneLoc.lat = Lat;

phoneLoc.lon = Long;

Serial.print(phoneLoc.lat, 7); Serial.print(", "); Serial.println(phoneLoc.lon, 7);

driveTo(phoneLoc, GPS_WAYPOINT_TIMEOUT);

}

}

I assume your lat/lon labels are populating and changing on your Android.

You might need set a ** Provider** to gps instead of fused ( your LocationSensor is probably defaulting to fused) .Your LocationSensor is not receiving a LocationChanged event and setting gps forces that to happen.

What does this mean to you Bill? What do you set TimeInterval to? How precise do you expect the coordinates determined by the gps. Most users can expect resolution to no better than 10 meters and occasionally as good as two meters.

Note, TimeInterval determines the minimum time interval, in milliseconds, that the sensor will try to use for sending out location updates. However, location updates will only be received when the location of the phone actually changes, and use of the specified time interval is not guaranteed. For example, if 30000 is used as the time interval, location updates will never be fired sooner than 30000ms, but they may be fired anytime after.

Values smaller than 30000ms (30 seconds) are not practical for most devices. Small values may drain battery and overwork the GPS.

Understood about the time interval. I would like get as accurate as possible. My problem is i can walk around the house and using a sattelite app i can see the coordinates change. Those changes are not transmitted over bluetooth. The first value shows up and then it seems to lock that and not send any additional updates.

..and that is probably happening because Google is forcing a fused Provider on you.

Then why would a satellite app on the same phone show it changing?

Because the MIT LocationSensor code has not been updated since 2014 and Google has changed how using the gps works. :cry: Your other application probably uses technology that forces gps. Without additional AI Blocks the LS uses fused on Android 10+ devices.

Hi, in addition to what @SteveJG has already said,
in your screen1 initialize you should better specify the following:
image
In this way every 1 second you should (it depends on your phone's GPS capabilities) have an update that can be get by the event
image

In my code AccuMin is trimmed according to several trials. Typically it's set to 5 or 10 (be careful to exclude value =0 !)
As @SteveJG has said, the update speed is not guaranteed, but these are the minimum values that I have used in my app's (running on LENOVO 8" and 10" pads) on a rally car, and it works almost fine (i.e. quick enough). In my use the battery drain is not a concern, 'cause the pads are supplied by the car (12Vdc => 5Vdc).

On another vehicle I've used a different solution: the use of an extension by @Juan_Antonio ( :+1:) called .com.KIO4_NmeaMessage.aix
The raw NMEA data is then made available by his extension and you can parse it to get the data you want.

Both modes run fast but, please be aware that the GPS signal in open space is far better than in closed/narrow/strict locations...

EDIT : I see now that you try the accuracy by walking around the house..hmmm.....in my first attempts, by walking in my garden either, it was never working so fine as running on a car, and in any case it highly depends on how many satellites your system is capable to link.

I knew there was something up. How would I add the AI blocks. I am new to all this and don't have a good working knowledge yet. Any help would be greatly appreciated.

I tried the KIO4 route but could not get the message to display.

What Android version. If Android 10+ you will have issues not present on Android lower than 10.

I need to run now.

Have you allowed the following permissions ?
image

No where is that?

In your phone's settings you shall allow coarse and fine location capabilities.

One more question and then I want to try some stuff. You said the "screen 1 initialize" which block is that?

Screen1 is the "master" screen, from where any app begins.
In the blocks page you have:
image
So in the event "initialize" you shall perform the LocationSensor initialization, as well.

I dont even have that. Thanks

AccuMin variable is defined by what? Do I initialize that in the Screen1

OK Admittedly I am horrible at this.

I put AccuMin in the middle of the page but cannot figure the block connectors to set the value

Here is a method that 'works'. GPS with Android 12 to set Provider to gps.

@uskiara @bill_snyder What you have to do depends on your Android.

That method works, if gps is enabled and therefore available in property AvailableProviders

Here is a solution which locks the provider to gps only if it is available

GPSsimple_2_Taifun.aia (13.1 KB)

Taifun

1 Like