def upload_data(self, cluster, node, sensor_t, sensor_q, sensor_u, measurements): x = Videk(videk_token) x.api_url = videk_api_url cluster_id = x.getClusterID(cluster) if cluster_id == None: x.createCluster(cluster) cluster_id = x.getClusterID(cluster) node_id = x.getNodeID(node) if node_id == None: x.createNode(node, cluster_id) node_id = x.getNodeID(node) sensor_id = x.getSensorID(node, sensor_t, sensor_q) if sensor_id == None: x.createSensor(node_id, sensor_t, sensor_q, sensor_u) sensor_id = x.getSensorID(node, sensor_t, sensor_q) videk_m = """{"latitude":"","longitude":"","ts":"","value":""}""" preparedData = [] for measurement in measurements: data = json.loads(videk_m) data["value"] = measurement["v"] data["ts"] = datetime.fromtimestamp(int(measurement["t"])).isoformat() data["latitude"] = measurement["lat"] data["longitude"] = measurement["lon"] preparedData.append(data) x.uploadMesurements(preparedData, node_id, sensor_id)
def upload_data(self, cluster, node, sensor_t, \ sensor_q, sensor_u, measurements): x = Videk(videk_token) x.api_url = videk_api_url cluster_id = x.getClusterID(cluster) if cluster_id == None: x.createCluster(cluster) cluster_id = x.getClusterID(cluster) node_id = x.getNodeID(node) if node_id == None: x.createNode(node, cluster_id) node_id = x.getNodeID(node) sensor_id = x.getSensorID(node, sensor_t, sensor_q) if sensor_id == None: x.createSensor(node_id, sensor_t, sensor_q, sensor_u) sensor_id = x.getSensorID(node, sensor_t, sensor_q) videk_m = '''{"latitude":"","longitude":"","ts":"","value":""}''' preparedData = [] for measurement in measurements: data = json.loads(videk_m) data['value'] = measurement["v"] data['ts'] = datetime.fromtimestamp(int(measurement["t"])) \ .isoformat() data['latitude'] = measurement["lat"] data['longitude'] = measurement["lon"] preparedData.append(data) x.uploadMesurements(preparedData, node_id, sensor_id)
from datetime import datetime from videk_rest_client import Videk from random import randint x = Videk('secret') x.api_url = "http://localhost/api" cluster = "example"; node = "example.com" sensor_t = "test" sensor_q = "test_value" sensor_u = "t" cluster_id = x.getClusterID(cluster) if cluster_id == None: x.createCluster(cluster) cluster_id = x.getClusterID(cluster) node_id = x.getNodeID(node) if node_id == None: x.createNode(node, cluster_id) node_id = x.getNodeID(node) sensor_id = x.getSensorID(node, sensor_t, sensor_q) if sensor_id == None: x.createSensor(node_id, sensor_t, sensor_q, sensor_u) sensor_id = x.getSensorID(node, sensor_t, sensor_q) measurement = '''{"latitude":"","longitude":"","ts":"","value":""}''' while True:
x = Videk('nRmU1rIiTETP4brIPkKr+SO/uumG5kzR') cluster = "beep"; node = "beepMislinja" sensor_t = "beep" sensor_q1 = "voltage" sensor_u1 = "mV" sensor_q2 = "signal" sensor_u2 = "dBm" sensor_q3 = "weight" sensor_u3 = "g" cluster_id = x.getClusterID(cluster) if cluster_id == None: x.createCluster(cluster) cluster_id = x.getClusterID(cluster) node_id = x.getNodeID(node) if node_id == None: x.createNode(node, cluster_id) node_id = x.getNodeID(node) sensor_id_v = x.getSensorID(node, sensor_t, sensor_q1) if sensor_id_v == None: x.createSensor(node_id, sensor_t, sensor_q1, sensor_u1) sensor_id_v = x.getSensorID(node, sensor_t, sensor_q1) sensor_id_s = x.getSensorID(node, sensor_t, sensor_q2) if sensor_id_s == None: x.createSensor(node_id, sensor_t, sensor_q2, sensor_u2)
if videk.serverOnline(): print "Videk server is online ..." else: print "Videk server is offline ..." sys.exit(1) pmc_file_name = "/tmp/pmc-data" spm_file_name = "/tmp/spm-data" videk.latitude = lat videk.longitude = lon cluster_id = videk.getClusterID(cluster) if cluster_id == None: videk.createCluster(cluster) cluster_id = videk.getClusterID(cluster) node_id_by_node_name = videk.getNode(node) node_id_by_node_machine_id = videk.getNodeByHardwareId(machine_id) node_model_update = {} if node_id_by_node_name == None and node_id_by_node_machine_id == None: videk.createNode(node, cluster_id) node_id = videk.getNodeID(node) videk.updateSingleNodeParam(node_id, "machine_id", machine_id) videk.addNodeExtraField(node, "MAC", mac) videk.addNodeExtraField(node, "Software", sw_version) node_model = videk.getNode(node) elif node_id_by_node_name == None and node_id_by_node_machine_id != None: node_model = videk.getNodeByHardwareId(machine_id)
#!/usr/bin/env python # encoding: utf-8 import subprocess import re import time import json import datetime from videk_rest_client import Videk x = Videk('TOKEN') x.createCluster('clusterName') cluster_id = x.getClusterID('clusterName') x.createNode('nodeName', cluster_id) node_id = x.getNodeID('nodeName') x.createSensor(node_id, 'sensorType', 'sensorQuantity', 'sensorUnit') sensor_id = x.getSensorID('nodeName', 'sensorType', 'sensorQuantity') measurement = '''{"latitude": 99.999999 , "longitude": 99.999999 ,"ts": "2014-07-24T15:14:30.850Z","value": 0 }''' while True: #Get CPU temperature sensors = subprocess.check_output("sensors") temperatures = { match[0]: float(match[1]) for match in re.findall("^(.*?)\:\s+\+?(.*?)°C", sensors, re.MULTILINE) } preparedData = [] data = json.loads(measurement)
#!/usr/bin/env python # encoding: utf-8 import subprocess import re import time import json import datetime from videk_rest_client import Videk x = Videk('TOKEN') x.createCluster('clusterName') cluster_id = x.getClusterID('clusterName') x.createNode('nodeName', cluster_id) node_id = x.getNodeID('nodeName') x.createSensor(node_id, 'sensorType', 'sensorQuantity', 'sensorUnit') sensor_id = x.getSensorID('nodeName', 'sensorType', 'sensorQuantity') measurement = '''{"latitude": 99.999999 , "longitude": 99.999999 ,"ts": "2014-07-24T15:14:30.850Z","value": 0 }''' while True: #Get CPU temperature sensors = subprocess.check_output("sensors") temperatures = {match[0]: float(match[1]) for match in re.findall("^(.*?)\:\s+\+?(.*?)°C", sensors, re.MULTILINE)} preparedData = [] data = json.loads(measurement) data['value'] = temperatures['Core 0'] data['ts'] = datetime.utcnow().isoformat() data['latitude'] = 11.111111