Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. sudo mount -t cifs //THOMASRASPI/PiShare /mnt/thomasraspi username=pi,password=######,domain=nixcraft
  2. sudo /usr/bin/python /home/pi/Adafruit_Python_DHT/examples/feuchtigkeitsmesser.py
  3.  
  4. #!/usr/bin/python
  5. # -*- coding: utf-8 -*-
  6. # Author: Thomas
  7.  
  8. # Dann wird das Python Script gecalled
  9. import os
  10. import subprocess
  11. import sys
  12. import time
  13. import csv
  14. import Adafruit_DHT
  15. import datetime
  16. import sqlite3
  17. #SQLite
  18. conn = sqlite3.connect('/mnt/thomasraspi/tempfeucht.db') #Zur Datenbank verbinden
  19. c = conn.cursor() #Cursor Objekt erstellen
  20. #CSV
  21. csvfile = open('tempfeucht.csv','wb')
  22. writer = csv.writer(csvfile)
  23. writer.writerow(['Time','Temperatur','Feuchtigkeit'])
  24. # Endlosschleife
  25. if len(sys.argv) > 1:
  26. print 'Output an'
  27. else:
  28. FNULL = open(os.devnull, 'w')
  29. retcode = subprocess.call(['echo', 'foo'], stdout=FNULL, stderr=subprocess.STDOUT)
  30.  
  31. while True:
  32. try:
  33. humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 4)
  34. if humidity is not None and temperature is not None:
  35. cet = datetime.datetime.today() + datetime.timedelta(hours=2) #Aktuelle Zeit
  36. temperature = round(temperature,1)
  37. humidity = round(humidity,1)
  38. print('{0} Temp={1}C° Humidity={2}%'.format(cet, temperature, humidity))
  39. writer.writerow([cet,temperature,humidity])
  40. c.execute("""INSERT INTO tempdaten (DATETIME, TEMPERATUR, FEUCHTIGKEIT)
  41. VALUES (?, ?, ?);""",(cet, temperature, humidity))
  42. conn.commit()
  43. time.sleep(555)
  44. else:
  45. print('Failed to get reading. Try again!')
  46. sys.exit(1)
  47. except EOFError as e:
  48. print 'EXIT', 'EOF Error'
  49. c.close()
  50. sys.exit()
  51. except KeyboardInterrupt: #Bei Strg+C Die Verbindung schließen
  52. print 'Connection closed'
  53. c.close()
  54. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement