Battery consumption - sensors?

Hello, I have develop quite complex app that measure your BPM, your inactivity (via gyroscope), your GPS position and GSM signal strenght. After few tests, my app is working aprox. 7.5 hours till battery dead. I need to increase to 8-9 hours.

My first test setup: GPS localization every 1 minute, GSM strenght every 1 minute, BPM measure every 1 seconds. Wifi+LTE always on, display brightness 60%. ==> 7.5 hours

My second test setup: GPS every 2 minutes, GSM every 2 minutes, BPM measure every 30 seconds, WIFI+LTE always on, display brightness 60%. Result is the same. 7.5 hours.

SO. I think, that even I set GPS, GSM, BPM for 1 or 5minutes, sensors are “always on” (if you understand me).

This is how I did it:

    public void CheckingGPSPosition()
    {
        Device.StartTimer(TimeSpan.FromSeconds(1), () =>
        {
            _gps_seconds--;
           
            if (_gps_seconds == 0)
            {
                _gps_seconds = 120;
                GetActualGPS();
            }

            return _isTimerStart;
        });
    }

Is this correct…? After 120 seconds this function call GetActualGPS function:

    public async void GetActualGPS()
    {
         try
        {
            Tizen.Location.Locator locator;
            locator = new Locator(LocationType.Hybrid); // .Gps
            Tizen.Location.Location location = locator.GetLocation();

            if (location != null)
            {
                gps_location_latitude = location.Latitude.ToString().Replace(",", ".");
                gps_location_longtitude = location.Longitude.ToString().Replace(",", ".");

                Preferences.Set("location_latitude", gps_location_latitude);
                Preferences.Set("location_longlitude", gps_location_longtitude);
            }
            else
            {
                await DisplayAlert("0", "location is null", "OK");
            }
        }
        catch (Exception ex)
        {
            await DisplayAlert("Unable to get location", ex.Message, "OK");
        }
    }

And BPM like this, I set monitor.Interal to 30000 (30 seconds). But I am not sure, If it is right.

    private void OnPrivilegesGranted()
    {
        _monitor = new HeartRateMonitor();           
        _monitor.Interval = 30000;  
        _monitor.PausePolicy = SensorPausePolicy.None;

        StartMeasurement();
    }

  private void StartMeasurement()
    {
        _monitor.DataUpdated += OnMonitorDataUpdated;
        _monitor.Start();
    }
   private void OnMonitorDataUpdated(object sender, HeartRateMonitorDataUpdatedEventArgs e)
    {
        hrValue.Text = e.HeartRate > 0 ? e.HeartRate.ToString() : "0";
    }

I also have a small ElottieAnimation JSON - heartbeat. But in 90% my app is not visible, sensors working in background.

Hello,
Would you please tell what problem you are actually facing right now? You have mentioned that you have developed the app already and it is working approx. 7.5 hours till battery dead. That means the code is fine. Otherwise, it will not work that perfectly. Isn’t it?

OK my main problem is checking GPS position. I simply need call “findGPSposition” function every 1 minute and in this function I need start GPS - find location - write it down - close GPS.

This is my two samples. First work only first time. First time when I call this function, I get GPS position. After one minute I get the exactly the same position (even I am in other place)

private static Locator locator = null;

function GetGPS(){

            locator = new Locator(LocationType.Hybrid);
            locator.Start();
            //locator.Interval = 10;
            Tizen.Location.Location location = locator.GetLocation();

            if (location != null)
            {
                gps_location_latitude = location.Latitude.ToString();
                gps_location_longtitude = location.Longitude.ToString();

                latitude.Text = gps_location_latitude;
                longitude.Text = gps_location_longtitude;
            }
            else
            {
                latitude.Text = "no GPS";
            }

            locator.Stop(); 
            locator.Dispose();
            locator = null;
            location = null;
}

Second sample - I get actual position every minutes, but GPS is working nonstop == battery consumption is very big.

private static Locator locator = null;

function GetGPS(){
            locator = new Locator(LocationType.Hybrid);
            locator.Start();
            //locator.Interval = 10;
            Tizen.Location.Location location = locator.GetLocation();

            if (location != null)
            {
                gps_location_latitude = location.Latitude.ToString();
                gps_location_longtitude = location.Longitude.ToString();

                latitude.Text = gps_location_latitude;
                longitude.Text = gps_location_longtitude;
            }
            else
            {
                latitude.Text = "no GPS";
            }

            //locator.Stop(); 
            //locator.Dispose();
            locator = null;
            location = null;
 }

Simply I can not figure it out, how to simply start GPS - get location and close GPS so battery lasts longer

Hello,
As far as I understand if your application continuously uses GPS, GSM data, it will drain your battery drastically. You can not solve this battery issue from your code. To save your battery life you can run this process i.e. collect location data every after 2 mins when your application is in the foreground only.
For battery optimization, please go through the link- Best Practices for Location | Tizen Docs
I am not sure but you can try with alarm API once to start and stop the location service, it may help you a little bit.

Hello,

thank you for your reply. Main problem is, that my app is (and needed to) working in background too. In 90% user will have open this app all the time in foreground, but I develop it that it work on background too. Long story short - simply I need loop, which turn on gps - get location - turn off. Every for example 2 minutes. And this is for me big problem, because logicaly - turn on gsp - get location - turn off gsp should work, but in Tizen (xamarin .net) not. It work only once, I get first location. Then when you turn off gps and try turn on again = not working. Nothing happend.