Archived:How to use your phone as a panic button using PySymbian

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

This Python on Symbian code example acts as a panic button - sending by SMS your location (cell ID and LAC, and GPS if available) to predefined emergency numbers and recipients.

Article Metadata
Created: tommybreit (29 Aug 2008)
Last edited: hamishwillee (31 May 2013)


The PySymbian code posted here will basically do the following when run:

  • Immediately transmit LAC and CellID to predefined recipients via SMS (this allows for a rough containment of where you are located in your emergency)
  • Call an predefined emergency number
  • Try to get the GPS position of your phone and if it gets a signal transmit Latitude/Longitude and current speed every three minutes via SMS to predefined recipients

This sums up to a rather complete emergency package acting as some kind of panic button (place this as an .sis application on your today screen or similar...). If you ever get into an emergency immediately broadcast all relevant info to get help!


import e32, appuifw, positioning, location, messaging, telephone
def gps_init():
global gps_data
gps_data = {
'satellites': {'horizontal_dop': 0.0, 'used_satellites': 0, 'vertical_dop': 0.0, 'time': 0.0,'satellites': 0, 'time_dop':0.0},
'position': {'latitude': 0.0, 'altitude': 0.0, 'vertical_accuracy': 0.0, 'longitude': 0.0, 'horizontal_accuracy': 0.0},
'course': {'speed': 0.0, 'heading': 0.0, 'heading_accuracy': 0.0, 'speed_accuracy': 0.0}
positioning.position(course=1,satellites=1,callback=gps, interval=500000,partial=0)
appuifw.note(u'Problem with GPS','error')
def gps(event):
global gps_data
gps_data = event
def gps_stop():
#this function stops GPS
appuifw.note(u'Problem with GPS','error')
def gps_emerg():
gpessa = str( 'My GPS position is (Lat/Long/Geschwindigkeit): %s, %s, %i' % (pos_lat, pos_long, speed) )
print gpessa
messaging.sms_send('0123456789', gpessa) #PUT number of receipient you want to inform here
print 'GPS Position sent!'
print 'Recalling emergency phone number...'
telephone.dial('0123456789') #PUT some emergency number here
ftrack = location.gsm_location()
messa = str( 'I have hit the panic button! My current cell information is LAC %s and Cell-ID %s. Trying to send my exact GPS position soon...' % (ftrack[2] , ftrack[3]) )
print messa
messaging.sms_send('0123456789', messa) #PUT number of receipient you want to inform here
print 'SMS sent!'
print 'Calling emergency phone number...' #PUT some emergency number here
count = 0
while True:
count = count + 1
sat = gps_data['satellites']['used_satellites']
pos_lat = gps_data['position']['latitude']
pos_long = gps_data['position']['longitude']
speed = gps_data['course']['speed']
if pos_lat > 0:
print 'Found GPS position, terminating call to free the line...'

PS: Credits also go to the original contributor of the GPS code. Please keep in mind that you will need the "unsigned_testrange" edition PySymbian for location/position capabilities to function properly.

This page was last modified on 31 May 2013, at 04:05.
126 page views in the last 30 days.