Results 1 to 19 of 19

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.


Thread: Calendar Wireless Sync

  1. #1
    Default Calendar Wireless Sync
    After looking around the phone, it seems that a 3rd party implementation of SyncML for wireless sync of the Calendar and Contact database on the iPhone is perfectly feasible.

    Both the Calendar and the Contact Database are stored in sqlite databases, which are easily accessible and the SyncML standard is XML based. This would give iPhones the much needed "I need to sync wirelessly to my outlook/exchange calendar at work" feature.

    And since the python modules for both XML and sqlite are available for the iphone version, it could even be written in python, for entreprising hackers looking to build a prototype.

    Any takers?

  2. #2
    I started thinking about this for google calendar but just don't have the free time to dedicate to it. I would love this ability.

  3. #3
    I'm working on a Python implementation of an on-iPhone POP mail server that screen-scrapes OWA so the iPhone can see the inbox as a regular mail account without using 3rd party servers:

    http://www.hackint0sh.org/forum/showthread.php?t=3023

    There are a couple of other guys who are working on syncing calendars and contacts as you suggest using sqlite:

    http://www.hackint0sh.org/forum/show...light=calendar

    I was not aware of a working sqlite library for iPhone Python. Do you have a link? What I'm trying to figure out right now is how to get Twisted running on the iPhone so I can dump POP in favor of IMAP. That combined with the sql calendar sync would resolve my ONLY complaints about the iPhone, and I'm sure a lot of others too.

    Biggest problem with Python or any other daemon process is the impact on battery life, though. I have to turn my scripts on and off as needed...

  4. #4
    Quote Originally Posted by lh99 View Post
    I'm working on a Python implementation of an on-iPhone POP mail server that screen-scrapes OWA so the iPhone can see the inbox as a regular mail account without using 3rd party servers:

    http://www.hackint0sh.org/forum/showthread.php?t=3023

    There are a couple of other guys who are working on syncing calendars and contacts as you suggest using sqlite:

    http://www.hackint0sh.org/forum/show...light=calendar

    I was not aware of a working sqlite library for iPhone Python. Do you have a link? What I'm trying to figure out right now is how to get Twisted running on the iPhone so I can dump POP in favor of IMAP. That combined with the sql calendar sync would resolve my ONLY complaints about the iPhone, and I'm sure a lot of others too.

    Biggest problem with Python or any other daemon process is the impact on battery life, though. I have to turn my scripts on and off as needed...
    nice, finally someone tackles the ol OWA way of getting mail....make sure to put a note on the app for where to send donations when you are done

  5. #5
    Quote Originally Posted by lh99 View Post
    I was not aware of a working sqlite library for iPhone Python. Do you have a link? What I'm trying to figure out right now is how to get Twisted running on the iPhone so I can dump POP in favor of IMAP. That combined with the sql calendar sync would resolve my ONLY complaints about the iPhone, and I'm sure a lot of others too.

    Biggest problem with Python or any other daemon process is the impact on battery life, though. I have to turn my scripts on and off as needed...
    Actually the current version of python compiled for the iPhone already contains the sqlite3 library. As proof, the following code works, and prints the list of Calendars currently synced with your phone.
    Code:
    #!/usr/bin/python
    import sqlite3
    
    CALENDAR_DB = "/var/root/Library/Calendar/Calendar.sqlitedb"
    
    def main():
    	
    	conn = sqlite3.connect(CALENDAR_DB)
    	c = conn.cursor()
    	c.execute("SELECT * FROM Calendar")
    	for row in c:
    		print row
    	return
    	
    if __name__ == "__main__":
    	main()
    Also the script doesn't have to run in the background constantly. You can use launchctl to start it on regular intervals, like every half hour or so.

    oO

  6. #6
    I've been creating a service that offers some of the functionality. It's a SyncML to iCal gateway. It acts as a SyncML client with your SyncML server and offers the resulting events as an iCal feed. This way you can subscribe your iCal to the feed and sync it to your iPhone.

    It is still beta and i'm still improving the solution, but is works very well with a range of servers already.

    Try it out at:
    http://syncml2ical.com/

  7. #7
    I tried to access the Calendar DB using my PHP in apache and I get and error accessing DB, did you change the permissions of the folder or anything to allow ready and write. Please Help. Could the location be wrong because this php file is stored in Library/Web Server/Documents/Calendar.php Do I have to put a /../ or something before the address to get it to work. Thanks for any help in advance.

    <?php

    // set db
    $db = "/var/root/Library/Calendar/Calendar.sqlitedb";

    // open database file
    $conn = sqlite_open($db) or die ("ERROR: Cannot open database");

    //subjects
    $sql = "SELECT * FROM Calendar";
    $rs= sqlite_query($sql, $conn);
    $num = sqlite_num_rows($rs);
    while ($row = sqlite_fetch_array ($rs) )
    {
    echo "$row";
    echo "<br>";
    }

    // close database file
    sqlite_close($conn);
    ?>

  8. #8
    Quote Originally Posted by joejoe123 View Post
    I tried to access the Calendar DB using my PHP in apache and I get and error accessing DB, did you change the permissions of the folder or anything to allow ready and write. Please Help. Could the location be wrong because this php file is stored in Library/Web Server/Documents/Calendar.php Do I have to put a /../ or something before the address to get it to work. Thanks for any help in advance.
    Problems:
    1. Some file permissions exist which don't let you access the database.
    2. The way you are trying to access the sqlite database only supports up to version 2 while the Calendar.sqlitedb is version 3.

    Solutions:

    1. Change the permission of /var/root/Library/Calendar/ to 755
    2. Also I think that you are going to have to set the permissions of /var/root/Library/Calendar/Calendar.sqlitedb to 664 to allow PHP to get write access to the file.
    3. I got this code to work:


    PHP Code:
    <?php
    $dbh 
    = new PDO('sqlite:/var/root/Library/Calendar/Calendar.sqlitedb'); 
    foreach (
    $dbh->query('SELECT * FROM Calendar') as $row){
        
    print_r($row);
        print(
    "<br>");
    }
    ?>
    Also here is a list of tables contained in the Calendar.sqlitedb:
    • Calendar
    • sqlite_sequence
    • CalendarChanges
    • Event
    • EventChanges
    • EventExceptionDate
    • Task
    • TaskChanges
    • Alarm
    • AlarmChanges
    • Recurrence
    • RecurrenceChanges
    • OccurrenceCache
    • OccurrenceCacheDays
    Last edited by stockmopar; 2007-10-27 at 04:43 AM.

  9. #9
    Tasks are in the database? Then one has to ask why they are not implemented on the phone at this juncture.

    Quote Originally Posted by stockmopar View Post

    Also here is a list of tables contained in the Calendar.sqlitedb:
    • Calendar
    • sqlite_sequence
    • CalendarChanges
    • Event
    • EventChanges
    • EventExceptionDate
    • Task <<<<- What?
    • TaskChanges
    • Alarm
    • AlarmChanges
    • Recurrence
    • RecurrenceChanges
    • OccurrenceCache
    • OccurrenceCacheDays

  10. #10
    Default I found out the
    date conversions:

    it uses a mac version of Unix Epioche its based on 2001-01-01 at 00:00:00 not 1970-01-01 at 00:00:00 like normal

    the code below extracts the dates of events and converts then converts back to show you how to do it. I will be creating an awesome interface soon. I just need sometime. For you tech guys out there 978307200 is the number of secs between 1970 and 2001 in decimal. It works. have fun

    $dbh = new PDO('sqlite:/var/root/Library/Calendar/Calendar.sqlitedb');
    foreach ($dbh->query('SELECT start_date FROM Event') as $row){
    $start_date =$row["start_date"];
    print_r($start_date);
    print("<br>");
    $date = date("y-m-d", ($start_date + 978307200));
    echo "$date";
    echo "<br>";
    $day = date("d", ($start_date + 978307200));
    echo "$day";
    echo "<br>";
    $month = date("m", ($start_date + 978307200));
    echo "$month";
    echo "<br>";
    $year = date("y", ($start_date + 978307200));
    echo "$year";
    echo "<br>";
    $hour = date("H", ($start_date + 978307200));
    echo "$hour";
    echo "<br>";
    $minute = date("i", ($start_date + 978307200));
    echo "$minute";
    echo "<br>";
    $second = date("s", ($start_date + 978307200));
    echo "$second";
    echo "<br>";
    $unixdate = mktime($hour, $minute, $second, $month, $day, $year);
    $macunixdate = $unixdate - 978307200;
    echo "$macunixdate";
    echo "<br>";
    }

  11. #11
    Progress Report:

    Okay I am getting closer to getting this working!

    Currently here is what I have working:
    • Load iPod Calendar's Events Into Array
    • Send all calendar events to External PHP using cURL (Command Line)
    • Load Google Calendar's Events Into Array
    • Create Google Calendar Event From an iPod Calendar's Event
    • Create iPod Calendar Event


    What I don't have yet is:
    • Comparing Calendars to See What Has to Be Added Where
    • Recursive Events


    Note: That I currently haven't been able to access the Google Calendar API from the iPod. I have ran into many different problems including: cURL (Command Line) can't resolve anything google, PHP doesn't have cURL module, and PHP doesn't have openssl module. There may be a way to do this in Python, but I don't know too much in that area. So that is why I am using an External PHP script to do this.
    Last edited by stockmopar; 2007-11-03 at 08:41 AM. Reason: Updated Progress

  12. #12
    I may not be as far as stockmopar however i am getting a lot working and having some pit falls.

    my conversion for the date format is only correct on calendar entries with a time. All day events are some reason 5 hrs early. 2007-11-21 19:00:00 for a 2007-11-22 all day event. Give it a try let me know if i am making a mistake

    also here is my interface for the web app to search.
    almost working and allowing updating. Trying to get the date conversion thing. PLEASE HELP

    Last edited by joejoe123; 2007-11-03 at 02:10 AM.

  13. #13
    It looks like Apple handles all day events differently than regular events. Regular events are based on your timezone, but the all day events comes up as (_float)? So what I think this means is that it goes off of GMT time. I think that you could just do a check for the all_day tag and then add whatever your offset is to that. Here it is 5 hours. Good find, I will have to change my code accordingly too.

    Update

    I have successfully added an Event to the Calendar using PHP!!!

    $dbh = new PDO('sqlite:/var/root/Library/Calendar/Calendar.sqlitedb');

    $dbh->query("insert into Event (summary, location, description, start_date, start_tz, end_date, all_day, calendar_id, orig_event_id, orig_start_date) values ('Added From PHP', 'Location', 'Description', 216068400, 'America/Chicago', 216072000, 0, 1, 0, 0)");
    Last edited by stockmopar; 2007-11-03 at 08:37 AM. Reason: Automerged Doublepost

  14. #14
    awesome stockmopar, this is great back and forth analysis, I cant wait till both of our finish products to get this working even better. Thanks.

    so weird if u pull a dump

    INSERT INTO "_SqliteDatabaseProperties" VALUES('OccurrenceCacheTimeZone','Etc/GMT+4');

    its Etc/GMT+4 which would be prefect just do a right 2 string for it to work for everyone.

    but then i pulled a SELECT value FROM _SqliteDatabaseProperties where key = 'OccurrenceCacheTimeZone'

    and the response was US/Eastern for me. which sucks cause no easy way to use for everyone. Any ideas or am i thinking of this all wrong.

    My thoughts are if someone is using the phone and puts a search date of today, it first looks for today there time not GMT but to make GMT according to the phone you need someones timezone first. Am I wrong? Please help
    Last edited by joejoe123; 2007-11-03 at 08:37 PM.

  15. #15
    I am not sure if this is what you are looking for, but this seems to be working for me. I think that this takes into effect their timezone offset. For me it worked for all day events before and after the daylight savings time change. This is part of my code that I have used to acheive this:

    <?php

    $tz_offset = date('P', $event["start_date"]);
    $tz_sign = substr($tz_offset,0,1);
    $tz_ammount = substr(str_replace(":00","", $tz_offset),1);
    if(substr($tz_ammount,0,1) == "0") $tz_ammount = substr($tz_ammount,1);
    $tz_offset = $tz_sign . $tz_ammount;
    $tz_sec_offset = $tz_offset * 60 * 60;

    $event["start_timezone"] = $currEvent["start_tz"];

    if($currEvent["all_day"]) {
    $event["start_date"] -= $tz_sec_offset;
    print(date('g:i',$event["start_date"]));
    print(date('e',$event["start_date"]));
    }

    ?>

    This outputs the correct start time 12:00 and the date('e',$event["start_date"]) outputs the string like 'US/Eastern' or for me 'America/Chicago'.

  16. #16
    Any updates on this? I, and probably a million others, are very anxsiously awaiting a decision on this. Thanks

  17. #17
    I have a proto type I want to release but I would need some help. Using PDO I can only get it to do one update or insert command at a time. I want it to do multiples. I should release my code and work by tomorrow. I am by no means a pro or even and amateur at that point but I have to say it will not be horrible atleast. I will post tomorrow

    http://my.funambol.com/c/portal/layo..._id=PUB.1001.1

    here is a program funambol that looks promising, its on installer. Hasnt come out fully yet though but will






    HERE IT IS PLEASE HELP TEST!!!!!!!!!!!!!

    Sorry if my coding is poor, but I am not the best coder. I think I have most of this working from what I pictured; however, I would like your opinions and help.

    Known issues, if an event was an all day event turned to a none all day event I can't figure out how to add the time offset difference.

    Features to add, alerts, and a way to view reoccurence events. I am not sure how apple used the db for this. Can someone help.

    You can download the rar at:
    http://www.modmyi.com/forums/downloa...o=file&id=1402
    or
    http://www.geocities.com/plojm/Calen...Pv0.1alpha.zip

    open and put all files in your web documents folder, make sure you calendar folder and db has the right permissions see the thread page one.
    and run index.php.

    Thank for the help in advance
    Last edited by joejoe123; 2007-11-12 at 04:47 AM. Reason: Automerged Doublepost

  18. #18
    You can also use funambol to perform wireless sync of you calendar.

    Download http://syncml2ical.com/pmwiki.php?n=Main.SyncML2iPhone

    to you iphone and change the preferences to connect to the funambol portal.

    http://my.funambol.com/sync

    DB=./cal

  19. #19
    can this work with multiple google calendars?

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •