|
|
2011-05-30
, 20:43
|
|
|
Posts: 1,647 |
Thanked: 2,116 times |
Joined on Mar 2007
@ UNKLE's Never Never Land
|
#2
|
global StartTime StartTime = time.time()
PastTime = time.time() - StartTime if PastTime >= GPSTIMEOUT: data.stop()
|
|
2011-05-31
, 08:04
|
|
Posts: 27 |
Thanked: 17 times |
Joined on Jun 2010
|
#3
|
|
|
2011-05-31
, 08:09
|
|
Posts: 141 |
Thanked: 41 times |
Joined on Apr 2011
@ Ahmedabad, India
|
#4
|
|
|
2011-05-31
, 09:57
|
|
Posts: 214 |
Thanked: 140 times |
Joined on Aug 2010
|
#5
|
def turn_off_gps(control):
control.stop()
return False
def start_gps(control):
control.start()
gobject.timeout_add(30000, turn_off_gps, control)
return True
def init ():
control = ...
gobject.timeout_add(120000, start_gps, control)
I've followed the guide on http://wiki.maemo.org/PyMaemo/Using_Location_API. The purpose is to every 3rd hour connect with the GPS, fetch 10 coordinates and send them to my server. If I lose my phone I can always go to my server and find the coordinates of the phone. The script works fine, but the problem occurs when I enter a closed building without GPS-reception, then my phone tries forever until it finds GPS-reception which ofcourse drains the battery. So I'd like to implement a function that cancels the update if the script takes longer than 5 minutes. How can this be made?
Thanks!
import location import gobject x=0 def on_error(control, error, data): print "location error: %d... quitting" % error data.quit() def on_changed(device, data): global x if not device: return if device.fix: if device.fix[1] & location.GPS_DEVICE_LATLONG_SET: #http://maps.google.com/maps?q=62.62991%2C17.040443 print "http://maps.google.com/maps?q=%f,%f" % device.fix[4:6] if x>8: #commented out to allow continuous loop for a reliable fix - press ctrl c to break the loop, or program your own way of exiting) data.stop() else: x=x+1 def on_stop(control, data): data.quit() def start_location(data): data.start() return False loop = gobject.MainLoop() control = location.GPSDControl.get_default() device = location.GPSDevice() control.set_properties(preferred_method=location.METHOD_USER_SELECTED, preferred_interval=location.INTERVAL_5S) control.connect("error-verbose", on_error, loop) device.connect("changed", on_changed, control) control.connect("gpsd-stopped", on_stop, loop) gobject.idle_add(start_location, control) loop.run()