#N900 mbarcode, python, SMS and sqlite3

As I worked on my blog post about QR Codes, I confirmed something I had been concerned about with mbarcode; it doesn’t send SMS messages. In the discussion about mbarcode, the author writes about his desire to “Add support for further 2D barcode payloads - please suggest any you think it doesn't handle, code appreciated too”. I added a suggestion for supporting sending SMS messages, and started looking for how to add this.

One of the first things I discovered was Kurt Fleisch’s logarchive.py. One of the things that is great about working on the N900 is that you can find good python code that you can read through, copy to a file on your N900, execute it, and then start modifying it. Yet even before I started playing with the script, I noticed something very interesting. The script is reading from an SQLite3 database called “/home/user/.rtcom-eventlogger/el.db”

Firing up SQLite3 on my N900, I went into the database and started looking around. It was a listing of communications events. Every SMS message that I had sent or received, and had not yet deleted, was in there. The same for every phone call placed, received, or missed. A quick look revealed eleven different tables. Most of which didn’t do much for me. However a few tables jumped out at me; Services, EventTypes and Events.

Services has three entries, Calls, Chat Messages and SMS. There are eight entries in the EventTypes table, Inbound calls, Outbound Calls, Missed Calls and Voicemail Messages for the Call service, Inbound Chat and Outbound Chat for the Chat message service, and Inbound SMS and Outbound SMS for SMS services.

The real data is in Events. As I write this, there are 214 events in my Events table. Using a simple SQL query, ‘select event_type_id, count(*) from Events group by event_type_id;’ I can find how many of each type of event there is. With further exploration, I can check various times of various phone calls and messages. There is a lot that can be done with this, especially in terms of building up interesting interconnectivity between a CRM and the N900.

Yet this didn’t get me any closer to being able to suggest code to enable the addition of SMS functionality to mbarcode. A little more searching led me to PyMaemoSMS. I copied this text and gave it a run and it seems to work pretty well. However, it seemed to fail when I used numbers with an odd number of digits. It seems like some patch had been added to append an F to numbers with an odd number of digits. I commented out that section and the SMS messages work nicely from Python. With working Python code for sending SMS messages, there are a lot of interesting things that can be done and this code could be used as a basis for adding SMS messages to mbarcode.

(Categories: )