I’ve been working on a “simple” Electron locator using the Google Maps integration. I wanted to work sleep modes into it, because I want it to run on battery, so that it would publish a location, then sleep for a while. At one point I had that working as expected. But then I wanted to get fancy and have it determined whether it was stationary or in motion, and sleep longer or shorter, accordingly. In the process of making those changes, I managed to screw up my state tracking, so now it’s not sleeping/waking/tracking correctly. I think part of my problem is that I started with a particular sleep mode example which just wasn’t the most appropriate for my use-case. It’s not the example’s fault, it’s mine.
So, anyhow, I’m going to pretty much re-write it from scratch, based on what I’ve learned. so far. My question isn’t about making the code work, I can do that. My question is:
I’m basically going to save the previously known location (as
retained variables), and compare it to the current location and accuracy level to see if we’ve moved or not. If we are moving, I want to track location probably about every 1-3 minutes (maybe sleeping in between?). If we’ve stopped, I plan to increase the sleep time by one minute after each wake, up to a maximum of, say, 15 minutes.
Based on those criteria, what are the best strategies for me to use regarding the sleep modes vs maybe just doing
cellular_off(NULL) between readings?
But what about for the shallow end of the pool? If I want to get location once a minute, is it worth sleeping at all? Or turning the modem off and back on again? What about for 2 minutes, or 3?