Hi sirius3,
was meinst du mit Traceback?
Folgende Fehlermeldung erhalten ich wenn ich das Script ausführe:
Traceback (most recent call last):
File "./test1.py", line 46, in <module>
cursor.execute("INSERT INTO position (datum, zeit, latitude, longitude) VALUES (%s, %s, %s, %s)",(datum, zeit, latitude, longitude))
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1054, "Unknown column 'nan' in 'field list'")
Zur Sicherheit nochmal das ganze Script von mir:
Code: Alles auswählen
#! /usr/bin/python
# Written by Dan Mandle http://dan.mandle.me September 2012
# License: GPL 2.0
import os
from gps import *
from time import *
import time
import threading
import MySQLdb
gpsd = None #seting the global variable
os.system('clear') #clear the terminal (optional)
class GpsPoller(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
global gpsd #bring it in scope
gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
self.current_value = None
self.running = True #setting the thread running to true
def run(self):
global gpsd
while gpsp.running:
gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer
if __name__ == '__main__':
gpsp = GpsPoller() # create the thread
try:
gpsp.start() # start it up
while True:
#It may take a second or two to get good data
#print gpsd.fix.latitude,', ',gpsd.fix.longitude,' Time: ',gpsd.utc
os.system('clear')
datum = gpsd.utc
zeit = gpsd.fix.time
latitude = gpsd.fix.latitude
longitude = gpsd.fix.longitude
dbcon = MySQLdb.connect(host="localhost",user="root",passwd="Saskia2804!",db="raspi_gps" )
cursor = dbcon.cursor()
cursor.execute("INSERT INTO position (datum, zeit, latitude, longitude) VALUES (%s, %s, %s, %s)",(datum, zeit, latitude, longitude))
cursor.close()
dbcon.commit()
print '----------------------------------------'
print 'latitude ' , gpsd.fix.latitude
print 'longitude ' , gpsd.fix.longitude
# print 'time utc ' , gpsd.utc,' + ', gpsd.fix.time
# print 'altitude (m)' , gpsd.fix.altitude
# print 'eps ' , gpsd.fix.eps
# print 'epx ' , gpsd.fix.epx
# print 'epv ' , gpsd.fix.epv
# print 'ept ' , gpsd.fix.ept
# print 'speed (m/s) ' , gpsd.fix.speed
# print 'climb ' , gpsd.fix.climb
# print 'track ' , gpsd.fix.track
# print 'mode ' , gpsd.fix.mode
# print
# print 'sats ' , gpsd.satellites
time.sleep(2) #set to whatever
except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
print "\nKilling Thread..."
gpsp.running = False
gpsp.join() # wait for the thread to finish what it's doing
print "Done.\nExiting."
Gruß TOP