Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sudo mount -t cifs //THOMASRASPI/PiShare /mnt/thomasraspi username=pi,password=######,domain=nixcraft
- sudo /usr/bin/python /home/pi/Adafruit_Python_DHT/examples/feuchtigkeitsmesser.py
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- # Author: Thomas
- # Dann wird das Python Script gecalled
- import os
- import subprocess
- import sys
- import time
- import csv
- import Adafruit_DHT
- import datetime
- import sqlite3
- #SQLite
- conn = sqlite3.connect('/mnt/thomasraspi/tempfeucht.db') #Zur Datenbank verbinden
- c = conn.cursor() #Cursor Objekt erstellen
- #CSV
- csvfile = open('tempfeucht.csv','wb')
- writer = csv.writer(csvfile)
- writer.writerow(['Time','Temperatur','Feuchtigkeit'])
- # Endlosschleife
- if len(sys.argv) > 1:
- print 'Output an'
- else:
- FNULL = open(os.devnull, 'w')
- retcode = subprocess.call(['echo', 'foo'], stdout=FNULL, stderr=subprocess.STDOUT)
- while True:
- try:
- humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 4)
- if humidity is not None and temperature is not None:
- cet = datetime.datetime.today() + datetime.timedelta(hours=2) #Aktuelle Zeit
- temperature = round(temperature,1)
- humidity = round(humidity,1)
- print('{0} Temp={1}C° Humidity={2}%'.format(cet, temperature, humidity))
- writer.writerow([cet,temperature,humidity])
- c.execute("""INSERT INTO tempdaten (DATETIME, TEMPERATUR, FEUCHTIGKEIT)
- VALUES (?, ?, ?);""",(cet, temperature, humidity))
- conn.commit()
- time.sleep(555)
- else:
- print('Failed to get reading. Try again!')
- sys.exit(1)
- except EOFError as e:
- print 'EXIT', 'EOF Error'
- c.close()
- sys.exit()
- except KeyboardInterrupt: #Bei Strg+C Die Verbindung schließen
- print 'Connection closed'
- c.close()
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement