Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sched, time
- import sys
- import mysql.connector
- import Adafruit_DHT as dht
- channel = 'pi-jadis'
- sql_conn = mysql.connector.connect(user='python_user',password='test',host='localhost', database='jadis_sensor')
- cursor = sql_conn.cursor()
- timestamp = time.time()
- h,t = dht.read_retry(dht.DHT22, 4)
- temp='{0:0.1f}'.format(t)
- hum='{0:0.1f}'.format(h)
- message = {'temperature': temp, 'humidity':hum}
- reading = ("INSERT INTO temp_hum (channel, readings, timestamp) VALUES (%(chann)s ,%(mess)s, %(timestamp)s)")
- readings = {
- 'chann': channel,
- 'mess': message,
- 'timestamp': timestamp
- }
- cursor.execute(reading, readings)
- sql_conn.commit()
- cursor.close()
- sql_conn.close()
- print'<%s> %s' % (channel ,message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement