locked
Best Practice: GPS + Battery Consumption RRS feed

  • Question

  • Hi,

    I'm developing a program that gets gps data every 30 seconds. I'm using the GPS sample code (C#):

    Pseudo Code:

    gps.open()
    Loop: sleep for 30 seconds
         - get my coordinates

    This app runs in the background (no UI interface). My design is flawed and is a power hog. Has one designed something similar that does not consume battery as much? Any help would be appreciated.

     

    Thanks,

    Alice


    Thursday, June 3, 2010 9:30 PM

Answers

  • Not really. On some devices you can use the power management API to keep the GPS receiver "warm" even when the device is suspended. But power management behaviours are OEM dependent and this will only work on some devices. Other devices will totally ignore your calls to modify the power state of the GPS hardware while at the same time reporting that your call was successful. 

    If you power down the GPS hardware then when you power it back up it may not be able to return a position immediately.  For some devices it can take from 45 seconds to a minute for the device to get another GPS fix. That is close to the time interval at which you want to get the device's position which could make powering down the GPS hardware rather pointless. 

    If you want to save power you will need to either increase the time between polls (ex: getting position every few minutes instead of ever minute) or tolerate a reduction in positioning resolution (use WiFi or cell tower positioning). 


    Joel Ivory Johnson | http://www.j2i.net | Device Application Development MVP
    It takes all the running you can do to stay in one place.If you want to get somewhere else,you must try to run at least twice as fast as that.
    • Marked as answer by warrentang Thursday, June 10, 2010 2:35 AM
    Monday, June 7, 2010 3:25 PM

All replies

  • Turning on additional radios in the device is going to cause an increase in power consumption. If your program is running in unattended mode then it is going to raise power consumption a good bit too.  I'm not confident that getting the GPS position once every thirty seconds is really going to cause the GPS radio to be off for that period or if your devices power manager will decide to delay powering off the hardware. 

     

    Depending on the required precision of the coordinates you need you may want to try inferring location be the cell tower the phone is connected to. That will be the least power hungry location method. 


    Joel Ivory Johnson | http://www.j2i.net | Device Application Development MVP
    It takes all the running you can do to stay in one place.If you want to get somewhere else,you must try to run at least twice as fast as that.
    Friday, June 4, 2010 12:48 AM
  • So would closing gps (gps.close()) between polls help at all? And is there a better method to use besides  sleeping for 30 seconds? 


    Can explain unattended mode, thanks.

     

    -Alice

    Friday, June 4, 2010 1:42 AM
  • So would closing gps (gps.close()) between polls help at all? 

    I've no idea. That depends on the devices power management behaviour. That's completely OEM dependent and will vary from one device to another. On one of my devices doing that would cause the device to need to go through the process of reacquiring a fix in which case closing the GPS connection is disadvantageous. If you are trying to create a program for a specific device I'd say experiment and see what works. If you are making the program for a range of devices and if you don't need a high resolution position then go with cell tower based location. 


    Joel Ivory Johnson | http://www.j2i.net | Device Application Development MVP
    It takes all the running you can do to stay in one place.If you want to get somewhere else,you must try to run at least twice as fast as that.
    Friday, June 4, 2010 2:05 PM
  • Is there better way to do this besides "sleep"? Maybe use alarms or something similar?

    Friday, June 4, 2010 3:13 PM
  • What are you doing once you have the device's position? It's difficult to tell you a better way of polling the location without knowing how it's being used. Are you logging the devices position? Using it for a location based search?

     


    Joel Ivory Johnson | http://www.j2i.net | Device Application Development MVP
    It takes all the running you can do to stay in one place.If you want to get somewhere else,you must try to run at least twice as fast as that.
    Friday, June 4, 2010 5:38 PM
  • I'm sending it to a web server. 
    Friday, June 4, 2010 7:35 PM
  • A heuristic solution can be applied here. e.g. Say you determine that the GPS position has not changed in last X number of reads. There is a  chance that next read will also report no change in location. Now your application can sleep for 1 min (or whatever you think) rather than 30 seconds. After 1 minute if the location has changed, reduce the delay to 30 seconds again, otherwise sleep for 1 min or more again.

    : Onkar

    http://www.42gears.com
    [SureLock Studio: Quick and Easy way to lockdown Windows Mobile devices ]
    Sunday, June 6, 2010 4:37 AM
  •  

    ^ That's a good approach. But it is my understanding that once gps connection is opened it constant reading the coordinates. Is there a way to "sleep" the gps connection/thread? So for lets say 1 minute the GPS connection does nothing.

    What do you  thing about using GPS cache instead of reading the latest coordinates, you can read the last cached value. 

    Thanks,

    Alice

    Monday, June 7, 2010 3:01 PM
  • Not really. On some devices you can use the power management API to keep the GPS receiver "warm" even when the device is suspended. But power management behaviours are OEM dependent and this will only work on some devices. Other devices will totally ignore your calls to modify the power state of the GPS hardware while at the same time reporting that your call was successful. 

    If you power down the GPS hardware then when you power it back up it may not be able to return a position immediately.  For some devices it can take from 45 seconds to a minute for the device to get another GPS fix. That is close to the time interval at which you want to get the device's position which could make powering down the GPS hardware rather pointless. 

    If you want to save power you will need to either increase the time between polls (ex: getting position every few minutes instead of ever minute) or tolerate a reduction in positioning resolution (use WiFi or cell tower positioning). 


    Joel Ivory Johnson | http://www.j2i.net | Device Application Development MVP
    It takes all the running you can do to stay in one place.If you want to get somewhere else,you must try to run at least twice as fast as that.
    • Marked as answer by warrentang Thursday, June 10, 2010 2:35 AM
    Monday, June 7, 2010 3:25 PM