Writing /var/lib/dokuwiki/data/meta/teaching/ie0117/proyectos/2013/ii/proyecto_gpg_-_drivecr/coordenadasgps-cel.meta failed
teaching:ie0117:proyectos:2013:ii:proyecto_gpg_-_drivecr:coordenadasgps-cel
This is an old revision of the document!
This code transform the NMEA data that ShareGPS send to the port 50000 in latitude and longitude coordinates that Openstreetmaps can recognize.
#!/bin/bash # -*- ENCODING: UTF-8 -*- ./adb forward tcp:50000 tcp:50000 ./gpsread2.py exit
#!/usr/bin/python # -*- coding: utf-8 -*- ############################## gpsread2.py ############################################### #********** #sudo apt-get install python-mechanize python-beautifulsoup #**********Revisar si el webbrowser esta instalado import socket, string, sys, mechanize, webbrowser from bs4 import BeautifulSoup try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('localhost', 50000)) except : print '\n\n\n************No se ha establecido la comunicacion con el GPS********' raise SystemExit### def Muestra(datosa,datosc): #Muestras los datos obtenidos por el gps lat1, long1,gl,ml,sl,glo,mlo,slo= DEC (datosa[2],datosa[4]) direc= obtdirec() opensm(lat1,long1) #print '[-] Latitud Hemisferio: ',gl,' grados ',ml, ' minutos',sl,' segundos.',datosa[3] print '\n[-] Las coordenadas son: ' , lat1, long1 print '\n[-] La rápidez es: ', float(datosc)[7]*1.85, 'km/h' print '\n[-] La dirección es: '+direc save = raw_input('Desea guardar los datos?: (YES/no) ') if save == "" or save == 'YES' or save == 'yes' or save == 'Yes' or save == 'Y' or save == 'y': saved(lat1,long1,float(datosc)[7]*1.85,direc ) opensm (str(lat1), str(lon1)) def obtdirec(): #Extrae la direccion de los datos NMEA infov=s.recv(250) while '$GPGMC' not in infov: infov=s.recv(250) indv=info.find('$GPGMC') #Encuentra el inicio de $GPGGA $ endv=info.find('$',indv+6,) #Encuentra el final strgv = infov[indv:endv].rsplit(',') #Separa los elementos del strin print '[-] Hora actual: '+datos[0][0:2]+':'+datos[0][2:4]+':'+datos[0][4:6] azimut=int(datos[7]) rumbo='' if(azimut==0): rumbo='Norte' elif(azimut<90 and azimut>0): rumbo='Noreste' elif(azimut==90): rumbo='Este' if(azimut>90 and azimut < 180): rumbo='Sureste' if(azimut==180): rumbo='Sur' if(azimut>180 and azimut<360): rumbo='Suroeste' if(azimut==270): rumbo='Oeste' if(azimut>270 and azimut<360): rumbo='Suroeste' return (rumbo) def saved(lat1,long1,rapid,direc ): #Guarda los datos en un archivo llamado listGPS.txt en el directorio donde est[a el script de python try: desc=raw_input('\n\n\tDescripcion: ') f= open ('listGPS.txt', 'r') if f.readline() == "": f.close() f= open ('listGPS.txt', 'w') f.write ('\t\t\tLista de coordenadas GPS\n') f.close() else: pass f= open ('listGPS.txt', 'a') f.write ('\n---->\t'+lat1+'\t'+long1+'\t'+rapid+' km/h '+direc+'\t\t'+desc ) f.close() print '\n\nSe guardaron los datos en listGPS.txt' except: print '\n\n\n Error en la escritura de los datos.' def DEC (gms1,gms2): #Convierte los datos de Lat y Long grados, minutos y segundos en decimales seplat = gms1.rsplit('.') seplong= gms2.rsplit('.') gl=float(seplat[0][:2]) ml=float(seplat[0][2:]) sl=float('0.'+seplat[1])*60 glo=float(seplong[0][:3]) mlo=float(seplong[0][3:]) slo=(float('0.'+seplong[1])*60) lat= gl+(ml/60)+(sl/3600) #No hago casos para saber que signo llevan la latidud y la longitud, debido a q es restringido a Costa Rica, por tanto los signos no van a cambiar longi=-(glo+mlo/60+(slo/3600)) return (lat,str(longi),gl,ml,sl,glo,mlo,slo) def opensm(lat, lon): #Abre la posicion en OSM try: url= 'http://nominatim.openstreetmap.org/search.php' br = mechanize.Browser() br.set_handle_robots(False) # ignore robots br.set_handle_refresh(False) # can sometimes hang without this response = br.open(url) #for form in br.forms(): #Encuentra formularios #print "Form name:", form.name #print form br.form = list(br.forms())[0] # seleccion del formulario br.set_all_readonly(False) # allow everything to be written to control1 = br.form.find_control("q") #Selecciona el control por nombre control2 = br.form.find_control ("polygon") ll= lat+' '+lon control1.value= ll control2.value=['1'] resp = br.submit() response.close() html = br.response().read() # soup = BeautifulSoup(html) for link in soup.find_all(): x=(link.get('href')) #print "------>",type( x), x if type(x)== str: for i in lat: if i in x: es = True else: es = False if es == True: linkm=x break else: pass else: pass webbrowser.open_new(linkm) #Abre el link obtenido except: print '\n\n\n Revise la conexión a internet.' def detec(lectura): if lectura[2]== '': print 'NO HAY SEÑAL DE SATELITES, ASEGURESE DE NO ESTAR EN LUGARES CUBIERTOS' resp= raw_input('\n\n\nQuiere intentarlo de nuevo?: (YES/no) ') if resp == '' or resp == 'YES' or resp == 'yes' or resp == 'Yes' or resp == 'Y' or resp== 'y': try: main() except IndexError: main() else: return raise SystemExit else: pass def main(): info=s.recv(250) while '$GPGGA' not in info: info=s.recv(100) print info ind=info.find('$GPGGA') #Encuentra el inicio de $GPGGA en el codigo NMEA obtenido end=info.find('$',ind+6,) #Encuentra el final strg = info[ind:end].rsplit(',') #Separa los elementos del string resultante print strg detec(strg) #Detecta la señal de los satélites Muestra(strg,strgc,strgv) #opensm('10.08985','-84.47398') main()
***The problem in that method is about no satellites signal, in that case shareGPS sends empty NMEA data.
teaching/ie0117/proyectos/2013/ii/proyecto_gpg_-_drivecr/coordenadasgps-cel.1457364391.txt.gz · Last modified: 2022/09/20 00:08 (external edit)