transistorsoft / flutter_background_geolocation

Sophisticated, battery-conscious background-geolocation & geofencing with motion-detection
https://www.transistorsoft.com/shop/products/flutter-background-geolocation
Other
646 stars 240 forks source link

Extras having issue going null #1209

Closed SushrutNaik10 closed 5 months ago

SushrutNaik10 commented 9 months ago

Your Environment

geofenceModeHighAccuracy: true , authorization: bg.Authorization( strategy: "JWT", accessToken: SharedPrefs().getAccessToken(), refreshToken: SharedPrefs().getRefreshToken(), refreshUrl: "https://11",

refreshPayload: {
   "Token":SharedPrefs().getRefreshToken()
},

),

extras: { "source": 1, "tenantId": 1, "vehicleId": userController.user.value!.vehicleId!, },

  desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
    distanceFilter: 0.0,
    stopOnTerminate: false,
    startOnBoot: true,
    debug: false,
    isMoving: true,
    heartbeatInterval: 60,
    locationUpdateInterval: 60000,
    fastestLocationUpdateInterval: 30000,
    enableHeadless: true,
      autoSync: true,
   // transistorAuthorizationToken: token,
    backgroundPermissionRationale: bg.PermissionRationale(
        title:
            "Allow Motor MotorMouth to access this device's location even when the app is closed or not in use.",
        message:
            "This app collects location data to enable recording your trips and calculate distance-travelled.",
        positiveAction: 'Change to "{backgroundPermissionOptionLabel}"',
        negativeAction: 'Cancel'),
    logLevel: bg.Config.LOG_LEVEL_VERBOSE

)).then((bg.State state) { bg.BackgroundGeolocation.startGeofences(); });


## Expected Behavior
Extras should have value

## Actual Behavior
Extras going null

{"location":{"event":"motionchange","is_moving":false,"uuid":"221bd91b-a9b7-4221-9063-b9fe86d914a1","timestamp":"2024-01-10T06:43:26.670Z","age":1356,"odometer":0,"coords":{"latitude":15.8313439,"longitude":74.5050677,"accuracy":30,"speed":-1,"speed_accuracy":-1,"heading":-1,"heading_accuracy":-1,"altitude":714.9,"ellipsoidal_altitude":714.9,"altitude_accuracy":4.6,"age":1363},"activity":{"type":"still","confidence":100},"battery":{"is_charging":true,"level":1},"extras":{}}

## Steps to Reproduce
<!--- reproduce this issue; include code to reproduce, if relevant -->
1.Whenever bg service is started extras are going null

## Context
to put extras in api call

## Debug logs
<!-- include iOS / Android logs
- ios XCode logs,
- use #getLog #emailLog methods (@see docs)
- Android: $ adb logcat -s TSLocationManager
-->
<details>
    <summary>Logs</summary>

``` <!-- syntax-highligting:  DO NOT REMOVE -->
PASTE_YOUR_LOGS_HERE

[c.t.l.a.BackgroundGeolocation removeListener] D/TSLocationManager( 8502): ✅ removeListener event: location D/TSLocationManager( 8502): [c.t.f.b.streams.StreamHandler onListen] location D/TSLocationManager( 8502): [c.t.l.a.BackgroundGeolocation removeListener] D/TSLocationManager( 8502): ✅ removeListener event: motionchange D/TSLocationManager( 8502): [c.t.f.b.streams.StreamHandler onListen] motionchange D/TSLocationManager( 8502): [c.t.f.b.streams.StreamHandler onListen] authorization W/TSLocationManager( 8502): [c.t.f.b.BackgroundGeolocationModule ready] W/TSLocationManager( 8502): ⚠️ #ready already called. Redirecting to #setConfig V/TSLocationManager( 8502): *** IS DEBUG? 1 D/TSLocationManager( 8502): [c.t.l.adapter.TSConfig e] ℹ️ Persist config, dirty: [authorization, authorization.accessToken, authorization.refreshToken, authorization.refreshPayload, extras] I/TSLocationManager( 8502): [c.t.l.http.HttpService flush] I/TSLocationManager( 8502): ╔═════════════════════════════════════════════ I/TSLocationManager( 8502): ║ HTTP Service (count: 4) I/TSLocationManager( 8502): ╠═════════════════════════════════════════════ I/WM-Processor( 8502): Moving WorkSpec (00c8fcfe-e43c-483e-b7cd-07836d388afc) to the foreground I/WM-SystemFgDispatcher( 8502): Started foreground service Intent { act=ACTION_START_FOREGROUND cmp=greengaadi.com.acb/androidx.work.impl.foreground.SystemForegroundService (has extras) } I/TSLocationManager( 8502): [c.t.l.u.BackgroundTaskManager$Task start] ⏳ startBackgroundTask: 17 D/TSLocationManager( 8502): [c.t.l.d.s.SQLiteLocationDAO first] D/TSLocationManager( 8502): ✅ Locked 1 records I/TSLocationManager( 8502): [c.t.l.http.HttpService a] I/TSLocationManager( 8502): 🔵 HTTP POST: 221bd91b-a9b7-4221-9063-b9fe86d914a1 W/TSLocationManager( 8502): [c.t.l.http.HttpService$f onResponse] W/TSLocationManager( 8502): ⚠️ Response: 400, Bad Request D/TSLocationManager( 8502): [c.t.l.d.s.SQLiteLocationDAO unlock] D/TSLocationManager( 8502): ✅ UNLOCKED: 221bd91b-a9b7-4221-9063-b9fe86d914a1 I/TSLocationManager( 8502): [c.t.l.u.BackgroundTaskManager$Task stop] ⏳ stopBackgroundTask: 17 I/WM-WorkerWrapper( 8502): Worker result SUCCESS for Work [ id=00c8fcfe-e43c-483e-b7cd-07836d388afc, tags={ com.transistorsoft.locationmanager.util.BackgroundTaskWorker } ] I/WM-SystemFgDispatcher( 8502): Stopping foreground service

christocracy commented 9 months ago

The plug-in inserts each recorded location into its SQLite database (no matter what). The extras are stamped onto each recorded location before INSERT.

When your http server returns 200, that recorded is DELETE FROM the database.

When your server returns an error, the plug-in will keep trying and trying and trying to upload that same record (eg a record with empty extras) until Config.maxDaysToPersist causes them to be automatically deleted.

You likely have a non-empty database containing records with empty extras from before you implemented Config.extras.

See api docs .getCount(), .getLocations(), .destroyLocations().

SushrutNaik10 commented 9 months ago

This issues is happening randomly if we uninstall and install it will work but sometimes when we log in it sends empty extra but in body it contains extras

christocracy commented 9 months ago

sends empty extra but in body it contains extras

I don't know what this means

SushrutNaik10 commented 9 months ago

post request : https://11e **** I/flutter (21584): body : {[Location {odometer: 0.0, activity: {confidence: 100, type: still}, extras: {tenantId: 1, source: 1, vehicleId: 6}, battery: {level: 1.0, is_charging: true}, uuid: 761fa8f1-e918-4b48-ae53-1a26fc123bd4, sample: true, age: 203428, coords: {altitude: 714.9, heading: -1.0, latitude: 15.8313447, accuracy: 56.1, heading_accuracy: -1.0, altitude_accuracy: 6.3, speed_accuracy: -1.0, speed: 0.0, age: 203441, longitude: 74.5050855, ellipsoidal_altitude: 714.9}, is_moving: false, timestamp: 2024-01-10T08:17:20.763Z}]}

This is what body consist but in at backend extras is coming null and server returns 400 bad request

christocracy commented 9 months ago

Show me corresponding json data from logs at your server where extras "are null". Are you sure the uuid match the logs at the device and server?

SushrutNaik10 commented 9 months ago

This is not happening all the time but happens sometime but i have checked uuid is same and it returns 400 error

SushrutNaik10 commented 9 months ago

server

UpdateLocation api {"location":{"event":"motionchange","is_moving":false,"uuid":"82914dcb-bab1-4db4-ad9e-22dfc1a4f2ca","timestamp":"2024-01-10T13:51:22.861Z","age":1451,"odometer":0,"coords":{"latitude":15.8313439,"longitude":74.5050677,"accuracy":30,"speed":-1,"speed_accuracy":-1,"heading":-1,"heading_accuracy":-1,"altitude":714.9,"ellipsoidal_altitude":714.9,"altitude_accuracy":4.6,"age":1459},"activity":{"type":"still","confidence":100},"battery":{"is_charging":true,"level":1},"extras":{}}

sent from plugin

I/TSLocationManager(17209): 🔵 HTTP POST: 82914dcb-bab1-4db4-ad9e-22dfc1a4f2ca D/TSLocationManager(17209): ✅ UNLOCKED: 82914dcb-bab1-4db4-ad9e-22dfc1a4f2ca I/TSLocationManager(17209): 🔵 HTTP POST: 82914dcb-bab1-4db4-ad9e-22dfc1a4f2ca D/TSLocationManager(17209): ✅ UNLOCKED: 82914dcb-bab1-4db4-ad9e-22dfc1a4f2ca I/TSLocationManager(17209): 🔵 HTTP POST: 82914dcb-bab1-4db4-ad9e-22dfc1a4f2ca D/TSLocationManager(17209): ✅ UNLOCKED: 82914dcb-bab1-4db4-ad9e-22dfc1a4f2ca I/flutter (17209): [onLocation] [Location {odometer: 0.0, activity: {confidence: 100, type: still}, extras: {}, event: motionchange, battery: {level: 1.0, is_charging: true}, uuid: 82914dcb-bab1-4db4-ad9e-22dfc1a4f2ca, age: 1451, coords: {altitude: 714.9, heading: -1.0, latitude: 15.8313439, accuracy: 30.0, heading_accuracy: -1.0, altitude_accuracy: 4.6, speed_accuracy: -1.0, speed: -1.0, age: 1459, longitude: 74.5050677, ellipsoidal_altitude: 714.9}, is_moving: false, timestamp: 2024-01-10T13:51:22.861Z}] I/flutter (17209): body : {[Location {odometer: 0.0, activity: {confidence: 100, type: still}, extras: {}, event: motionchange, battery: {level: 1.0, is_charging: true}, uuid: 82914dcb-bab1-4db4-ad9e-22dfc1a4f2ca, age: 1451, coords: {altitude: 714.9, heading: -1.0, latitude: 15.8313439, accuracy: 30.0, heading_accuracy: -1.0, altitude_accuracy: 4.6, speed_accuracy: -1.0, speed: -1.0, age: 1459, longitude: 74.5050677, ellipsoidal_altitude: 714.9}, is_moving: false, timestamp: 2024-01-10T13:51:22.861Z}]} I/flutter (17209): [location] - [Location {odometer: 0.0, activity: {confidence: 100, type: still}, extras: {}, event: motionchange, battery: {level: 1.0, is_charging: true}, uuid: 82914dcb-bab1-4db4-ad9e-22dfc1a4f2ca, age: 1451, coords: {altitude: 714.9, heading: -1.0, latitude: 15.8313439, accuracy: 30.0, heading_accuracy: -1.0, altitude_accuracy: 4.6, speed_accuracy: -1.0, speed: -1.0, age: 1459, longitude: 74.5050677, ellipsoidal_altitude: 714.9}, is_moving: false, timestamp: 2024-01-10T13:51:22.861Z}]

even tough extra is getting triggered in debug mode it is going null

as soon as i reinstall it works

christocracy commented 9 months ago

as soon as i reinstall it works

It's not the "re-install" that makes it "work", it's the emptying of the database.

Calling .destroyLocations() would empty the database and "make it work" too.

It's important to understand that the plug-in is not aware of your configured extras until the .ready(config) method resolves. You likely have some sort of timing issue where you're causing a location to be recorded before .ready(config) resolves, resulting in recording a location with empty extras -- the extras are not "null", they're empty.

github-actions[bot] commented 6 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 5 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.