I am using the GPS sensor NEO and I get the coordinates correctly, I want to capture the reading string every 5 seconds. As I mentioned, I manage to read but I do not capture it every 5 seconds, my program is as follows:
import gps
import itertools
import json
import os
import portdetect
import time
import serial
from threading import Thread
(puerto1, puerto2) = portdetect.detectar_puerto()
print puerto1, puerto2
port = serial.Serial(puerto1, 115200, timeout=1)
os.system('sudo systemctl stop gpsd.socket')
time.sleep(2)
os.system('sudo systemctl disable gpsd.socket')
time.sleep(2)
comando = 'sudo gpsd ' + puerto2 + ' -F /var/run/gpsd.sock'
os.system(str(comando))
#print str(comando)
# Listen on port 2947 (gpsd) of localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
class Contador:
def __init__(self, comienzo = 0):
self.raw_datos = comienzo
def leergps(self):
while True:
try:
report = session.next()
# Wait for a 'TPV' report and display the current time
# To see all report data, uncomment the line below
# print report
if report['class'] == 'TPV':
if hasattr(report, 'time') or hasattr(report, 'lat') or hasattr(report, 'lon') or hasattr(report,
'speed'):
datos = [report.time, report.lat, report.lon, report.speed]
clave = ['tiempo', 'lat', 'lon', 'speed']
diccionario = dict(itertools.izip(clave, datos))
self.raw_datos = (json.dumps(diccionario))
# print raw_datos
return self.raw_datos
else:
return report['class']
except:
print "Error de coordenadas"
def capturar(self):
while True:
posicion = self.raw_datos
time.sleep(5)
print posicion
if __name__ == '__main__':
c = Contador()
Thread(target = c.capturar).start()
Thread(target = c.leergps()).start()
When I run the program, it sends me only "0".
Any ideas that can guide me?