exit("Please : export PYOTSDB_ENDPOINT='https://opentsdb.iot.runabove.io'") end_point = u"%s/api/query" % end_point source = os.environ.get('PYOTSDB_HOSTNAME') if not source: exit("Please : export PYOTSDB_HOSTNAME=$(hostname -s)") delta = os.environ.get('PYOTSDB_DELTA') if not delta: exit("Please : export PYOTSDB_DELTA=XX") delta = int(delta)*60*60 # init pyotsb worker from PyOTSDB import PyOTSDB con = PyOTSDB(endpoint=end_point, username=token_id, password=token_key) # making query print("Getting the count of points since %sh for indoor t°" % os.environ.get('PYOTSDB_DELTA')) res = con.get(start=int(time.time())-delta, queries = [{ "metric": "home.temp.indoor", "aggregator": "avg", "tags": { "source": os.uname()[1].split('.')[0] } }] ) print res data = json.loads(res)
if not end_point: exit("Please : export PYOTSDB_ENDPOINT='https://opentsdb.iot.runabove.io'") end_point = u"%s/api/put" % end_point source = os.environ.get('PYOTSDB_HOSTNAME') if not source: exit("Please : export PYOTSDB_HOSTNAME=$(hostname -s)") period = int(os.environ.get('PYOTSDB_PERIOD')) if not period: exit("Please : export PYOTSDB_PERIOD=YY") # init pyotsb worker from PyOTSDB import PyOTSDB con = PyOTSDB(endpoint=end_point, username=token_id, password=token_key) while True: timer = int(time.time()) print("sending indoor t°") con.put(metric_name='home.temp.indoor', timestamp=timer, value=random.randrange(20, 25), tags = { 'source': source, }) print("sending outdoor t°") con.put(metric_name='home.temp.outdoor', timestamp=timer, value=random.randrange(10, 16),