Guidance Need For QPython GPS Logger Program

20 views
Skip to first unread message

TheICQ

unread,
May 25, 2018, 7:32:41 PM5/25/18
to QPython

Hi I am testing my below program on my Android Moto E4. It does not seem to get a GPS Fix even when I am outside waiting for an 30 mins can anybody please guide me where I am going wrong. Below is my code using Qpython 3.6 and Qpythong 2.7 Android app. The main goal of this program is to get a GPS fix and enter the logs in the file which is stored in the phone at a particular location . I also tested but seems to be giving some errors.

 import androidhelper, os, time, datetime 

droid = androidhelper.Android()
droid.startLocating()

while not droid.readLocation()[1].has_key('gps') :
    print "Waiting on gps to turn on"
    time.sleep(15) 

if not os.path.exists('/sdcard/logs'):
    os.mkdir('/sdcard/logs') 

# Now we'll loop until the user closes the application 

while True:
    loc = droid.readLocation() 

    lat = str(loc.result['gps']['latitude'])
    lon = str(loc.result['gps']['longitude'])
    alt = str(loc.result['gps']['altitude']) 
    now = str(datetime.datetime.now())
    f = open('/sdcard/logs/logfile.txt','a')
    outString = now + ',' + lat + ',' + lon + ',' + alt + '\n'
    f.write(outString)
    print outString
    f.close()
    time.sleep(15)
Reply all
Reply to author
Forward
0 new messages