Advertisement
Typhoon

Raspberry Pi Temp/Humidity to ELK

Dec 25th, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import sys
  4. import Adafruit_DHT
  5. from datetime import datetime
  6. from elasticsearch import Elasticsearch
  7. import RPi.GPIO as GPIO
  8. import ipgetter
  9.  
  10. humidity, temperature = Adafruit_DHT.read_retry(11,4)
  11.  
  12. GPIO.setmode(GPIO.BCM)
  13. GPIO.setup(17, GPIO.OUT)
  14.  
  15. tFile = open('/sys/class/thermal/thermal_zone0/temp')
  16. temp = float(tFile.read())
  17. tempC = temp/1000
  18. tFile.close()
  19. GPIO.cleanup()
  20. ext_ip = ipgetter.myip()
  21.  
  22. es = Elasticsearch(host='abc.mydomain.com', port=9200, http_auth=('admin', 'admin'))
  23. doc = {
  24.     'cputemp': tempC,
  25.     'airtemp': temperature,
  26.     'humidity': humidity,
  27.     'external_ip': ext_ip,
  28.     'author': 'tomas',
  29.     'timestamp': datetime.now()
  30.        }
  31. res = es.index(index="raspberry_iot", doc_type='sys_stats', body=doc)
  32. print datetime.now()
  33. print tempC
  34. print ext_ip
  35. print(res['created'])
  36.  
  37. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement