We have moved to a new Sailfish OS Forum. Please start new discussions there.
4

[question] What better to use "sleep" command or timer ?

asked 2016-01-03 01:07:07 +0300

Schturman gravatar image

Hi.
Maybe someone know what better to use in the script, the "sleep" command or timer that will start service file ?
What will eat lees our battery ?
For example my script always seat in background and run command every 20 sec with sleep command. Maybe instead sleep command, it better to create timer that will start service, and service will start my script once the same every 20 sec.
What you think ?
Thanks

edit retag flag offensive close delete

3 Answers

Sort by » oldest newest most voted
3

answered 2016-01-03 10:37:14 +0300

LVPVS gravatar image

Hei,

Try this:

timedclient-qt5 -a'whenDue;runCommand=/home/nemo/.scripts/my_command.sh@nemo' -r'minute=0;everyDayOfWeek;everyDayOfMonth;everyMonth' -e'APPLICATION=Name_of_my_Script;TITLE=Name_of_my_Script'

This will run your script every hour at :00.

For more options, use this command in CLI:

timedclient-qt5 --help

LVPVS over.

edit flag offensive delete publish link more

Comments

@LVPVS, i have a few questions about your answer:
1. Why it better than systemd.timer ?
2. How it work in deep sleep mode ?
3. You mean adding this line to the service file?
4. @nemo - mean run script as user? If I will add @root, it somehow should ask about password?
5. Can I remove this line:
minute=0;everyDayOfWeek;everyDayOfMonth;everyMonth
And use for example "second=20" to run script every 20 sec?
Or for example how to change it if I want to run script every 6 days in specific time ?
Thanks

Schturman ( 2016-01-03 12:59:59 +0300 )edit
1

Hei,

  1. It works in deep sleep mode. See calendar events.
  2. See the previous pount.
  3. Typing in CLI. Timedclient-qt5 is the built-in cron-alternative.
  4. You can handle root within your script.
  5. No. Instead, add everyHour and evetyMinutes, then seconds=20. Try day=6;hour=your_hour;minute=your_minute.

timedclient-qt5 --help is your friend. ;)

LVPVS over.

LVPVS ( 2016-01-03 13:17:40 +0300 )edit

Thanks! Will try...

Schturman ( 2016-01-03 13:26:15 +0300 )edit
1

answered 2016-01-03 01:26:43 +0300

lukas gravatar image

Maybe cron is suitable to your needs. I expect minimal battery load.

edit flag offensive delete publish link more

Comments

cron came to my mind as well, but be aware the possibility of phone overwriting your cronfile with every patch (don't know if they are altered or not on updates - don't see any reason for why they would alter them).

avhakola ( 2016-01-03 02:58:52 +0300 )edit

Thanks, I don't really want cause to people install cron...

Schturman ( 2016-01-03 07:45:20 +0300 )edit
0

answered 2016-01-03 03:11:37 +0300

g7 gravatar image

Both sleeps and systemd timers are blocked when the phone is in deep sleep.

You should use a patched version of cron (there was one SRPM floating around here/on TMO) or hook into timed.

No matter which method you use, waking up the phone every 20 seconds will really drain your battery.

If you instead don't care about running the script when the phone is suspended, I guess sleep would be the better choice given the short delay time.

edit flag offensive delete publish link more

Comments

You say both of them stops working in deep sleep mode, that means no differences what to use..
But I did a test with timer (20sec), started it and leaved phone for 35 min. When I checked log I found that my script started by timer every 20 sec and sent log 105 times... That mean or that the timer worked in deep sleep mode of the phone or timer prevented deep sleep mode ...
How I can check it ?

Schturman ( 2016-01-03 07:56:07 +0300 )edit

systemd timers? Were you charging the phone? The phone doesn't enter deep sleep while charging. Otherwise I guess the phone didn't enter deep sleep. Did the battery drain more than usual?

g7 ( 2016-01-03 14:25:30 +0300 )edit

I don't know if battery drain was more or not, I did test only for 35 min. And every 20 sec my script sent notification to event screen. It was only for test. Usually it should check something and if it have changes, script should send notification to event screen if not, it just finish script action.

Schturman ( 2016-01-03 14:41:40 +0300 )edit

Hm, maybe the short delay time is preventing the phone from entering in deep sleep? That, or in latest SailfishOS systemd has been patched to correctly wake up the system, but I doubt that.

Try, just to be sure, with a more ample timeout (10 minutes for example). Anyway IMHO if you want to be sure to wake up the system even when it's in deep sleep timed is the best option.

g7 ( 2016-01-03 17:46:26 +0300 )edit

Thanks for answer.

Schturman ( 2016-01-03 18:09:53 +0300 )edit
Login/Signup to Answer

Question tools

Follow
7 followers

Stats

Asked: 2016-01-03 01:07:07 +0300

Seen: 738 times

Last updated: Jan 03 '16