/
tracker3.py
106 lines (82 loc) · 3.01 KB
/
tracker3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#Script written in python for the S60
# Written for the Nokia 6110 Navigator (with a slightly broken screen!)
# Aim is to have it turn on GPS, get a position, turn off the GPS and then send it by SMS
import sysinfo, positioning, e32, time, messaging
#Functions
def initialize_gps():
'''This function initializes the GPS. The select_module(module_id) can be used to select the GPS module in this function.
In this case we are using the default GPS (integrated GPS) hence we do not need to select it.'''
print "Intializing GPS"
global gps_data
global gpson
#Intitialize the global dictionary with some initial dummy value (0.0 in this case)
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}
}
try:
# Set requesters - it is mandatory to set at least one
positioning.set_requestors([{"type":"service","format":"application","data":"gps_app"}])
# Request for a fix every 0.5 seconds
positioning.position(course=1,satellites=1,callback=cb_gps, interval=1000000,partial=1)
# Sleep for 30 seconds for the intitial fix
e32.ao_sleep(30)
gpson = 1
except:
print "Problem with GPS"
def cb_gps(event):
global gps_data
gps_data = event
def cb(state):
if state==messaging.ESent:
print "**Message was sent**"
if state==messaging.ESendFailed:
print "**Something went wrong**"
def stop_gps():
global gpson
'''Function to stop the GPS'''
try:
positioning.stop_position()
gpson_off = 0
print "GPS Stopped"
except:
print "Problem with GPS"
#Main Loop
global gpson
gpson = 0
loop_number = 0
count = 0
old_lat = 0.0
print "Starting Tracker3 program"
while True:
if (gpson == 0):
#initialize GPS
initialize_gps()
sats = gps_data['satellites']['used_satellites']
print sats, gpson, gps_data['position']['latitude']
if ((sats > 3) and (gps_data['position']['latitude'] != old_lat)):
print gps_data['satellites']['used_satellites'], gps_data['position']['latitude'], gps_data['position']['longitude'], gps_data['course']['speed']
#stop GPS
#stop_gps()
old_lat = gps_data['position']['latitude']
#Get battery data
battery = sysinfo.battery()
#Get signal strength
signal = sysinfo.signal_dbm()
#Get time
user_time = time.time()
count = count + 1
#Print data
telem_string = "%d,%d,%f,%f,%.2f,%d,%d,%d" % (count, user_time, gps_data['position']['latitude'], gps_data['position']['longitude'], gps_data['course']['speed'], gps_data['course']['heading'], signal, battery)
print telem_string
messaging.sms_send('+447748628528', telem_string,'8bit',cb)
#Reset loop number
loop_number = 0
#Sleep time, sleep for 5 minutes
print "Sleeping"
e32.ao_sleep(300)
else:
loop_number = loop_number + 1
print "No GPS Position yet, retry:", loop_number
e32.ao_sleep(10)