Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Motion Change takes too long to update #1996

Closed
Nabeel07925 opened this issue Apr 12, 2024 · 9 comments
Closed

Motion Change takes too long to update #1996

Nabeel07925 opened this issue Apr 12, 2024 · 9 comments
Labels

Comments

@Nabeel07925
Copy link

Two issues/questions

  1. I have recently purchased the license for the React native sdk but it has some issues. The Motion type takes too long to update. For instance, if my motion changes from walking to driving (in_vehicle), it takes almost 5 minutes to update the motion state, absolutely not suitable for my use case. I am using the sdk for a car parking system I am developing and I need to capture the change in motion within a couple seconds at most.
  2. Sometimes the app doesn't capture motion at all in the background, I don't get any http request on my server when I start walking or even driving. I have to trigger the app again and again (open and close) to make it work, which sometimes work and sometimes doesn't.

Your Environment

System:

  • Plugin version: 4.15.2
  • Platform: Android
  • OS version: Ubuntu22.04
  • Device manufacturer / model: HP Zbook G6
  • React Native version (react-native -v): 0.72.6
  • java version: openjdk 11.0.22 2024-01-16
  • Plugin config:
React.useEffect(() => {
        if (!userId)
            return
        /// 1.  Subscribe to events.
        // BackgroundGeolocation.destroyLocations().then(res => {
        const onLocation = BackgroundGeolocation.onLocation((location) => {
            console.log('[onLocation]', location);
            setLocation(JSON.stringify(location, null, 2));
        })

        const onMotionChange = BackgroundGeolocation.onMotionChange((event) => {
            console.log('[onMotionChange]', event);
        });

        const onActivityChange = BackgroundGeolocation.onActivityChange((event) => {
            console.log('[onActivityChange]', event);
        })

        const onProviderChange = BackgroundGeolocation.onProviderChange((event) => {
            console.log('[onProviderChange]', event);
        })

        BackgroundGeolocation.onHttp(response => {
            console.log("[http] ", response);
        });


        /// 2. ready the plugin.
        BackgroundGeolocation.ready({
            // Geolocation Config
            desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
            distanceFilter: 0,
            stopOnStationary: false,
            locationUpdateInterval: 5000,  // Get a location every 5 seconds


            // Activity Recognition
            // stopTimeout: 5,
            // Application config
            debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
            logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
            enableHeadless: true,
            foregroundService: true,
            stopOnTerminate: false,   // <-- Allow the background-service to continue tracking when user closes the app.
            startOnBoot: true,        // <-- Auto start tracking when device is powered-up.
            // HTTP / SQLite config
            url: 'https://api.lotvector.com/api/v1/location',
            batchSync: false,       // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
            autoSync: true,         // <-- [Default: true] Set true to sync each location to server as it arrives.
            headers: {              // <-- Optional HTTP headers
                "X-FOO": "bar"
            },
            params: {               // <-- Optional HTTP params
                "user_id": userId
            },
            maxDaysToPersist: -1,
        }).then((state) => {
            // setEnabled(true)
            BackgroundGeolocation.start();
            console.log("- BackgroundGeolocation is configured and ready: ", state.enabled, state);
        }).catch(err => {
            setEnabled(false)
            console.log("error in starting motion tracking is ", err)
        });
    }, [userId]);

package.json

{
  "name": "parking-app-bare",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "expo start --dev-client",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@aws-amplify/react-native": "^1.0.9",
    "@aws-amplify/rtn-web-browser": "^1.0.9",
    "@aws-amplify/ui-react-native": "^2.0.7",
    "@react-native-async-storage/async-storage": "^1.22.3",
    "@react-native-community/netinfo": "^11.2.1",
    "@react-navigation/native": "^6.1.16",
    "@react-navigation/native-stack": "^6.9.25",
    "@turf/turf": "^6.5.0",
    "amazon-cognito-identity-js": "^6.3.7",
    "aws-amplify": "^6.0.9",
    "axios": "^1.6.3",
    "expo": "~49.0.15",
    "expo-notifications": "~0.20.1",
    "expo-splash-screen": "~0.20.5",
    "expo-status-bar": "~1.6.0",
    "install": "^0.13.0",
    "npm": "^10.5.0",
    "react": "18.2.0",
    "react-native": "0.72.6",
    "react-native-background-fetch": "^4.2.3",
    "react-native-background-geolocation": "^4.15.2",
    "react-native-geolocation-service": "^5.3.1",
    "react-native-gesture-handler": "^2.16.0",
    "react-native-get-random-values": "^1.10.0",
    "react-native-maps": "^1.13.0",
    "react-native-modalize": "^2.1.1",
    "react-native-safe-area-context": "^4.8.2",
    "react-native-screens": "^3.29.0",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-svg": "^14.1.0",
    "react-native-toast-message": "^2.2.0",
    "react-native-url-polyfill": "^2.0.0",
    "react-native-vector-icons": "^10.0.3"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true
}

Expected Behavior

I should immediately get both motion and location updates without any delay as soon as I start moving with correct motion type.

Actual Behavior

Sometimes, motion updates don't work in the background. It starts working after 10, 20 minutes all of a sudden. I don't have any geofencing enabled as of now. Also motion update is not correct most of the times. It gives walking when I am in a vehicle and sometimes gives in_vehicle state when I am idle or walking.

Steps to Reproduce

Just run the app with these configurations, terminate the app and check the updates in db or server. I am not sure if the issue I am facing is because of some misconfiguration or it's an actual bug.

Context

I am trying to develop a car parking application where the mobile of the user is used a tracker. I rely heavily on the motion and location updates from this library. When the motion type changes from in_vehicle to walking, I check a couple of events on my side and update the parking location of the car. Without motion update within seconds, the app doens't work correctly.

Debug logs

Don't have logs

PASTE_YOUR_LOGS_HERE
@christocracy
Copy link
Member

  1. There’s nothing that can be done about that.
  2. See https://dontkillmyapp.com

@christocracy
Copy link
Member

You’ll have better/worse performance on different devices.

my Pixel 6 performs beautifully.

@Nabeel07925
Copy link
Author

I see. Secondly, about the motion type not working properly, is it something wrong with my configuration or a bug in the library?

@christocracy
Copy link
Member

is it something wrong with my configuration or a bug in the library?

No. The Motion api is provide by Google Play Services. It’s proprietary code created by Google. This api provides nothing more than an ON/OFF switch. It is not configurable.

@Nabeel07925
Copy link
Author

Thanks for the quick response @christocracy. I see an option activityRecognitionInterval in the docs which is deprecated, that's why I asked. Actually I worked with the google activity recognition api earlier and it was pretty accurate but the downside was I wasn't able to configure it to work in the background (when app terminates) so I shifted to this library. Is there anything we can do to improve the results?

@christocracy
Copy link
Member

christocracy commented Apr 12, 2024

activityRecognitionInterval

That option is no longer used. It comes from the old Android ActivityRecognitionApi. This plug-in transitioned to the more modern ActivityTransitionApi years ago.

Is there anything we can do to improve the results?

I already answered this question: no. The api is either ON or OFF. Everything else depends upon Google’s proprietary code, the quality of the sensors on your device and the manufacturer’s version of the Android OS running on your device.

there is no configuration for the plug-in that affects the performance of the motion api.

@Nabeel07925
Copy link
Author

Got it. thanks for confirming.

Copy link

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

@github-actions github-actions bot added the stale label May 13, 2024
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants