Hey Leute,
Ich habe ein kleines Problem,
ich möchte dynamische Daten in meine Datenbank einlesen und speichern.
Leider bekomme ich immer wieder eine Fehlermeldung und weiß nicht, wie ich sie beheben soll.
Programmcode:
#!/usr/bin/env python
import sys
import MySQLdb as mdb
import time as Zeit
import datetime
import grovepi
# Connect the Grove Sound Sensor to analog port A0
# SIG,NC,VCC,GND
sound_sensor = 0
grovepi.pinMode(sound_sensor,"INPUT")
connect = mdb.connect("localhost", 'root', 'raspberry', 'raspberrypidb');
c = connect.cursor()
c.execute("SELECT * FROM Lautstaerke")
connect.commit()
while True:
try:
# Read the sound level
sensor_value = grovepi.analogRead(sound_sensor)
c.execute("INSERT INTO Lautstaerke(Datum, Zeit, Lautstaerke_DEZ, Lautstaerke_dB) VALUES('CURRENT_DATE(), NOW(), 200, 200/10))")
print "sensor_value =", sensor_value
Zeit.sleep(.5)
except IOError:
print "Error"
Fehlermeldung:
pi@raspberrypi ~/GrovePi/Software/Python $ sudo python grove_sound_sensor.py
Traceback (most recent call last):
File "grove_sound_sensor.py", line 28, in <module>
c.execute("INSERT INTO Lautstaerke(Datum, Zeit, Lautstaerke_DEZ, Lautstaerke_dB) VALUES('CURRENT_DATE(), NOW(), 200, 200/10))")
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.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''CURRENT_DATE(), NOW(), 200, 200/10))' at line 1")
Kann mir da jemand helfen?