N900, Erminig and Google Calendar – the battle for the battery

The latest N900 update (PR1.2) is already history – some are happy (like me) others are completely devastated. I, like many others, decided to make full reset of the device, as was abusing it allot. This meant that the new firmware together with the latest eMMC contents was reflashed. After that I’ve started fresh to reconfigure my device, and following the KISS approach, I wanted to restore only the apps that I really use. Having that in mind there was one thing that really bugged me – MfE. It was used only to sync my Google Calendars through nyevasync and in order to be always in sync I had to enable autoconnect WiFi – that way the calendar was able to sync on the given interval of time. But staying always online drains the battery allot. Maybe this is the biggest power drain source together with the 3G connectivity. Clearly a solution that connects-syncs-disconnects would be greatly appreciated. Below you’ll find the way I did it.

The first thing I’ve needed was an alternative to MfE  – I don’t like the sync-only-one calendar with google and the fact that I have a Exchange Mail account that just sits in my Modest configuration. As always the maemo community helped and thanks, thanks, thanks to lorelei from maemo.org – I was able to use Erminig for that purpose. The application in the current stage is quite feature complete IMHO. It offers syncing in both directions for local calendars to/from Google calendars and supports *multiple* calendars. The other great thing about Erminig is that you can sync from command line 🙂 which opens the path to quite simple script implementing the connect-sync-disconnect philosophy. The script itself is quite simple. It respects the situations in which the WiFi was already active – it drops the connection only when it was initiated from the script itself:

/opt/mybin/synccal

#!/bin/sh
# Autor: Todor Tsankov (2010)
#
# 2010-05-28 - initial release

RETRIES=3
CONNECTED=false
DROPCONN=false

# check for existing wifi connectivity
if [ "$(/sbin/route | awk '/au/ {print $1}')" == "default" ]; then
	CONNECTED=true
else
  for i in $(seq 1 $RETRIES); do
    # try to connect to any known wifi
    run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:"[ANY]" uint32:0
    sleep 20
    if [ "$(/sbin/route | awk '/au/ {print $1}')" == "default" ]; then
      CONNECTED=true
      DROPCONN=true
      break
    fi
  done
fi

if [ "$CONNECTED" == "true" ]; then
  # sync erminig if having connectivity
  /usr/bin/erminig -a

  # sync MfE
  # run-standalone.sh dbus-send --print-reply --type=method_call --session --dest=com.nokia.asdbus /com/nokia/asdbus com.nokia.asdbus.fullSync

  sleep 5

  # drop the wifi connection if it was initiated by this script (saves battery)
  if [ "$DROPCONN" == "true" ]; then
    run-standalone.sh dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
  fi
fi

All that is left now is to save that script somewhere and invoke it in certain interval of time – how you’ll do it – it’s up to you. You can invoke it manually through X-terminal and tools like “Desktop Command Widget” or automate it with tools like Alarmed and fcron.

MfE comment: As you can see the MfE can be forced to sync from command line also, so if you prefer it, but still would like to minimize your wifi usage and optimize battery life – just comment erminig sync line and uncomment the MfE one.

Warning: the script is it’s infancy and although it makes some state checks it may misbehave.

Advertisements
Tagged , ,

3 thoughts on “N900, Erminig and Google Calendar – the battle for the battery

  1. Joonas says:

    Hello

    It is possible to modify the script to auto update calendars via Erminig every time when N900 connects on 3G network? Thank you for your help.

    • You don’t need to modify the script for this to work, but an app (like the ones that I’ve mentioned in the post) that runs the script not at predefined intervals of time, but instead runs it when 3G connection goes online. Unfortunately from the tip of my head I cannot recall any app that can do that.

      • REB says:

        Put the script in /etc/network/if-up.d
        It will run as soon as the network is connected

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: