Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import sys
- import Adafruit_DHT
- from datetime import datetime
- from elasticsearch import Elasticsearch
- import RPi.GPIO as GPIO
- import ipgetter
- humidity, temperature = Adafruit_DHT.read_retry(11,4)
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(17, GPIO.OUT)
- tFile = open('/sys/class/thermal/thermal_zone0/temp')
- temp = float(tFile.read())
- tempC = temp/1000
- tFile.close()
- GPIO.cleanup()
- ext_ip = ipgetter.myip()
- es = Elasticsearch(host='abc.mydomain.com', port=9200, http_auth=('admin', 'admin'))
- doc = {
- 'cputemp': tempC,
- 'airtemp': temperature,
- 'humidity': humidity,
- 'external_ip': ext_ip,
- 'author': 'tomas',
- 'timestamp': datetime.now()
- }
- res = es.index(index="raspberry_iot", doc_type='sys_stats', body=doc)
- print datetime.now()
- print tempC
- print ext_ip
- print(res['created'])
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement