def testWriteData(self):
        nv = datanodesvalue()
        nv.set_name("Arm No")
        nv.set_path("armno")
        nv.set_dataType("double")
        nv.set_value(2.0)
        nv1 = datanodesvalue()
        nv1.set_name("Leg No")
        nv1.set_path("legno")
        nv1.set_dataType("double")
        nv1.set_value(2.0)

        d = self.c.writedata(self.deviceId, nv, nv1)
        self.assertIsNotNone(d)
        self.assertEqual(2, d.totalWritten)
        self.assertEqual(2, len(d.resultlist))
	def testWriteData(self):
		nv = datanodesvalue()
		nv.set_name("Arm No")
		nv.set_path("armno")
		nv.set_dataType("double")
		nv.set_value(2.0)
		nv1 = datanodesvalue()
		nv1.set_name("Leg No")
		nv1.set_path("legno")
		nv1.set_dataType("double")
		nv1.set_value(2.0)
		
		d = self.c.writedata(self.deviceId, nv, nv1)		
		self.assertIsNotNone(d)
		self.assertEqual(2, d.totalWritten)
		self.assertEqual(2, len(d.resultlist))
Beispiel #3
0
def send(counter, expression, random):
    nv = datanodesvalue()
    nv.set_name("Counter")
    nv.set_path("Counter")
    nv.set_dataType("double")
    nv.set_value(float(counter))

    nv1 = datanodesvalue()
    nv1.set_name("Expression")
    nv1.set_path("Expression")
    nv1.set_dataType("double")
    nv1.set_value(float(expression))

    nv2 = datanodesvalue()
    nv2.set_name("Random")
    nv2.set_path("Random")
    nv2.set_dataType("double")
    nv2.set_value(float(random))

    print(c.writedata(deviceId, nv, nv1, nv2))
def send_data_to_iot_ticket(value, value2):
    print("WRITE DEVICE DATANODES FUNTION.")
    listofvalues = []
    nv = datanodesvalue()
    nv.set_name("Humidity")  #needed for writing datanode
    nv.set_path("hum")
    nv.set_dataType("double")
    nv.set_unit("%")
    nv.set_value(value)  #needed for writing datanode
    nv1 = datanodesvalue()
    nv1.set_name("Temperature")  #needed for writing datanode
    nv1.set_path("temp")
    nv1.set_dataType("double")
    nv1.set_unit("C")
    nv1.set_value(value2)  #needed for writing datanode
    listofvalues.append(nv)
    listofvalues.append(nv1)
    print(c.writedata(deviceId, *listofvalues)
          )  # another way to make this would be c.writedata(deviceId, nv, nv1)
    print("END WRITE DEVICE DATANODES FUNCTION")
    print("-------------------------------------------------------\n")
class test(object):
    c = Client(baseurl, username, password)
    cr = criteria()
    cr.set_criterialist("age", "height", "weight", "hair color", "Eye Color",
                        "finger no", "Speakers (Logitech USB Headset H340)")
    nv = datanodesvalue()
    nv.set_name("Finger No")
    nv.set_path("fingerno")
    nv.set_dataType("double")

    def autowrite(self):
        threading.Timer(2, self.autowrite).start()
        self.nv.set_value(round(random.uniform(0.0, 100.0), 2))
        self.nv.set_timestamp(self.c.dttots(datetime.datetime.now()))
        self.c.writedata("6f8af5b13ae04c1aad2dcabb612ec028", self.nv)
        print("v: " + str(self.nv.get_value()) + "\nts: " +
              str(self.nv.get_timstamp()) + "\n")
print(c.movedevice(deviceId,"E0001")) # E0001=enterprise id of destination enterprise.
print("END MOVE DEVICE FUNCTION")
print("-------------------------------------------------------\n")
#read datanode demo
print("READ DEVICE DATANODES FUNTION.")
cr = criteria()
cr.set_criterialist("Latitude", "Longitude", "Finger No")
fd = "2016-03-22 17:22:00"
td = "2016-03-22 17:25:00"
print(c.readdata(deviceId, cr, fd, td))
print("END READ DEVICE DATANODES FUNCTION")
print("-------------------------------------------------------\n")
#write datanode demo
print("WRITE DEVICE DATANODES FUNTION.")
listofvalues=[]
nv = datanodesvalue()
nv.set_name("Arm No") #needed for writing datanode
nv.set_path("armno")
nv.set_dataType("double")
nv.set_value(2.0) #needed for writing datanode
nv1 = datanodesvalue()
nv1.set_name("Leg No") #needed for writing datanode
nv1.set_path("legno")
nv1.set_dataType("double")
nv1.set_value(2.0) #needed for writing datanode
listofvalues.append(nv)
listofvalues.append(nv1)
print(c.writedata(deviceId, *listofvalues)) # another way to make this would be c.writedata(deviceId, nv, nv1)
print("END WRITE DEVICE DATANODES FUNCTION")
print("-------------------------------------------------------\n")
Beispiel #7
0
    def write_to_iot_ticket(self, data, iot_id, result):

        timeStamp = time()

        rssi = data["gws"][0]
        float_rssi = float(rssi["rssi"])
        nv = datanodesvalue()
        nv.set_name("RSSI")
        nv.set_path(iot_id)
        nv.set_dataType("double")
        nv.set_value(float_rssi)
        nv.set_timestamp(timeStamp)

        gateway_delay = result['gatewaydelay']
        float_gvd = float(gateway_delay)
        nv1 = datanodesvalue()
        nv1.set_name("Gateway delay")
        nv1.set_path(iot_id)
        nv1.set_dataType("double")
        nv1.set_value(float_gvd)
        nv1.set_timestamp(timeStamp)

        network_delay = result['networkdelay']
        float_nvd = float(network_delay)
        nv2 = datanodesvalue()
        nv2.set_name("Network delay")
        nv2.set_path(iot_id)
        nv2.set_dataType("double")
        nv2.set_value(float_nvd)
        nv2.set_timestamp(timeStamp)

        per = result['per']
        float_per = float(per)
        nv3 = datanodesvalue()
        nv3.set_name("PER")
        nv3.set_path(iot_id)
        nv3.set_dataType("double")
        nv3.set_value(float_per)
        nv3.set_timestamp(timeStamp)

        interval = result['interval']
        float_interval = float(interval)
        nv4 = datanodesvalue()
        nv4.set_name("Measurement interval")
        nv4.set_path(iot_id)
        nv4.set_dataType("double")
        nv4.set_value(float_interval)
        nv4.set_timestamp(timeStamp)

        measinterval = result['measinterval']
        float_measinterval = float(measinterval)
        nv5 = datanodesvalue()
        nv5.set_name("Measured interval")
        nv5.set_path(iot_id)
        nv5.set_dataType("double")
        nv5.set_value(float_measinterval)
        nv5.set_timestamp(timeStamp)

        interval_ms = result['interval_ms']
        float_interval_ms = float(interval_ms)
        nv6 = datanodesvalue()
        nv6.set_name("Measurement interval (ms)")
        nv6.set_path(iot_id)
        nv6.set_dataType("double")
        nv6.set_value(float_interval_ms)
        nv6.set_timestamp(timeStamp)

        c = Client(self.baseurl, self.username, self.password)

        print(c.writedata(self.dev_iot_id, nv, nv1, nv2, nv3, nv4, nv5, nv6))
Beispiel #8
0
    def write_to_iot_ticket(self, data, iot_id, result):

        timeStamp = time()

        rssi = data["gws"][0]
        float_rssi = float(rssi["rssi"])
        nv = datanodesvalue()
        nv.set_name("RSSI")
        nv.set_path(iot_id)
        nv.set_dataType("double")
        nv.set_value(float_rssi)
        nv.set_timestamp(timeStamp)

        gateway_delay = result['gatewaydelay']
        float_gvd = float(gateway_delay)
        nv1 = datanodesvalue()
        nv1.set_name("Gateway delay")
        nv1.set_path(iot_id)
        nv1.set_dataType("double")
        nv1.set_value(float_gvd)

        nv1.set_timestamp(timeStamp)

        network_delay = result['networkdelay']
        float_nvd = float(network_delay)
        nv2 = datanodesvalue()
        nv2.set_name("Network delay")
        nv2.set_path(iot_id)
        nv2.set_dataType("double")
        nv2.set_value(float_nvd)
        nv2.set_timestamp(timeStamp)

        per = result['per']
        float_per = float(per)
        nv3 = datanodesvalue()
        nv3.set_name("PER")
        nv3.set_path(iot_id)
        nv3.set_dataType("double")
        nv3.set_value(float_per)
        nv3.set_timestamp(timeStamp)

        interval = result['interval']
        float_interval = float(interval)
        nv4 = datanodesvalue()
        nv4.set_name("Measurement interval")
        nv4.set_path(iot_id)
        nv4.set_dataType("double")
        nv4.set_value(float_interval)
        nv4.set_timestamp(timeStamp)

        measinterval = result['measinterval']
        float_measinterval = float(measinterval)
        nv5 = datanodesvalue()
        nv5.set_name("Measured interval")
        nv5.set_path(iot_id)
        nv5.set_dataType("double")
        nv5.set_value(float_measinterval)
        nv5.set_timestamp(timeStamp)

        interval_ms = result['interval_ms']
        float_interval_ms = float(interval_ms)
        nv6 = datanodesvalue()
        nv6.set_name("Measurement interval (ms)")
        nv6.set_path(iot_id)
        nv6.set_dataType("double")
        nv6.set_value(float_interval_ms)
        nv6.set_timestamp(timeStamp)

        snr = data["gws"][0]
        float_snr = float(snr["snr"])
        nv7 = datanodesvalue()
        nv7.set_name("snr")
        nv7.set_path(iot_id)
        nv7.set_dataType("double")
        nv7.set_value(float_snr)
        nv7.set_timestamp(timeStamp)

        reference_delay = result['calculated_delay']
        float_reference_delay = float(reference_delay)
        nv8 = datanodesvalue()
        nv8.set_name("Reference delay")
        nv8.set_path(iot_id)
        nv8.set_dataType("double")
        nv8.set_value(float_reference_delay)
        nv8.set_timestamp(timeStamp)

        time_off_calculated = result['calculated_minimum_off_period']
        float_time_off_calculated = float(time_off_calculated)
        nv9 = datanodesvalue()
        nv9.set_name("Calculated minimum time off delay")
        nv9.set_path(iot_id)
        nv9.set_dataType("double")
        nv9.set_value(float_time_off_calculated)
        nv9.set_timestamp(timeStamp)

        time_off_calculated_from_meas = result[
            'calculated_minimum_off_period_from_measured_delay']
        float_time_off_calculated_from_meas = float(
            time_off_calculated_from_meas)
        nv10 = datanodesvalue()
        nv10.set_name(
            "Calculated minimum time off delay from measurement result")
        nv10.set_path(iot_id)
        nv10.set_dataType("double")
        nv10.set_value(float_time_off_calculated_from_meas)
        nv10.set_timestamp(timeStamp)

        c = Client(self.baseurl, self.username, self.password)

        print(
            c.writedata(self.dev_iot_id, nv, nv1, nv2, nv3, nv4, nv5, nv6, nv7,
                        nv8, nv9, nv10))
from iotticket.client import Client

data = json.load(open(sys.argv[1]))
username = data["username"]
password = data["password"]
deviceId = data["deviceId"]
baseurl = data["baseurl"]

#create client object
c = Client(baseurl, username, password)
tempfile = open("/home/pi/IoT-ticket/" + sys.argv[2] + ".data")
text = tempfile.read()
tempfile.close()
temperature = float(text)

nv = datanodesvalue()
nv.set_name(sys.argv[2])
nv.set_path("TelldusNetwork")
nv.set_dataType("double")

nv.set_unit("deg")

#set the value of the node with the temperature value
nv.set_value(temperature)
#set the timestamp as now
nv.set_timestamp(c.dttots(datetime.datetime.now()))
#call writedata function
c.writedata(deviceId, nv)
print("v: " + str(nv.get_value()) + "\nts: " + str(nv.get_timstamp()) + "\n")
#the program will run every 2 seconds
Beispiel #10
0
    deviceId = data["deviceId"]
baseurl = data["baseurl"]
c = Client(baseurl, username, password)
if(c!="404 URL NOT FOUND!!!"):
    if deviceId == "": # It's not registered yet, it need to be regitered.
        d = device()
        d.set_name("Register Test")
        d.set_manufacturer("Dell")
        d.set_type("PC")
        d.set_description("More register")
        registeredDevice = c.registerdevice(d)
        data["deviceId"] = registeredDevice.deviceId
        deviceId = registeredDevice.deviceId
        json.dump(data,open(sys.argv[1], "w"))
    # Creating the data tags and set the default values
    nv = datanodesvalue()
    nv.set_name("Processor")
    nv.set_path("fedora/percentVal")
    nv.set_dataType("double")
    killOrdernv = datanodesvalue()
    killOrdernv.set_name("orderToKill")
    killOrdernv.set_path("fedora/kill")
    killOrdernv.set_dataType("boolean")
    killOrdernv.set_timestamp(c.dttots(datetime.datetime.now()))
    killOrdernv.set_value(False)
    c.writedata(deviceId, killOrdernv)
    # It's used configure which variiables will be read from the server
    cr = criteria()
    cr.set_criterialist("orderToKill") # Variable that says that the process need to be killed
    while 1:
        # Get cpu percent
    print("REGISTER DEVICE FUNTION.")
    print(c.registerdevice(d))
    print("END REGISTER DEVICE FUNCTION")
    print("-------------------------------------------------------\n")
    #read datanode demo
    print("READ DEVICE DATANODES FUNTION.")
    cr = criteria()
    cr.set_criterialist("Latitude", "Longitude", "Finger No")
    fd = "2016-03-22 17:22:00"
    td = "2016-03-22 17:25:00"
    print(c.readdata(deviceId, cr, fd, td))
    print("END READ DEVICE DATANODES FUNCTION")
    print("-------------------------------------------------------\n")
    #write datanode demo
    print("WRITE DEVICE DATANODES FUNTION.")
    nv = datanodesvalue()
    nv.set_name("Arm No")
    nv.set_path("armno")
    nv.set_dataType("double")
    nv.set_value(2.0)
    nv1 = datanodesvalue()
    nv1.set_name("Leg No")
    nv1.set_path("legno")
    nv1.set_dataType("double")
    nv1.set_value(2.0)
    print(c.writedata(deviceId, nv, nv1))
    print("END WRITE DEVICE DATANODES FUNCTION")
    print("-------------------------------------------------------\n")
else:
    print(c)
baseurl = data["baseurl"]

while 1:
	#create client object
	c = Client(baseurl,username,password)	
	#read the content of the sensor
	tempfile = open("/sys/bus/w1/devices/28-000006b19b27/w1_slave")
	text = tempfile.read()
	tempfile.close()
	#split to get the second line temperature data
	tempdata = text.split("\n")[1].split(" ")[9]
	#get the actual number of the temperature
	temperature = float(tempdata[2:])
	#divided by 1000 to get real temperature degree
	temperature = temperature/1000
	#create datanodesvalue object and call the set functions
	nv = datanodesvalue()
	nv.set_name("Sensor temperature")
	nv.set_path("tempVal")
	nv.set_dataType("double")
	nv.set_unit("deg")
	#set the value of the node with the temperature value
	nv.set_value(temperature)
	#set the timestamp as now
	nv.set_timestamp(c.dttots(datetime.datetime.now()))
	#call writedata function
	c.writedata(deviceId, nv)
	print("v: " + str(nv.get_value()) +"\nts: " + str(nv.get_timstamp()) + "\n")
	#the program will run every 2 seconds
	time.sleep(2)