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

geofenceTemplate not triggering #39

Closed
joserocha3 opened this issue Mar 18, 2019 · 4 comments
Closed

geofenceTemplate not triggering #39

joserocha3 opened this issue Mar 18, 2019 · 4 comments

Comments

@joserocha3
Copy link
Contributor

Your Environment

  • Plugin version: flutter_background_geolocation: ^1.0.0-beta.5
  • Platform: iOS
  • OS version: 12.1
  • Device manufacturer / model: iPhone X Simulator
  • Flutter info (flutter doctor):
[✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.14.3 18D109, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.3)
[✓] VS Code (version 1.32.3)
[✓] Connected device (1 available)

• No issues found!
  • Plugin config:
await bg.BackgroundGeolocation.ready(bg.Config(
    desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
    persistMode: bg.Config.PERSIST_MODE_GEOFENCE,
    logLevel: bg.Config.LOG_LEVEL_VERBOSE,
    stopOnTerminate: false,
    enableHeadless: true,
    startOnBoot: true,
    reset: true,
    autoSync: true,
    httpRootProperty: '.',
    geofenceTemplate:
        '{ "query": "mutation { insert_location(objects: { lat: <%= latitude %> lng: <%= longitude %> } ) { affected_rows } }" }',
    url: '$TRACKER_HOST',
    locationAuthorizationRequest: 'Always',
    locationAuthorizationAlert: {
      'titleWhenNotEnabled': 'Location services not enabled',
      'titleWhenOff': 'Location services are OFF',
      'instructions':
          'Location services required to start earning points. Please enable \'Always\' in location settings.',
      'cancelButton': 'Cancel',
      'settingsButton': 'Settings'
    },
    speedJumpFilter: 300,
    foregroundService: true,
    notificationPriority: bg.Config.NOTIFICATION_PRIORITY_MIN,
    notificationTitle: 'Zone Tracker',
    notificationText: 'Zone search underway',
    notificationChannelName: 'Zone Tracker',
  ));

Expected Behavior

geofenceTemplate should be used when sending http request to server.

Actual Behavior

The regular http request is sent to the server. See server log below.

Context

Send a custom http request. It works fine for locationTemplate. I even used the same template and remove most of the fields for geofenceTemplate, however it seems to not be used.

Please note that the onGeofence even fires as expected. Plugin sees geofences and responds to them. Only missing piece is the use of geofenceTemplate.

Debug logs

╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 0 | df: -1.0m | age: 0.0s
╚═══════════════════════════════════════════════════════════
✅-[TSLocationManager locationManager:didUpdateLocations:] Acquired motionchange position: <+37.33233141,-122.03121860> +/- 5.00m (speed 0.00 mps / course -1.00) @ 3/18/19, 6:00:14 PM Central Daylight Time
🔵-[TSLocationManager startMonitoringStationaryRegion:radius:] Radius: 25
🔴-[TSLocationManager stopUpdatingLocation]
🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 5.0
🎾-[TSLocationManager startMonitoringSignificantLocationChanges]
ℹ️-[GeofenceDAO doInsert:geofence:] ef41ed99-576a-4333-8d43-34eb1677ee1e
ℹ️-[GeofenceDAO doInsert:geofence:] f1432aeb-1c86-4e76-80c5-51c7b06e6f64
ℹ️-[GeofenceDAO doInsert:geofence:] 068052bd-8d12-4ab3-8875-373c729322ed
ℹ️-[GeofenceDAO doInsert:geofence:] f73b97ee-0fae-4b42-80fc-372af2732714
ℹ️-[GeofenceDAO doInsert:geofence:] 7f8faff8-7914-4341-9fc8-088cb40fa859
ℹ️-[GeofenceDAO doInsert:geofence:] 94b49104-b190-4140-9a7d-e928c8e4ce8a
ℹ️-[GeofenceDAO doInsert:geofence:] fef5686d-3f90-4078-bfb9-305cd96a7bbf
ℹ️-[GeofenceDAO doInsert:geofence:] 9548d733-2cc1-4930-b016-f9a09622c6fe
ℹ️-[GeofenceDAO doInsert:geofence:] 004350c3-085b-49f1-b2bb-1ba14bbfbd6f
ℹ️-[GeofenceDAO doInsert:geofence:] 7a5e2ea5-3a69-4a49-9551-f9dda77e912b
ℹ️-[GeofenceDAO doInsert:geofence:] 5e1a0674-c247-4269-bb59-7235bd6dcf9c
ℹ️-[GeofenceDAO doInsert:geofence:] 991e4767-c40e-446b-927d-7a351580f786
ℹ️-[GeofenceDAO doInsert:geofence:] c028ff45-93b4-4690-b596-80857a3849b2
ℹ️-[GeofenceDAO doInsert:geofence:] 08d9a355-2eb2-4d03-b924-5166aee292dc
╔═══════════════════════════════════════════════════════════
║ -[TSGeofenceManager evaluateProximity:] Found 3 / 14 within 1000 m
╚═══════════════════════════════════════════════════════════
🎾-[TSGeofenceManager startMonitoringGeofence:] 7a5e2ea5-3a69-4a49-9551-f9dda77e912b
🎾-[TSGeofenceManager startMonitoringGeofence:] 5e1a0674-c247-4269-bb59-7235bd6dcf9c
🎾-[TSGeofenceManager startMonitoringGeofence:] 991e4767-c40e-446b-927d-7a351580f786
🎾-[TSGeofenceManager locationManager:didEnterRegion:] 7a5e2ea5-3a69-4a49-9551-f9dda77e912b
🎾-[TSGeofenceManager requestLocation]
ℹ️+[LocationAuthorization run:onCancel:] status: 3
🔵-[TSGeofenceManager locationManager:didUpdateLocations:] <+37.33156519,-122.03057969> +/- 30.00m (speed 3.13 mps / course 221.50) @ 3/18/19, 6:00:34 PM Central Daylight Time
╔═══════════════════════════════════════════════════════════
║ -[TSGeofenceManager fireGeofenceEvent:] 📢ENTER Geofence: 7a5e2ea5-3a69-4a49-9551-f9dda77e912b
╚═══════════════════════════════════════════════════════════
✅-[TSGeofenceManager fireGeofenceEvent:] INSERT: 1851C184-DC53-4CF4-B760-9C4EB7F521D6
╔═══════════════════════════════════════════════════════════
║ -[TSHttpService flush:error:] 
╚═══════════════════════════════════════════════════════════
✅-[BackgroundTaskManager createBackgroundTask] 82
✅-[TSHttpService schedulePost:] LOCKED: A21539D0-816B-46CD-B680-8286D76939F2
✅-[BackgroundTaskManager createBackgroundTask] 83
flutter: [geofence] - [GeofenceEvent identifier: 7a5e2ea5-3a69-4a49-9551-f9dda77e912b, action: ENTER]
⚠️-[TSHttpService doPost:] HTTP ERROR: 400
***
* {"errors":[{"extensions":{"path":"$","code":"parse-failed"},"message":"the key 'query' was not present"}]}
flutter: [onHttp] - [HttpEvent {success: false, status: 400, responseText: {"errors":[{"extensions":{"path":"$","code":"parse-failed"},"message":"the key 'query' was not prese...}]
✅-[TSHttpService post:error:] UNLOCKED: A21539D0-816B-46CD-B680-8286D76939F2
╔═══════════════════════════════════════════════════════════
║ -[TSHttpService finish:error:] Success: 0
╚═══════════════════════════════════════════════════════════
✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 82 OF (
    82,
    83
)
╔═══════════════════════════════════════════════════════════
║ -[TSGeofenceManager evaluateProximity:] Found 3 / 14 within 1000 m
╚═══════════════════════════════════════════════════════════
🔵-[TSGeofenceManager evaluateProximity:delay:]_block_invoke Re-evaluation timer fired
✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 83 OF (
    83

This is logged on the server:

{"timestamp":"2019-03-18T23:01:30.171+0000","level":"info","type":"http-log","detail":{"status":400,"query_hash":"23903da2af2b92d5a77f53bdaf229dfa2f5a3fde","http_version":"HTTP/1.1","query_execution_time":1.16292e-4,"request_id":"de711d52-1c63-4ef1-9d0d-676a91853116","url":"/v1alpha1/graphql","ip":"70.124.39.95","response_size":76,"user":{"x-hasura-role":"anonymous"},"method":"POST","detail":{"error":{"path":"$","error":"the key 'query' was not present","code":"parse-failed"},"request":"{\"coords\":{\"speed\":0,\"longitude\":-122.0312186,\"floor\":0,\"latitude\":37.332331410000002,\"accuracy\":5,\"altitude_accuracy\":-1,\"altitude\":0,\"heading\":-1},\"extras\":{},\"is_moving\":false,\"odometer\":0,\"uuid\":\"A21539D0-816B-46CD-B680-8286D76939F2\",\"activity\":{\"type\":\"unknown\",\"confidence\":100},\"battery\":{\"level\":-1,\"is_charging\":false},\"timestamp\":\"2019-03-18T23:00:02.709Z\"}"}}}
@christocracy
Copy link
Member

You probably have existing geofences rendered with the default template in the plugin db. Templates are never re-rendered.

clear the database with destroyLocations

@joserocha3
Copy link
Contributor Author

That got it working. It also explains some other behavior I was seeing that was puzzling me. I did not realize the geofenceTemplate would persist.

Thank you again for the quick reply.

@christocracy
Copy link
Member

christocracy commented Mar 18, 2019

The plugin persists JSON representations of events (location, geofence) at the time the events occur.

It doesn’t persist the actual event data.

The Schema is essentially like this:

| id | uuid | created_at | json |

If you change the template, the plugin has no original data to re-render.

I didn’t want to waste resources rendering the data for each http request. The JSON is rendered just once.

@joserocha3
Copy link
Contributor Author

I didn’t want to waste resources rendering the data for each http request. The JSON is rendered just once.

Good lookin' out.

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

No branches or pull requests

2 participants