Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import sys
- import datetime
- from influxdb import InfluxDBClient
- import pigpio
- # Set this variables, influxDB should be localhost on Pi
- host = "localhost"
- port = 8086
- user = ""
- password = ""
- # The database we created
- dbname = "poele"
- # Sample period (s)
- interval = 15
- pi = pigpio.pi()
- if not pi.connected:
- exit(0)
- sensor = pi.spi_open(0, 1000000, 0) # CE0 on main SPI
- # Allow user to set session and runno via args otherwise auto-generate
- if len(sys.argv) > 1:
- if (len(sys.argv) < 3):
- print "Must define session and runNo!!"
- sys.exit()
- else:
- session = sys.argv[1]
- runNo = sys.argv[2]
- else:
- session = "temperature"
- now = datetime.datetime.now()
- runNo = now.strftime("%Y%m%d")
- # Create the InfluxDB object
- client = InfluxDBClient(host, port, user, password, dbname)
- # Run until keyboard out
- try:
- while True:
- c, d = pi.spi_read(sensor, 2)
- if c == 2:
- word = (d[0]<<8) | d[1]
- if (word & 0x8006) == 0: # Bits 15, 2, and 1 should be zero.
- t = (word >> 3)/4.0
- cel = "{:.2f}".format(t)
- celcius = float(cel)
- far = (t*1.8)+32
- iso = time.ctime()
- #iso = time.strftime('%Y-%m-%dT%H:%M:%SZ',time.localtime(time.time()))
- client = InfluxDBClient(host='127.0.0.1', port=8086, username='', password='', ssl=False, verify_ssl=False)
- client.write(['interface,path=address,elementss=link value=3'],{'db':'yourdb'},204,'line')
- client.write_points(json_body)
- # Wait for next sample
- time.sleep(interval)
- except KeyboardInterrupt:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement