Geht vermutlich.
Hab ich aber nicht für bezahlt.
Als Bausatz sollte das wesentlich billiger sein.
SMD = Surface Mounted Device. Da gibt's keine Beine mehr.Syon hat geschrieben:
Das Bauteil hat auch keine Beine mehr.
Die sind bündig weg.
Code: Alles auswählen
#!/usr/bin/env python
import subprocess
import smtplib
import socket
from email.mime.text import MIMEText
import time
import MySQLdb as mdb
import sys
import RPi.GPIO as GPIO, time, os
from sys import stdout
from datetime import datetime
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(2, GPIO.IN)
gread = 0
hcount = 0
load = 0
lch = 0
imp = 0
lcheck = 0
now = datetime.now()
last = now
lastlast = last
delta = now - last
pstart = 1
Empf = 'mail'
Abs = 'mail'
Passw = 'Password'
smtpserv = smtplib.SMTP_SSL('Server',465)
smtpserv.ehlo()
# In Account einloggen
smtpserv.login(Abs, Passw)
Wtxt = 'Ladestation neu gestartet'
cmsg = MIMEText(Wtxt)
cmsg['Subject'] = 'Ladestation neu gestartet'
cmsg['From'] = 'Ladestation'
cmsg['To'] = Empf
smtpserv.sendmail(Abs, [Empf], cmsg.as_string())
smtpserv.quit()
def RCtime (channel):
# print "imp" #Zum Debuggen
global last
global lcheck
global gread
global hcount
global imp
imp = 1
now = datetime.now()
delta = now - last
lastlast = last
last = now
delta = last - lastlast
if delta.seconds < 30:
if lcheck == 1:
hcount += 1
if hcount > 100:
hcount = 1
gread += 0.00250 # entspricht 400 Impulsen pro kW. 0.00125=800 Imps/kW
writedb(gread,hcount)
else:
setload()
lcheck = 1
writedb(gread,hcount)
writerem(1)
postit(1, 0)
def setload ():
con = None
try:
con = mdb.connect('localhost', 'DB_User', 'Password', 'emob');
cur = con.cursor()
cur.execute("UPDATE emob.settings SET loading='1'")
con.commit()
except mdb.Error, e:
print "Error %d: %s" % (e.args[0],e.args[1])
sys.exit(1)
finally:
if con:
con.close()
def unsetload ():
con = None
try:
con = mdb.connect('localhost', 'DB_User', 'Password', 'emob');
cur = con.cursor()
cur.execute("UPDATE emob.settings SET loading='0'")
con.commit()
except mdb.Error, e:
print "Error %d: %s" % (e.args[0],e.args[1])
sys.exit(1)
finally:
if con:
con.close()
def writedb (akw,fcount):
loading = 0
con = None
try:
con = mdb.connect('localhost', 'DB_User', 'Password', 'emob');
cur = con.cursor()
cur.execute("SELECT loading FROM emob.settings")
ldata = cur.fetchone()
loading = ldata[0]
if loading == 1:
cur.execute("SELECT total FROM emob.countings")
data = cur.fetchone()
tkw = data[0]
if fcount == 100:
tkw += 1
sql = "UPDATE emob.countings SET actual=%s, total=%s"
cur.execute(sql, (akw,tkw))
con.commit()
except mdb.Error, e:
print "Error %d: %s" % (e.args[0],e.args[1])
sys.exit(1)
finally:
if con:
con.close()
return loading
def writerem (rload):
con = None
try:
con = mdb.connect('Server', 'DB_User', 'Password', 'DB_Name');
cur = con.cursor()
sql = "UPDATE DB_Name.station SET loading=%s" # ebenfalls anpassen!
cur.execute(sql, (rload))
con.commit()
except mdb.Error, e:
print "Error %d: %s" % (e.args[0],e.args[1])
sys.exit(1)
finally:
if con:
con.close()
def postit(pload, pkw):
Empfaenger = 'mail'
Absender = 'mail'
Passwort = 'Password'
smtpserver = smtplib.SMTP_SSL('Server',465)
smtpserver.ehlo()
# In Account einloggen
smtpserver.login(Absender, Passwort)
# Text
if pload == 1:
Wert = 'Ladevorgang gestartet'
if pload == 0:
Wert = 'Ladevorgang beendet: %s kW' % pkw
msg = MIMEText(Wert)
# Betreff + Datum
msg['Subject'] = 'Nachricht von der Ladestation'
# Absender
msg['From'] = 'Ladestation'
#Empfaenger
msg['To'] = Empfaenger
# E-Mail abschicken
smtpserver.sendmail(Absender, [Empfaenger], msg.as_string())
smtpserver.quit()
unsetload()
writedb(0,0)
GPIO.add_event_detect(2, GPIO.RISING, callback = RCtime, bouncetime = 100)
try:
while True:
imp = 0
time.sleep(30)
if imp == 0 and lcheck == 1:
unsetload()
lcheck = 0
writerem(0)
postit(0, gread)
hcount = 0
gread = 0
except KeyboardInterrupt:
GPIO.remove_event_detect(2)
Code: Alles auswählen
#!/usr/bin/env python
import time
import subprocess
import MySQLdb as mdb
from datetime import datetime
try:
while True:
con = mdb.connect('localhost', 'DB_User', 'Password', 'emob');
cur = con.cursor()
cur.execute("SELECT loading FROM emob.settings")
ldata = cur.fetchone ()
if ldata == (1L,):
subprocess.call( "vcgencmd display_power 1", shell=True )
time.sleep(600) # 10 Minuten Nachlaufzeit.
else:
time.sleep(5)
subprocess.call( "vcgencmd display_power 0", shell=True )
else:
time.sleep(5)
except mdb.Error, e:
print "Error %d: %s" % (e.args[0],e.args[1])
sys.exit(1)
finally:
if con:
con.close()
Code: Alles auswählen
#!/bin/sh
xset -dpms # disable DPMS (Energy Star) features.
xset s off # disable screen saver
xset s noblank # don't blank the video device
unclutter &
matchbox-window-manager &
midori -e Fullscreen -a http://localhost/index.php
Code: Alles auswählen
xinit /home/pi/startMidori.sh &
(/bin/sleep 10 && /usr/local/bin/emob/impsim.py) &
(/bin/sleep 15 && /usr/local/bin/emob/screen.py) &
exit 0