Hallo Leute ich will das in meiner Datenbank tabelle die Normale Zeit und Datum angezeigt wird.
Das ist der ORGINAL CODE der Funktioniert aber Datum/Zeit in UNIX Datum in die Datenbank schreibt.
Code
import RPi.GPIO as GPIO
import time
import sqlite3 as lite
import sys
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
# Define GPIO to use on Pi
PIR1_PIR = 7
#PIR2_PIR = 8
print "PIR Module Test (CTRL-C to exit)"
# Set pin as input
GPIO.setup(PIR1_PIR,GPIO.IN) # Echo
#GPIO.setup(PIR2_PIR,GPIO.IN)
Current_State = 0
Previous_State = 0
try:
print "Alarmanlage PIR Sensoren ; SCHARF ;"
# Loop until PIR output is 0
while GPIO.input(PIR1_PIR) ==1:
Current_State = 0
print " Ready;Bereit 'NO ALARM'"
# Loop until users quits with CTRL-C
while True :
ts = time.time()
# Pfad zu SQlite 3 Datenbank
db = "database.db"
# Read PIR state PIR 1
Current_State = GPIO.input(PIR1_PIR)
if Current_State==1 and Previous_State==0:
# PIR is triggered
print " ALARM ; !!! MOTION DETECTED !!! UNERLAUBTE AUTHORISIERUNG"
# Record previous state
Previous_State=1
con = lite.connect(db)
with con:
cur = con.cursor()
cur.execute("INSERT INTO tbl_log values(null , %d, 'PIR 1','ALARM')" % (ts) )
elif Current_State==0 and Previous_State==1:
# PIR has returned to ready state
print " Ready;BEREIT 'NO ALARM'"
Previous_State=0
con = lite.connect(db)
with con:
cur = con.cursor()
cur.execute("INSERT INTO tbl_log values(null , %d, 'PIR 1','BEREIT')" % (ts) )
# Wait for 10 milliseconds
time.sleep(1)
except KeyboardInterrupt:
print " Quit"
# Reset GPIO settings
GPIO.cleanup()
Alles anzeigen
Das ist der VERSUCHS Code mit dem ich die UNIX Datum time tamp in der Datenbank ändern wollte in Normal PC Datum/Zeit z.b. "2014-10-12 21:20:30"
Code
import RPi.GPIO as GPIO
import time
import sqlite3 as lite
import sys
import datetime
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
# Define GPIO to use on Pi
PIR1_PIR = 7
#PIR2_PIR = 8
print "PIR Module Test (CTRL-C to exit)"
# Set pin as input
GPIO.setup(PIR1_PIR,GPIO.IN) # Echo
#GPIO.setup(PIR2_PIR,GPIO.IN)
Current_State = 0
Previous_State = 0
try:
print "Alarmanlage PIR Sensoren ; SCHARF ;"
# Loop until PIR output is 0
while GPIO.input(PIR1_PIR) ==1:
Current_State = 0
print " Ready;Bereit 'NO ALARM'"
# Loop until users quits with CTRL-C
while True :
ts = datetime.datetime(*time.strptime("2007-03-04T21:08:12", "%Y-%m-%dT%H:%M:%S")[:6])
# Pfad zu SQlite 3 Datenbank
db = "database2.db"
# Read PIR state PIR 1
Current_State = GPIO.input(PIR1_PIR)
if Current_State==1 and Previous_State==0:
# PIR is triggered
print " ALARM ; !!! MOTION DETECTED !!! UNERLAUBTE AUTHORISIERUNG"
# Record previous state
Previous_State=1
con = lite.connect(db)
with con:
cur = con.cursor()
cur.execute("INSERT INTO tbl_log values(null , %d, 'PIR 1','ALARM')" % (ts) )
elif Current_State==0 and Previous_State==1:
# PIR has returned to ready state
print " Ready;BEREIT 'NO ALARM'"
Previous_State=0
con = lite.connect(db)
with con:
cur = con.cursor()
cur.execute("INSERT INTO tbl_log values(null , %d, 'PIR 1','BEREIT')" % (ts) )
# Wait for 10 milliseconds
time.sleep(1)
except KeyboardInterrupt:
print " Quit"
# Reset GPIO settings
GPIO.cleanup()
Alles anzeigen
Stimmt das so ?
Hat jemand eine Idee wie man es noch machen könnte