Advertisement
Guest User

jadis

a guest
Jul 4th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. import os
  2. import sched, time
  3. import sys
  4. import mysql.connector
  5. import Adafruit_DHT as dht
  6.  
  7. channel = 'pi-jadis'
  8.  
  9. sql_conn = mysql.connector.connect(user='python_user',password='test',host='localhost', database='jadis_sensor')
  10. cursor = sql_conn.cursor()
  11.  
  12. timestamp = time.time()
  13.  
  14. h,t = dht.read_retry(dht.DHT22, 4)
  15.  
  16. temp='{0:0.1f}'.format(t)
  17. hum='{0:0.1f}'.format(h)
  18. message = {'temperature': temp, 'humidity':hum}
  19.  
  20. reading = ("INSERT INTO temp_hum (channel, readings, timestamp) VALUES (%(chann)s ,%(mess)s, %(timestamp)s)")
  21.  
  22. readings = {
  23.         'chann': channel,
  24.         'mess': message,
  25.         'timestamp': timestamp
  26. }
  27.  
  28. cursor.execute(reading, readings)
  29.  
  30. sql_conn.commit()
  31.  
  32. cursor.close()
  33. sql_conn.close()
  34.  
  35. print'<%s> %s' % (channel ,message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement