Saturday, December 15, 2007

Cell Tracking with Python for Nokia Series 60

It's easy to assemble a quick application in python that tracks cell sites for you. I made a small app to do this and am using it on my Nokia E61. You need a Symbian Series 60 phone and Python interpreter installed on it.

To run it on your phone you need to do the following:



  • Download Python on to your phone.
    • References:
    • Download Python for Symbian from sourceforge. For Series 60 3rd edition download:
      • PythonForS60_1_4_1_3rdEd.SIS
      • PythonForS60_1_4_1_doc.pdf
      • PythonScriptShell_1_4_1_3rdEd_unsigned_freedevcert.SIS
  • You cannot get the location information in Symbian 3rd edition phones without a signed application and the Python Script Shell you just downloaded is not signed. There is no way to "turn off" Platform Security in a S60 3rd Edition device. As an individual you can get a developer certificate from Symbian to sign it yourself. The basic level developer certificate is free and getting it takes just a few minutes. More information on devcerts here
  • Getting a symbian devcert:
    • Download the DevCertRequest tool to generate a Certified Symbian Request (.csr) file. This tool guides you through five steps:
      • Name of application
      • File information
      • Personal information
      • Phone IMEI and capabilities information
      • Confirm Symbian Developer Request Details
    • Request a new DevCert by uploading the .csr file which generates a DevCert file ready for download.
  • Sign the file PythonScriptShell_1_4_1_3rdEd_unsigned_freedevcert.SIS using your devcert. Instructions on signing sis file is available here and here. Download signsis zip file here. Use the below command to sign:
    signsis PythonScriptShell_1_4_1_3rdEd_unsigned_freedevcert.SIS
    • PythonScriptShell_1_4_1_3rdEd_signed_devcert.SIS
    YourCert.cer YourCert.key 12345
  • Install PythonForS60_1_4_1_3rdEd.SIS and the signed python shell on to your phone.
  • Save the source code below on your PC and transfer it on to your phone via bluetooth

    # Simple app to display current cell info and signal strength.

    import e32
    import appuifw
    import location, sysinfo, time

    class my_cell_id:
    def __init__(self):
    self.text = u""

    def get_new_data(self):
    self.mcc, self.mnc, self.lac, self.cellid = location.gsm_location()
    self.bars = sysinfo.signal_bars()
    self.dbm = sysinfo.signal_dbm()
    self.sigpct = self.bars*100/7

    def lookup_mcc(self, mcc):
    if 404 == mcc or 405 == mcc:
    return u"India"
    else:
    return u"Unregistered Country"

    def get_display_text(self):
    self.text = u"Mobile Country Code: %s (%s)\nMobile Network Code: %s\nLocation Area Code: %s\nCell ID: %s\nSignal Strength: %s(%s%%) - %sdbm\nTime: %s\n" % (self.mcc, self.lookup_mcc(self.mcc), self.mnc, self.lac, self.cellid, self.bars, self.sigpct, self.dbm, time.asctime())
    return self.text

    def close(self):
    self.text = u""
    pass

    e32.ao_yield()

    class my_cell_info:
    def __init__(self):
    self.lock = e32.Ao_lock()
    self.timerstarted = 0

    self.old_title = appuifw.app.title
    appuifw.app.title = u"My Cell Info"

    self.exit_flag = False
    appuifw.app.exit_key_handler = self.abort

    appuifw.app.body = appuifw.Text()
    appuifw.app.body.set(u"Choose \"Fetch\" from options to fetch or refresh cell info anytime")
    self.dataobj = my_cell_id()

    self.timerobj = e32.Ao_timer()

    self.menu_fetch = (u"Fetch", self.handle_fetch)
    self.menu_auto_refresh_start = (u"Start Auto Fetch", self.handle_start_timer)
    self.menu_auto_refresh_end = (u"Stop Auto Fetch", self.handle_stop_timer)
    appuifw.app.menu = [self.menu_fetch, self.menu_auto_refresh_start, self.menu_auto_refresh_end]

    def loop(self):
    try:
    self.lock.wait()
    while not self.exit_flag:
    self.refresh()
    self.lock.wait()
    finally:
    self.dataobj.close()

    def close(self):
    appuifw.app.menu = []
    appuifw.app.body = None
    appuifw.app.exit_key_handler = None
    appuifw.app.title = self.old_title
    self.timerstarted = 0
    self.timerobj.cancel()

    def abort(self):
    # Exit-key handler.
    self.exit_flag = True
    self.lock.signal()

    def refresh(self):
    if 1 == self.timerstarted:
    self.dataobj.get_new_data()
    appuifw.app.body.set(self.dataobj.get_display_text())
    if 1 == self.timerstarted:
    self.timerobj.after(5, self.refresh)

    def handle_fetch(self):
    self.dataobj.get_new_data()
    self.refresh()

    def handle_start_timer(self):
    self.timerstarted = 1
    self.refresh()

    def handle_stop_timer(self):
    self.timerstarted = 0
    self.timerobj.cancel()

    def main():
    app = my_cell_info()
    try:
    app.loop()
    finally:
    app.close()

    if __name__ == "__main__":
    main()

  • Fire up Python on your phone and run the script!
It would be interesting if I had a GPS phone and I could link this up to www.cellspotting.com to tag my locality. May be I should work on it further...

2 comments:

chb said...

Hi,

Have you thought about how you could export this info (as well as any GPS info) to a database, so you could see:

a) interesting things like cell coverage in certain areas, routes

b) boring things like average cell signal variations by time, etc in your house, how it degrades during a major football match, speed of handover when travelling. etc

The GPS on the new N82 is up to this.

tan said...

Hi chb,

Yes, a later version of the script does log some information, thought not signal strength or GPS info. There are some apps which already do similar stuff, e.g. http://www.afischer-online.de/sos/celltrack/.

I wrote this script primarily to automatically populate the cellspotting database (http://www.cellspotting.com/). But it would definitely be interesting to see the patterns that you mention. Will think about it when I modify the script next.

Thanks!