Open dokterbob opened 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.
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.
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().
@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
@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;
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):