View Single Post
Posts: 188 | Thanked: 90 times | Joined on Sep 2006
#1
As you may have found, without allowing background data, apps like the calendar will not sync as per the schedule.

But, allowing background connections all the time will drain the battery (at least more than necessary)... Especially, since you may just want to sync at home in the morning, and would (like my wife) not think of turning of the background connection - leading to it trying to find a known connection all day.

So, I figured out how to schedule the sync - in my case it's just CalDAV (gmail calendar).

I use cron (from this meego thread: http://forum.meego.com/showthread.ph...highlight=cron and this site: https://gitorious.org/cron-for-harmattan/cron ) and gconftool-2 to get the N9 to switch to "background connections allowed" temporarily, then set the CalDAV in "Accounts" to sync within that window.

Here's the script, which I put in /home/user/bin/synccal.sh:
Code:
#!/bin/sh
cd /home/user/bin

INITIALLY=off

if [ `gconftool-2 -g /system/osso/connectivity/network_type/restricted_mode` == "false" ]
  then
    INITIALLY=already_on
  else
    gconftool-2 -t bool -s /system/osso/connectivity/network_type/restricted_mode false
    sleep 10
fi

#date >>  /home/user/bin/synccal.log

# sync caldav calendar
#dbus-send --session --print-reply --dest=com.meego.msyncd /synchronizer com.meego.msyncd.startSync string:'228076262'

whoami >> /home/user/bin/synccal.log
date >>  /home/user/bin/synccal.log

if [ $INITIALLY == "off" ]
  then
    sleep 300
    gconftool-2 -t bool -s /system/osso/connectivity/network_type/restricted_mode true
fi
At the start, if the background connection is not allowed, I put the sleep to 10 secs, which seems enough to make the connection to my wifi. Later I keep it for 300 secs, to have a good window to sync in.

And then as root, I setup cron:
Code:
/opt/cron/bin/crontab -e
10 6 * * * devel-su user -c 'sh /home/user/bin/synccal.sh'
Warning for the uninitiated! crontab -e requires you to input using vi commands... google: man vi
to get started on that one; all you need to know in terms of vi commands is
i
<esc>
:w
:wq
:q!

Note that with the above lines, the device will have an internet connection at 6:10am plus about 10 secs, until 6:15:10.
I setup CalDAV to sync at 6:11, and the past few mornings, that worked fine.

And now for the weird thing....
if you look at my script, you'll see some commented out stuff, dbus command to actually sync the caldav calendar, plus some other debugging/logging stuff.

The dbus sync command:
manually sync your calendar
check /home/user/.sync/profiles/sync/log to see which number got synced, then use that number in the dbus sync command.
Works fine, as user, if you have a network connection.
As root, use the command as in the crontab, on the command line.
Works fine too, whoami nicely indicates that the owner of the process is clearly 'user'.

BUT! As cron job, this doesn't work...
I can't figure out why not - it actually does log the date and whoami output to the log file... but doesn't run the dbus command...

Any hints?
 

The Following 3 Users Say Thank You to aRTee For This Useful Post: