Fcron

m (Auto 2G with Wi-Fi)
 
(41 intermediate revisions not shown)
Line 1: Line 1:
-
[http://fcron.free.fr Fcron] is standard Linux scheduler used to schedule any command at any time. So this means that it doesn't have any limits and you can schedule just about anything. It is run as daemon in the background so you don't need to worry about it. You set it up with a config file which contains schedule.
+
[http://fcron.free.fr fcron] is standard Linux scheduler used to schedule any command at any time. So this means that it doesn't have any limits and you can schedule just about anything. It is run as daemon in the background so you don't need to worry about it. You set it up with a config file which contains schedule.
 +
==Alternatives==
-
'''Alternatives:'''
+
'''cron'''
 +
Why not: cron is older than fcron and doesn't sleep between events.
-
'''cron''': Why not? - Cron is older than fcron and doesn't sleep between events.
 
-
'''anacron''': Why not? - Anacron is used to schedule daily jobs, fcron can schedule to minutes.
+
'''anacron'''
-
[http://maemo.org/packages/view/ses/ '''ses''']: Why not? - Ses is buggy, buggy and buggy. It doesn't even uninstall properly.
+
Why not: anacron is used to schedule daily jobs, fcron can schedule to minutes.
-
[http://talk.maemo.org/showthread.php?t=46594 '''Alarmed''']: It is the best alternative with a big plus (GUI), but also a big minus (no CLI). You can use custom command, so you can schedule anything, but you can't schedule it anytime (alarmed daemon doesn't provide an option for every possible time). It also needs python (because of the GUI, daemon itself doesn't need it), which consumes space.
 
 +
[http://maemo.org/packages/view/ses/ '''ses''']
-
Right now, fcron has to be:
+
Why not: ses is buggy, buggy and buggy. It doesn't even uninstall properly.
-
- ported again so we have latest version and 100% compatibility (this one searches for vi in /scratchbox, so editor has to be defined manually each time fcrontab is run
+
[http://talk.maemo.org/showthread.php?t=46594 '''Alarmed''']
-
- repacked, because a lot of stuff after the install has to be done manually - with proper packaging whole "Installation" chapter from this wiki would be unnecessary
+
Alarmed uses the Nokia's (non-standard) "alarmd" daemon which is already part of Maemo 5 and uses Python/Qt for GUI. You can use custom commands and set single and/or recurring events.
-
- uploaded to official maemo.org repositories, so it can be used by anyone
+
==Current issues==
 +
# Current version for Maemo is not the latest available ''(although the difference is minor)''.
 +
# When you edit fcrontab it wants to execute vi from /scratchbox ''(editor variable has to be defined manually each time fcrontab is run)''.
 +
# Some stuff has to be done manually after the installation ''(with proper packaging the whole "Installation" chapter from this wiki would be unnecessary)''.
 +
# It needs to be added to official maemo.org repositories so it can be used by anyone ''(it is currently availible in user ruskie's repository)''.
-
But these are not major things and it can be used already, it's 100% stable, just needs some manual work.
+
But these are not major things and as you can see it can be used already - current solutions and workarounds are in ''(brackets)''. Otherwise it's stable, does not have important bugs and does not affect battery life at all. It's a mature software which just needs some manual work.
-
 
+
==Installation==
-
=Installation=
+
Everything should be done from [[root access|root terminal]]. First you need to download the .deb from [https://repo.codemages.net/opt/fcron_3.0.1-2_armel_opt.deb ruskie's repository]. Put it somewhere on the device and execute the following commands, one by one:
Everything should be done from [[root access|root terminal]]. First you need to download the .deb from [https://repo.codemages.net/opt/fcron_3.0.1-2_armel_opt.deb ruskie's repository]. Put it somewhere on the device and execute the following commands, one by one:
  dpkg -i /path/to/deb/fcron_3.0.1-2_armel_opt.deb
  dpkg -i /path/to/deb/fcron_3.0.1-2_armel_opt.deb
-
  apt-get install adduser
+
  useradd fcron
-
adduser fcron
+
-
rm -r /home/fcron
+
  chown root:fcron /etc/fcron.*
  chown root:fcron /etc/fcron.*
  chmod 644 /etc/fcron.*
  chmod 644 /etc/fcron.*
  chown -R fcron:fcron /var/spool/fcron
  chown -R fcron:fcron /var/spool/fcron
-
  vi /etc/event.d/rcS-late
+
  /etc/init.d/fcron start
-
Last command opens rcS-late in vi text editor. You can use other text editor if you wish. After the line 38, which contains "initctl emit MOUNTS_OK" insert in a new line:
+
Now fcron has to be set to start on boot. This is done by creating a proper [[startup script]]. If you don't already have a custom one, then you need to create an empty file in /etc/event.d/ folder named as you like ("fcron" for example). Put this into the file:
 +
start on started hildon-desktop
 +
stop on starting shutdown
 +
console none
 +
service
 +
script
  /etc/init.d/fcron start
  /etc/init.d/fcron start
 +
end script
-
Then save this file. Back in terminal execute the same line:
+
And save it. This makes fcron run at startup.
-
/etc/init.d/fcron start
+
==Configuration==
 +
 
 +
fcrontab is a program which parses config file so fcron daemon can use it. It is used to modify schedule. First edit fcron's global configuration file, which is located at /etc/fcron.conf. The last configuration entry (line) must be changed to:
-
=Configuration=
+
editor = /usr/bin/vi
-
Fcrontab is a program which parses config file so fcron daemon can use it. It is used to modify schedule. From the root terminal first define the editor. This has to be done every time fcrontab is used.
+
This will use vi as fcrontab editor. You can use another editor. If this doesn't work, you can manually define editor every time before fcrontab is run. The command is run from the root terminal:
  export EDITOR=vi
  export EDITOR=vi
-
Again, you can use another editor. Next, fcrontab must be executed in edit mode:
+
Next, fcrontab must be executed in edit mode:
  fcrontab -e
  fcrontab -e
Line 63: Line 73:
   
   
  # COMMENT
  # COMMENT
-
  00 9 * * 1-5 run-standalone.sh /path/to/script/silent_profile.sh
+
  0 9 * * 1-5 run-standalone.sh /path/to/script/silent_profile.sh
  <more scheduled scripts>
  <more scheduled scripts>
   
   
Line 71: Line 81:
''!nolog(true)'' is the first line and specifies that successful executions aren't logged (we really don't need or want that). Also, if we use a script with dbus call, ''run-standalone.sh'' must be in front of it. It sets up environment variables correctly for sending dbus calls as root. ''!bootrun(true)'' specifies that commands after this line are executed at next boot if system wasn't on when they should be executed. This is useful only for clearing the GPRS counter or backup scripts, for example if you switch the phone off every night the GPRS counter will still be reset every first of the month when you turn the phone on in the morning.
''!nolog(true)'' is the first line and specifies that successful executions aren't logged (we really don't need or want that). Also, if we use a script with dbus call, ''run-standalone.sh'' must be in front of it. It sets up environment variables correctly for sending dbus calls as root. ''!bootrun(true)'' specifies that commands after this line are executed at next boot if system wasn't on when they should be executed. This is useful only for clearing the GPRS counter or backup scripts, for example if you switch the phone off every night the GPRS counter will still be reset every first of the month when you turn the phone on in the morning.
-
 
The first five fields are separated by a space:
The first five fields are separated by a space:
 +
'''MINUTE''' space '''HOUR''' space '''DAY_OF_MONTH''' space '''MONTH''' space '''DAY_OF_WEEK''' space '''/path/script.sh'''
-
['''minute'''][SPACE]['''hour'''][SPACE]['''day_of_month'''][SPACE]['''month'''][SPACE]['''day_of_week'''][SPACE]'''/path/script.sh'''
+
To interpret the two example lines: GPRS data counter is reset every 1st of the month at 00:00. Silent profile is set every Monday to Friday at 9:00. Possible values for fields are:
 +
* '''Minute''': 0-59
 +
* '''Hour''': 0-23
 +
* '''Day of month''': 1-31
 +
* '''Month''': 1-12
 +
* '''Day of week''': 0-7 (0 and 7 are both Sunday)
-
To interpret the two example lines: GPRS data counter is reset every 1st of the month at 00:00. Silent profile is set every Monday to Friday at 9:00. Possible values for fields are:
+
Asterisk (*) means "any", or to put it differently: it means that this value does not define when the command is run.
 +
After saving the edited config file, fcrontab will install it automatically and it will work from that moment on. Also don't forget that commenting out lines is useful for temporarily disabling a command. Just put an # in front of the line.
-
minute: 0-59
+
==Scripts==
-
hour: 0-23
+
So we have fcron now executing scripts at defined time. But we still need to provide scripts that are executed. Here is a collection of them, but you can easily make new ones based on the example scripts here and [[Phone control]] wiki page. Don't forget to add them here though. And keep in mind that they have to be marked executable (<code>chmod +x script.sh</code>) to work. The second D-Bus call in some scripts is a notification and can be modified, removed or added.
-
day of month: 1-31
+
===Profiles===
-
month: 1-12
+
====Silent====
-
day of week: 0-7 (0 and 7 are both Sunday)
+
<source lang="bash">
 +
#!/bin/sh
 +
dbus-send --type=method_call --dest=com.nokia.profiled /com/nokia/profiled com.nokia.profiled.set_profile string:"silent"
 +
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Profile is set to Silent"
 +
</source>
 +
====General====
-
Asterisk (*) means "any", or to put it differently: it means that this value does not define when the command is run.
+
<source lang="bash">
 +
#!/bin/sh
 +
dbus-send --type=method_call --dest=com.nokia.profiled /com/nokia/profiled com.nokia.profiled.set_profile string:"general"
 +
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Profile is set to General"
 +
</source>
 +
===Radio mode===
-
After saving the edited config file, fcrontab will install it automatically and it will work from that moment on. Also don't forget that commenting out lines is useful for temporarily disabling a command. Just put an # in front of the line.
+
====2G====
-
=Scripts=
+
<source lang="bash">
 +
#!/bin/sh
 +
dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:1
 +
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Network mode is set to 2G"
 +
</source>
-
So we have fcron now executing scripts at defined time. But we still need to provide scripts that are executed. Here is a collection of them, but you can easily make new ones based on the example scripts here and [[Phone control]] wiki page. Don't forget to add them here though. And keep in mind that they have to be marked executable (chmod +x script.sh) to work. The second dbus call in some scripts is a notification and can me modified, removed or added.
+
====3G====
-
===Silent profile===
+
<source lang="bash">
 +
#!/bin/sh
 +
dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:2
 +
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Network mode is set to 3G"
 +
</source>
-
#!/bin/sh
+
====Dual====
-
dbus-send --type=method_call --dest=com.nokia.profiled /com/nokia/profiled com.nokia.profiled.set_profile string:"silent"
+
-
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Profile is set to Silent"
+
-
===General profile===
+
<source lang="bash">
 +
#!/bin/sh
 +
dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:0
 +
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Network mode is set to Dual"
 +
</source>
-
#!/bin/sh
+
===Networking===
-
dbus-send --type=method_call --dest=com.nokia.profiled /com/nokia/profiled com.nokia.profiled.set_profile string:"general"
+
-
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Profile is set to General"
+
-
===Set radio mode to 2G===
+
====Disconnect internet connection====
-
#!/bin/sh
+
<source lang="bash">
-
dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:1
+
#!/bin/sh
-
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Network mode is set to 2G"
+
dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
 +
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Internet connection is disconnected"
 +
</source>
-
===Set radio mode to 3G===
+
====Connect to any saved internet connection====
-
#!/bin/sh
+
<source lang="bash">
-
dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:2
+
#!/bin/sh
-
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Network mode is set to 3G"
+
dbus-send --system --type=method_call --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:"[ANY]" uint32:0
 +
</source>
-
===Set radio mode to Dual===
+
====Disconnect mobile network====
-
#!/bin/sh
+
<source lang="bash">
-
dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:0
+
#!/bin/sh
-
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Network mode is set to Dual"
+
dbus-send --system --type=method_call --dest=com.nokia.phone.SSC /com/nokia/phone/SSC com.nokia.phone.SSC.set_radio boolean:false
 +
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Mobile network is disconnected"
 +
</source>
-
===Disconnect internet connection===
+
====Connect mobile network====
-
#!/bin/sh
+
<source lang="bash">
-
dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
+
#!/bin/sh
-
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Internet connection is disconnected"
+
dbus-send --system --type=method_call --dest=com.nokia.phone.SSC /com/nokia/phone/SSC com.nokia.phone.SSC.set_radio boolean:true
 +
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Mobile network is connected"
 +
</source>
-
===Disconnect mobile network===
+
====Disable Wi-Fi====
-
#!/bin/sh
+
<source lang="bash">
-
dbus-send --system --type=method_call --dest=com.nokia.phone.SSC /com/nokia/phone/SSC com.nokia.phone.SSC.set_radio boolean:false
+
#!/bin/sh
-
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Mobile network is disconnected"
+
run-standalone.sh dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
 +
ifconfig wlan0 down
 +
rmmod wl12xx
 +
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Wi-Fi disabled'
 +
</source>
-
===Connect mobile network===
+
====Enable Wi-Fi====
-
#!/bin/sh
+
<source lang="bash">
-
dbus-send --system --type=method_call --dest=com.nokia.phone.SSC /com/nokia/phone/SSC com.nokia.phone.SSC.set_radio boolean:true
+
#!/bin/sh
-
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Mobile network is connected"
+
modprobe wl12xx
 +
wl1251-cal
 +
stop wlancond
 +
start wlancond
 +
ifconfig wlan0 up
 +
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Wi-Fi enabled'
 +
</source>
 +
 
 +
===Securing device===
 +
 
 +
====Lock====
 +
 
 +
<source lang="bash">
 +
#!/bin/sh
 +
dbus-send --system --type=method_call --dest=com.nokia.system_ui /com/nokia/system_ui/request com.nokia.system_ui.request.devlock_open string:"com.nokia.mce" string:"/com/nokia/mce/request" string:"com.nokia.mce.request" string:"devlock_callback" uint32:'3'
 +
</source>
 +
 
 +
====Unlock====
 +
 
 +
<source lang="bash">
 +
#!/bin/sh
 +
dbus-send --system --type=method_call --dest=com.nokia.system_ui /com/nokia/system_ui/request com.nokia.system_ui.request.devlock_close string:"com.nokia.mce" string:"/com/nokia/mce/request" string:"com.nokia.mce.request" string:"devlock_callback" uint32:'0'
 +
</source>
===Reset GPRS data counter===
===Reset GPRS data counter===
-
#!/bin/sh
+
This script is now PR1.2 compliant and does not work on previous versions.
-
gconftool-2 -u /system/osso/connectivity/network_type/GPRS/gprs_rx_bytes
+
 
-
gconftool-2 -u /system/osso/connectivity/network_type/GPRS/gprs_tx_bytes
+
<source lang="bash">
-
gconftool-2 -s /system/osso/connectivity/network_type/GPRS/gprs_reset_time --type=string $(date +%s)
+
#!/bin/sh
 +
gconftool-2 -u /system/osso/connectivity/network_type/GPRS/gprs_home_rx_bytes
 +
gconftool-2 -u /system/osso/connectivity/network_type/GPRS/gprs_home_tx_bytes
 +
gconftool-2 -s /system/osso/connectivity/network_type/GPRS/gprs_home_reset_time --type=string $(date +%s)
 +
</source>
 +
 
 +
===Update e-mail===
 +
 
 +
This script has already necessary <code>run-standalone.sh</code> prefixes so the whole script does not need to be run through <code>run-standalone.sh</code> in fcrontab.
 +
 
 +
It checks whether the phone is connected to the internet and if it is not, connect is done, send and receive is performed and then script waits about minute and a half (Modest e-mail client which N900 uses is slow in this aspect) and if the phone is connected to a Wi-Fi, it stays connected and if it is not (is connected to GPRS), it disconnects.
 +
 
 +
<source lang="bash">
 +
#!/bin/sh
 +
#
 +
# n900 / maemo script to trigger an email fetch; connect to the internet if possible & necessary
 +
#
 +
# Copyright: 2011 Martin Dengler <martin@martindengler.com>
 +
# Dual License: MIT / GPL v3+
 +
# Latest version: http://wiki.maemo.org/Fcron#Update_e-mail
 +
 
 +
retrys=5
 +
 
 +
while [ $retrys -gt 0 ] ; do
 +
    if /sbin/route | grep -q "^default " ; then
 +
        break  #...we are connected
 +
    else
 +
        run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.icd --print-reply /com/nokia/icd com.nokia.icd.connect string:"[ANY]" uint32:0
 +
        retrys=`expr $retrys - 1`
 +
        sleep 1
 +
    fi
 +
done
 +
 
 +
/sbin/route | grep -q "^default " || exit 1
 +
 
 +
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Updating e-mail..."
 +
run-standalone.sh dbus-send --type=method_call --dest=com.nokia.modest /com/nokia/modest com.nokia.modest.SendReceive
 +
 
 +
sleep 120
-
===Lock phone===
+
# if we connected just for this, disconnect
 +
if [ $retrys -lt 5 ]; then
 +
  run-standalone.sh dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
 +
fi
-
#!/bin/sh
+
# no need to send another notification because we can't be sure the email updated anyway, and if you're still staring at the screen after two minutes waiting for a five-second notification to appear you need something better to do
-
dbus-send --system --type=method_call --dest=com.nokia.system_ui /com/nokia/system_ui/request com.nokia.system_ui.request.devlock_open string:"com.nokia.mce" string:"/com/nokia/mce/request" string:"com.nokia.mce.request" string:"devlock_callback" uint32:'3'
+
</source>
-
===Unlock phone===
+
===Backup===
-
#!/bin/sh
+
The scripts used for backing up can be found on [[Manual backup and restore]] wiki page. They overlap with scripts needed here, so they should be collected there.
-
dbus-send --system --type=method_call --dest=com.nokia.system_ui /com/nokia/system_ui/request com.nokia.system_ui.request.devlock_close string:"com.nokia.mce" string:"/com/nokia/mce/request" string:"com.nokia.mce.request" string:"devlock_callback" uint32:'0'
+
===Reboot===
===Reboot===
-
#!/bin/sh
+
Just put it directly in fcrontab:
-
rootsh reboot
+
-
===Auto 2G with WiFi===
+
0 0 * * * reboot
-
#!/bin/sh
+
Warning 1: Never put it after ''!bootrun(true)'' line in fcrontab! It could result in an endless reboot loop.
-
#
+
 
-
# auto2g by J.LeFebvre
+
Warning 2: Think twice before making a wrong time entry in fcrontab! The example here should suffice for most (it reboots device every midnight). Change the two zeroes in other numbers if you want, but don't put asterisks or ranges in those two fields!
-
#
+
 
-
# Automatically sets 2G cellular mode when a valid WiFi connection is running
+
Also remember that PIN has to be entered after a reboot. There is another way with sending reboot call via D-Bus which doesn't request to reenter PIN, but that is a forced reboot (no filesystem synchronization, etc.) and thus not the proper way of doing it.
-
# This helps conserve battery life
+
-
#
+
-
# If an automatic connection to 3G is required when not on WiFi then uncomment the two dbus commands under "set to 3G" line
+
-
#
+
-
if `/sbin/ifconfig wlan0 2>/dev/null | grep -q RUNNING`; then
+
-
    if `dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_selected_radio_access_technology | grep -q 'byte 2'`; then
+
-
      if (/bin/ping -c 1 www.google.com > /dev/null); then
+
-
          # set to 2G
+
-
          dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:1
+
-
          dbus-send --system --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'2G (GSM) cellular mode set'
+
-
      fi
+
-
    fi;
+
-
else
+
-
    if `dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_selected_radio_access_technology | grep -q 'byte 1'`; then
+
-
      # set to 3G
+
-
      # dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:2
+
-
      # dbus-send --system --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'3G cellular mode set'
+
-
      echo '' > /dev/null
+
-
    fi
+
-
fi
+
===Tweakr profiles===
===Tweakr profiles===
Line 204: Line 290:
This script is not tested yet. Also you must replace both "tweakrprofile" instances with the name of your profile (which should not be general or silent and should not be capitalized).
This script is not tested yet. Also you must replace both "tweakrprofile" instances with the name of your profile (which should not be general or silent and should not be capitalized).
-
#!/bin/sh
+
<source lang="bash">
-
+
#!/bin/sh
-
DBUSSET="dbus-send --print-reply --dest='com.nokia.profiled' /com/nokia/profiled com.nokia.profiled.set_value string:general string:\'%s\' string:\'%s\'"
+
-
+
-
dbus-send --type=method_call --dest=com.nokia.profiled /com/nokia/profiled com.nokia.profiled.set_profile string:"general"
+
-
+
-
gconftool-2 -s /system/tweakr/current-preset --type=string "tweakrprofile"
+
-
gconftool-2 -a /system/tweakr/tweakrprofile|sed 's/^ //'|sed 's/ = /=/'|awk -F'=' "{cmd=sprintf(\"${DBUSSET}\", \$1, \$2);system(cmd)}"
+
-
===Update e-mail===
+
DBUSSET="dbus-send --print-reply --dest='com.nokia.profiled' /com/nokia/profiled com.nokia.profiled.set_value string:general string:\'%s\' string:\'%s\'"
 +
 
 +
dbus-send --type=method_call --dest=com.nokia.profiled /com/nokia/profiled com.nokia.profiled.set_profile string:"general"
 +
 
 +
gconftool-2 -s /system/tweakr/current-preset --type=string "tweakrprofile"
 +
gconftool-2 -a /system/tweakr/tweakrprofile|sed 's/^ //'|sed 's/ = /=/'|awk -F'=' "{cmd=sprintf(\"${DBUSSET}\", \$1, \$2);system(cmd)}"
 +
</source>
 +
 
 +
===Auto 2G with Wi-Fi===
 +
 
 +
<source lang="bash">
 +
#!/bin/sh
 +
#
 +
# auto2g by J.LeFebvre
 +
#
 +
# Automatically sets 2G cellular mode when a valid Wi-Fi connection is running
 +
# This helps conserve battery life
 +
#
 +
# If an automatic connection to 3G is required when not on Wi-Fi then uncomment the two dbus commands under "set to 3G" line
 +
#
 +
if `/sbin/ifconfig wlan0 2>/dev/null | grep -q RUNNING`; then
 +
  if `dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_selected_radio_access_technology | grep -q 'byte 2'`; then
 +
      if (/bin/ping -c 1 www.google.com > /dev/null); then
 +
        # set to 2G
 +
        dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:1
 +
        dbus-send --system --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'2G (GSM) cellular mode set'
 +
      fi
 +
  fi;
 +
else
 +
  if `dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_selected_radio_access_technology | grep -q 'byte 1'`; then
 +
      # set to 3G
 +
      # dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:2
 +
      # dbus-send --system --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'3G cellular mode set'
 +
      echo '' > /dev/null
 +
  fi
 +
fi
 +
</source>
 +
 
 +
Comment: actually 3G doesn't use more energy than 2G, unless you transmit or receive data. So if your carrier doesn't expose your IP to the internet (no NAT) you won't safe any energy by switching to 2G during device connected to WLAN.
-
This script has already necessary run-standalone.sh prefixes so the whole script does not need to be run through run-standalone.sh in fcrontab. But you need to insert proper IAP_ID in the script.
+
===Gradually increase the volume===
-
What it does is that it checks whether the phone is connected to the internet and if it is, send and receive is performed and if it is not, the defined connection (IAP_ID) is used to connect, then send and receive is performed and script waits about minute and a half (Modest e-mail client which N900 uses is slow in this aspect) and then disconnects internet.  
+
For an example, you can use this if you softly want to wake up to music.
-
#!/bin/sh
+
<source lang="bash">
-
get=`route | awk '/au/ {print $1}'`
+
#!/bin/sh
-
if [ `echo $get` = default ]; then
+
# Gradually increase the volume, by raffe
-
run-standalone.sh dbus-send --type=method_call --dest=com.nokia.modest /com/nokia/modest com.nokia.modest.SendReceive
+
for i in 0 10 20 30 40 50 60 70 80 90 100
-
else
+
do
-
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Updating e-mail"
+
  dbus-send --session --type=method_call --dest=com.nokia.mafw.renderer.Mafw-Gst-Renderer-Plugin.gstrenderer /com/nokia/mafw/renderer/gstrenderer com.nokia.mafw.extension.set_extension_property string:'volume' variant:uint32:$i
-
run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:"IAP_ID" uint32:0
+
  /bin/sleep 5
-
sleep 10
+
done
-
run-standalone.sh dbus-send --type=method_call --dest=com.nokia.modest /com/nokia/modest com.nokia.modest.SendReceive
+
</source>
-
sleep 90
+
Note:tested and OK on PR1.2
-
run-standalone.sh dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
+
-
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"E-mail updated"
+
-
fi
+
[[Category:Software]]
[[Category:Software]]
[[Category:Power users]]
[[Category:Power users]]

Latest revision as of 21:58, 25 November 2013

fcron is standard Linux scheduler used to schedule any command at any time. So this means that it doesn't have any limits and you can schedule just about anything. It is run as daemon in the background so you don't need to worry about it. You set it up with a config file which contains schedule.

Contents

[edit] Alternatives

cron

Why not: cron is older than fcron and doesn't sleep between events.


anacron

Why not: anacron is used to schedule daily jobs, fcron can schedule to minutes.


ses

Why not: ses is buggy, buggy and buggy. It doesn't even uninstall properly.


Alarmed

Alarmed uses the Nokia's (non-standard) "alarmd" daemon which is already part of Maemo 5 and uses Python/Qt for GUI. You can use custom commands and set single and/or recurring events.

[edit] Current issues

  1. Current version for Maemo is not the latest available (although the difference is minor).
  2. When you edit fcrontab it wants to execute vi from /scratchbox (editor variable has to be defined manually each time fcrontab is run).
  3. Some stuff has to be done manually after the installation (with proper packaging the whole "Installation" chapter from this wiki would be unnecessary).
  4. It needs to be added to official maemo.org repositories so it can be used by anyone (it is currently availible in user ruskie's repository).

But these are not major things and as you can see it can be used already - current solutions and workarounds are in (brackets). Otherwise it's stable, does not have important bugs and does not affect battery life at all. It's a mature software which just needs some manual work.

[edit] Installation

Everything should be done from root terminal. First you need to download the .deb from ruskie's repository. Put it somewhere on the device and execute the following commands, one by one:

dpkg -i /path/to/deb/fcron_3.0.1-2_armel_opt.deb
useradd fcron
chown root:fcron /etc/fcron.*
chmod 644 /etc/fcron.*
chown -R fcron:fcron /var/spool/fcron
/etc/init.d/fcron start

Now fcron has to be set to start on boot. This is done by creating a proper startup script. If you don't already have a custom one, then you need to create an empty file in /etc/event.d/ folder named as you like ("fcron" for example). Put this into the file:

start on started hildon-desktop
stop on starting shutdown
console none
service
script
/etc/init.d/fcron start
end script

And save it. This makes fcron run at startup.

[edit] Configuration

fcrontab is a program which parses config file so fcron daemon can use it. It is used to modify schedule. First edit fcron's global configuration file, which is located at /etc/fcron.conf. The last configuration entry (line) must be changed to:

editor = /usr/bin/vi

This will use vi as fcrontab editor. You can use another editor. If this doesn't work, you can manually define editor every time before fcrontab is run. The command is run from the root terminal:

export EDITOR=vi

Next, fcrontab must be executed in edit mode:

fcrontab -e

The config file opens and it is empty first time we open it. Now we will enter commands we would like to schedule. An example config file looks like:

!nolog(true)

# COMMENT
0 9 * * 1-5 run-standalone.sh /path/to/script/silent_profile.sh
<more scheduled scripts>

!bootrun(true)
0 0 1 * * /path/to/script/reset_gprs_data_counter.sh
<a backup script also suits here if you have one>

!nolog(true) is the first line and specifies that successful executions aren't logged (we really don't need or want that). Also, if we use a script with dbus call, run-standalone.sh must be in front of it. It sets up environment variables correctly for sending dbus calls as root. !bootrun(true) specifies that commands after this line are executed at next boot if system wasn't on when they should be executed. This is useful only for clearing the GPRS counter or backup scripts, for example if you switch the phone off every night the GPRS counter will still be reset every first of the month when you turn the phone on in the morning.

The first five fields are separated by a space:

MINUTE space HOUR space DAY_OF_MONTH space MONTH space DAY_OF_WEEK space /path/script.sh

To interpret the two example lines: GPRS data counter is reset every 1st of the month at 00:00. Silent profile is set every Monday to Friday at 9:00. Possible values for fields are:

  • Minute: 0-59
  • Hour: 0-23
  • Day of month: 1-31
  • Month: 1-12
  • Day of week: 0-7 (0 and 7 are both Sunday)

Asterisk (*) means "any", or to put it differently: it means that this value does not define when the command is run.

After saving the edited config file, fcrontab will install it automatically and it will work from that moment on. Also don't forget that commenting out lines is useful for temporarily disabling a command. Just put an # in front of the line.

[edit] Scripts

So we have fcron now executing scripts at defined time. But we still need to provide scripts that are executed. Here is a collection of them, but you can easily make new ones based on the example scripts here and Phone control wiki page. Don't forget to add them here though. And keep in mind that they have to be marked executable (chmod +x script.sh) to work. The second D-Bus call in some scripts is a notification and can be modified, removed or added.

[edit] Profiles

[edit] Silent

#!/bin/sh
dbus-send --type=method_call --dest=com.nokia.profiled /com/nokia/profiled com.nokia.profiled.set_profile string:"silent"
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Profile is set to Silent"

[edit] General

#!/bin/sh
dbus-send --type=method_call --dest=com.nokia.profiled /com/nokia/profiled com.nokia.profiled.set_profile string:"general"
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Profile is set to General"

[edit] Radio mode

[edit] 2G

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:1
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Network mode is set to 2G"

[edit] 3G

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:2
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Network mode is set to 3G"

[edit] Dual

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:0
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Network mode is set to Dual"

[edit] Networking

[edit] Disconnect internet connection

#!/bin/sh
dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Internet connection is disconnected"

[edit] Connect to any saved internet connection

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:"[ANY]" uint32:0

[edit] Disconnect mobile network

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.phone.SSC /com/nokia/phone/SSC com.nokia.phone.SSC.set_radio boolean:false
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Mobile network is disconnected"

[edit] Connect mobile network

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.phone.SSC /com/nokia/phone/SSC com.nokia.phone.SSC.set_radio boolean:true
dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Mobile network is connected"

[edit] Disable Wi-Fi

#!/bin/sh
run-standalone.sh dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
ifconfig wlan0 down
rmmod wl12xx
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Wi-Fi disabled'

[edit] Enable Wi-Fi

#!/bin/sh
modprobe wl12xx
wl1251-cal
stop wlancond
start wlancond
ifconfig wlan0 up
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'Wi-Fi enabled'

[edit] Securing device

[edit] Lock

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.system_ui /com/nokia/system_ui/request com.nokia.system_ui.request.devlock_open string:"com.nokia.mce" string:"/com/nokia/mce/request" string:"com.nokia.mce.request" string:"devlock_callback" uint32:'3'

[edit] Unlock

#!/bin/sh
dbus-send --system --type=method_call --dest=com.nokia.system_ui /com/nokia/system_ui/request com.nokia.system_ui.request.devlock_close string:"com.nokia.mce" string:"/com/nokia/mce/request" string:"com.nokia.mce.request" string:"devlock_callback" uint32:'0'

[edit] Reset GPRS data counter

This script is now PR1.2 compliant and does not work on previous versions.

#!/bin/sh
gconftool-2 -u /system/osso/connectivity/network_type/GPRS/gprs_home_rx_bytes
gconftool-2 -u /system/osso/connectivity/network_type/GPRS/gprs_home_tx_bytes
gconftool-2 -s /system/osso/connectivity/network_type/GPRS/gprs_home_reset_time --type=string $(date +%s)

[edit] Update e-mail

This script has already necessary run-standalone.sh prefixes so the whole script does not need to be run through run-standalone.sh in fcrontab.

It checks whether the phone is connected to the internet and if it is not, connect is done, send and receive is performed and then script waits about minute and a half (Modest e-mail client which N900 uses is slow in this aspect) and if the phone is connected to a Wi-Fi, it stays connected and if it is not (is connected to GPRS), it disconnects.

#!/bin/sh
#
# n900 / maemo script to trigger an email fetch; connect to the internet if possible & necessary
#
# Copyright: 2011 Martin Dengler <martin@martindengler.com>
# Dual License: MIT / GPL v3+
# Latest version: http://wiki.maemo.org/Fcron#Update_e-mail
 
retrys=5
 
while [ $retrys -gt 0 ] ; do
    if /sbin/route | grep -q "^default " ; then
        break  #...we are connected
    else
        run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.icd --print-reply /com/nokia/icd com.nokia.icd.connect string:"[ANY]" uint32:0
        retrys=`expr $retrys - 1`
        sleep 1
    fi
done
 
/sbin/route | grep -q "^default " || exit 1
 
run-standalone.sh dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"Updating e-mail..."
run-standalone.sh dbus-send --type=method_call --dest=com.nokia.modest /com/nokia/modest com.nokia.modest.SendReceive
 
sleep 120
 
# if we connected just for this, disconnect
if [ $retrys -lt 5 ]; then
  run-standalone.sh dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
fi
 
# no need to send another notification because we can't be sure the email updated anyway, and if you're still staring at the screen after two minutes waiting for a five-second notification to appear you need something better to do

[edit] Backup

The scripts used for backing up can be found on Manual backup and restore wiki page. They overlap with scripts needed here, so they should be collected there.

[edit] Reboot

Just put it directly in fcrontab:

0 0 * * * reboot

Warning 1: Never put it after !bootrun(true) line in fcrontab! It could result in an endless reboot loop.

Warning 2: Think twice before making a wrong time entry in fcrontab! The example here should suffice for most (it reboots device every midnight). Change the two zeroes in other numbers if you want, but don't put asterisks or ranges in those two fields!

Also remember that PIN has to be entered after a reboot. There is another way with sending reboot call via D-Bus which doesn't request to reenter PIN, but that is a forced reboot (no filesystem synchronization, etc.) and thus not the proper way of doing it.

[edit] Tweakr profiles

This script is not tested yet. Also you must replace both "tweakrprofile" instances with the name of your profile (which should not be general or silent and should not be capitalized).

#!/bin/sh
 
DBUSSET="dbus-send --print-reply --dest='com.nokia.profiled' /com/nokia/profiled com.nokia.profiled.set_value string:general string:\'%s\' string:\'%s\'"
 
dbus-send --type=method_call --dest=com.nokia.profiled /com/nokia/profiled com.nokia.profiled.set_profile string:"general"
 
gconftool-2 -s /system/tweakr/current-preset --type=string "tweakrprofile"
gconftool-2 -a /system/tweakr/tweakrprofile|sed 's/^ //'|sed 's/ = /=/'|awk -F'=' "{cmd=sprintf(\"${DBUSSET}\", \$1, \$2);system(cmd)}"

[edit] Auto 2G with Wi-Fi

#!/bin/sh
#
# auto2g by J.LeFebvre
#
# Automatically sets 2G cellular mode when a valid Wi-Fi connection is running
# This helps conserve battery life
#
# If an automatic connection to 3G is required when not on Wi-Fi then uncomment the two dbus commands under "set to 3G" line
#
if `/sbin/ifconfig wlan0 2>/dev/null | grep -q RUNNING`; then
   if `dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_selected_radio_access_technology | grep -q 'byte 2'`; then
      if (/bin/ping -c 1 www.google.com > /dev/null); then
         # set to 2G
         dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:1
         dbus-send --system --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'2G (GSM) cellular mode set'
      fi
   fi;
else
   if `dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_selected_radio_access_technology | grep -q 'byte 1'`; then
      # set to 3G
      # dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:2
      # dbus-send --system --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:'3G cellular mode set'
      echo '' > /dev/null
   fi
fi

Comment: actually 3G doesn't use more energy than 2G, unless you transmit or receive data. So if your carrier doesn't expose your IP to the internet (no NAT) you won't safe any energy by switching to 2G during device connected to WLAN.

[edit] Gradually increase the volume

For an example, you can use this if you softly want to wake up to music.

#!/bin/sh
# Gradually increase the volume, by raffe 
for i in 0 10 20 30 40 50 60 70 80 90 100
do
  dbus-send --session --type=method_call --dest=com.nokia.mafw.renderer.Mafw-Gst-Renderer-Plugin.gstrenderer /com/nokia/mafw/renderer/gstrenderer com.nokia.mafw.extension.set_extension_property string:'volume' variant:uint32:$i
  /bin/sleep 5
done

Note:tested and OK on PR1.2

Retrieved from "http://wiki.maemo.org/Fcron"