benagricola / tracker

Particle Electron GPS / GSM tracker based on fancy-asset-tracker demo and ULOC tracking example.
GNU General Public License v3.0
30 stars 24 forks source link

No motion detection (when awake) not working after initial motion #4

Open dokterbob opened 8 years ago

dokterbob commented 8 years ago

After starting the device and triggering motion, it starts counting down towards sleep due to no motion, regardless of whether or not motion has been generated.

Serial log (from startup until disconnect due to sleep):

Attempted to check GPS but it isn't active!
Attempted to check GPS but it isn't active!
Attempted to check GPS but it isn't active!
Attempted to check GPS but it isn't active!
[...]
Attempted to check GPS but it isn't active!
Sleeping in 139s due to no motion...
Attempted to check GPS but it isn't active!
Attempted to check GPS but it isn't active!
Attempted to check GPS but it isn't active!
[...]
Attempted to check GPS but it isn't active!
checkMotion: BUMP - Setting lastMotion to 44537
GPS: Enabling power to GPS shield...
GPS: Starting serial ports...
GPS: Requesting hot restart...
GPS: Setting data format for ALLDATA...
GPS: Turning off antenna updates...
checkMotion: Connecting...
Sleeping in 157s due to no motion...
Sleeping in 147s due to no motion...
Sleeping in 137s due to no motion...
Sleeping in 127s due to no motion...
Sleeping in 117s due to no motion...
Sleeping in 107s due to no motion...
Publish: No GPS Fix, reporting Cellular location...
Sleeping in 97s due to no motion...
Sleeping in 87s due to no motion...
Sleeping in 77s due to no motion...
Sleeping in 67s due to no motion...
Sleeping in 57s due to no motion...
Sleeping in 47s due to no motion...
Sleeping in 37s due to no motion...
Sleeping in 24s due to no motion...
Sleeping in 14s due to no motion...
Sleeping in 4s due to no motion...
No motion in 180021 ms, sleeping...
GPS: Disabling power to GPS shield...```
dokterbob commented 8 years ago

Ah. The motion detection does in fact seem to work, only the motion is not reported on the serial. Please let me know if you can confirm this, I'll change the ticket such that it reflects this as a worthwhile feature.

benagricola commented 8 years ago

When motion detection resets the no-motion timer, this should print the checkMotion: BUMP message... to serial.

If that doesn't happen, it's possible that the Electron is currently running some other code which doesn't allow the motion to be picked up.

For example - the ULOC code must send the ULOC request, then sleep and loop for 10-20 seconds to receive the response. The application loop can't continue at this point because if it does so, the modem code may decode the UULOC URC which we need to receive.

During the delay timer within the ULOC code we can't check for motion so it's possible to miss motion during this.

This will be fixed when the official cellular locate API is added to the firmware (don't know what the timescales are for that though), although from what I saw it wouldn't be that hard to add 'ghetto' support in some manner.

The Adafruit LIS3DH library does have a 'getEvent' function which may be able to return the 'last' motion event from the Accelerometer - I'm not sure if it returns an event timestamp yet (haven't tested) but if it does, this may be a smarter way to check for motion rather than polling the value of the WKP pin in a loop.

benagricola commented 8 years ago

Recent commits modify the way motion is detected to use inertial interrupts rather than click detection. When the LIS3DH detects motion, it'll set the INT1 (WKP on the Electron) pin HIGH until the INT1_SRC register is read during loop().

DigiDr commented 8 years ago

@benagricola

Am also having problems with motion after idle sleep. Wakes up the first time, but not the second! Will edit later with more details after some experimentation

Alain1405 commented 7 years ago

@KuDeTa @benagricola I also have this issue. The accelerometers work at startup, but after a few minute I see 0s from the acceleration values. I suspect it's due to the GPS and Cellular threads (I commented those out and the accelerometer worked without issues) blocking the execution. The result is no motion detected of course and no blue LED.

Here's how I get the acceleration:

float get_acceleration() {

  sensors_event_t event;
  accel.getEvent(&event);
  return sqrt((event.acceleration.x * event.acceleration.x) + (event.acceleration.y * event.acceleration.y) + (event.acceleration.z * event.acceleration.z));
}

and my check for motion:

bool motion = digitalRead(WKP);
float a = get_acceleration();
motion = motion || a > 11;