Esempio n. 1
0
#!/usr/bin/env python

import sys
import time
import json
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)
Esempio n. 2
0
    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)
Esempio n. 3
0
#!/usr/bin/env python

import sys
import time
import json
from datetime import datetime
from videk_rest_client import Videk
from beep import Beep

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)
Esempio n. 4
0
#!/usr/bin/env python

import sys
import json
import time
import socket
import zerorpc
import os.path
from datetime import datetime
from videk_rest_client import Videk

import logging
logging.basicConfig()

videk = Videk("https://videk.ijs.si", "4PN8CBMKS3v9mBSmDgEPLeReUG5VWwsa")
node = socket.gethostname()
cluster = node[:node.rfind("-")]
lat = 46.042767
lon = 14.487632
machine_id = open('/etc/machine-id').readline().strip()
mac = open('/sys/class/net/eth0/address').read().strip()
sw_version = "v2.1"


def uploadSensors(node_id, sensor_type, sensors):
    for sensor in sensors:
        sensor_id = videk.getSensorID(node, sensor_type, sensor['name'])
        if sensor_id == None:
            videk.createSensor(node_id, sensor_type, sensor['name'],
                               sensor['unit'])
            sensor_id = videk.getSensorID(node, sensor_type, sensor['name'])
Esempio n. 5
0
#!/usr/bin/env python

import sys
import time
import json
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)
Esempio n. 6
0
#!/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)
Esempio n. 7
0
#!/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
Esempio n. 8
0
    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)