Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import math
- import requests
- import sys
- from time import sleep
- IP = "s2.3cte.local" # The IP of the machine hosting your influxdb instance
- DB = "test_db" # The database to write to, has to exist
- USER = "admin" # The influxdb user to authenticate with
- PASSWORD = "ksemwetipg" # The password of that user
- TIME = 1 # Delay in seconds between two consecutive update
- STATUS_MOD = 5 # The interval in which the updates count will be printed to your console
- n = 0
- temp = 0
- while True:
- for d in range(0, 360):
- with open('/sys/class/thermal/thermal_zone0/temp', 'r') as fin:
- temp = fin.read()
- v = 'temp_value value=%s' % temp
- ## without autentication
- #r = requests.post("http://%s:8086/write?db=%s" %(IP, DB), data=v)
- ## with autentication
- r = requests.post("http://%s/influxdb/write?db=%s" %(IP, DB), auth=(USER, PASSWORD), data=v)
- if r.status_code != 204:
- print 'Failed to add point to influxdb (%d) - aborting.' %r.status_code
- sys.exit(1)
- n += 1
- sleep(TIME)
- if n % STATUS_MOD == 0:
- print '%d points inserted.' % n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement