Electron + AssetTracker sleep mode

So i’ve got an Electron and AssetTracker v2 from a while back, and finally getting around to using it. I’m using the AssetTrackerRK library (though the problem also seemed to be there in the regular Asset Tracker library as well, but more pronounced).

Using the 3_WakeOnMove example, it seems to be working just fine, as long as once it’s detected its no longer moving, it stays still.

		if (accel.calibrateFilter(2000, 10000)) {
			// We've stopped moving and the accelerometer is calibrated

			// Uncomment this line to power down the GPS. It saves power but will increase the amount
			// of time to get a fix.
			digitalWrite(D6, HIGH);

			Serial.println("going to sleep");

			// If you use SLEEP_MODE_DEEP it's very important to make sure WKP is LOW before going to
			// sleep. If you go into SLEEP_MODE_DEEP with WKP high you will likely never wake up again
			// (until reset).
			if (digitalRead(WKP)) {
				// Try to calibrate again
			// Sleep

So here, if i stop moving the device long enough for the GPS to turn off, but start moving it BEFORE it goes to sleep, it wont wake back up.
If i stop moving it, and leave it still, it will wake up every time.

I’m really not sure where the problem here is. I’ve tried adding a digitalWrite(WKP,LOW) between the GPS off and sleep, but that didn’t seem to do anything.

It wakes up after the TIME_PUBLISH_BATTERY_SEC interval (22 minutes), and will wake on move after is sleeps again, until it gets “locked” like above again

It’s basically a hardware limitation with Gen 2 devices and the way the LIS3DH accelerometer wakes the device, and is not possible to fix. There’s a period between the time that digitalRead(WKP) and the system actually goes completely to sleep where if a motion wake event occurs, the device will go to sleep forever.

The reason is that the STM32F205 processor will fail to wake from sleep if the wakeup pin is already high when it sleeps on a pin rising.

Since there’s no way to pause the LIS3DH from generating wake requests for a period of time, this is really difficult to fix in a guaranteed way.

Gen 3 devices (nRF52840) and the Tracker SoM don’t have this issue.

Good to know. I’ve made a workaround where, if it wakes from a movement, the next wake time will drop to 30 seconds. If it wakes from the idle timer, go back to 22 minutes. It can still “break” twice in a row, causing it to jump back to 22 while it’s still moving, so there is still a bit of tweaking (maybe a gradual increase, or has to “idle” 5x at 30 seconds before going back up.)