def testRegisterDevice(self):
		devicename = "Johan"
		manufacturer = "Wapice"
		type = "employee"
		d = device()
		d.set_name(devicename)
		d.set_manufacturer(manufacturer)
		d.set_type(type)
		d.set_attributes(deviceattribute("py","thon"), deviceattribute("iot","ticket"), deviceattribute("a","b"))
		
		d = self.c.registerdevice(d)
		self.assertIsInstance(d, device)
		self.assertIsNotNone(d)
		self.assertIsNotNone(d.get_name())
		self.assertIsNotNone(d.get_createdAt())
		self.assertIsNotNone(d.get_manufacturer())
		self.assertIsNotNone(d.get_deviceId())
		self.assertIsNotNone(d.get_href())
		self.assertEqual(3, len(d.get_attributes()))
    def testRegisterDevice(self):
        devicename = "Johan"
        manufacturer = "Wapice"
        type = "employee"
        d = device()
        d.set_name(devicename)
        d.set_manufacturer(manufacturer)
        d.set_type(type)
        d.set_attributes(deviceattribute("py", "thon"),
                         deviceattribute("iot", "ticket"),
                         deviceattribute("a", "b"))

        d = self.c.registerdevice(d)
        self.assertIsInstance(d, device)
        self.assertIsNotNone(d)
        self.assertIsNotNone(d.get_name())
        self.assertIsNotNone(d.get_createdAt())
        self.assertIsNotNone(d.get_manufacturer())
        self.assertIsNotNone(d.get_deviceId())
        self.assertIsNotNone(d.get_href())
        self.assertEqual(3, len(d.get_attributes()))
示例#3
0
    def create_device(self):

        d = device()
        d.set_name("Lorawan end node")
        d.set_manufacturer("Wapice")
        d.set_type("sensor")
        d.set_description("LoRaWAN test network end node")
        d.set_attributes(deviceattribute("packet", "counter"))

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

        c.registerdevice(d)
        return c
print("Get all quota:\n" , c.getallquota())
print("END GET ALL QUOTA FUNCTION")
print("-------------------------------------------------------\n")
#get device quota demo
print("GET DEVICE QUOTA FUNTION.")
print(c.getdevicequota(deviceId))
print("END GET DEVICE QUOTA FUNCTION")
print("-------------------------------------------------------\n")
#create a device
d = device()
d.set_name("Johan") #needed for register
d.set_manufacturer("Wapice") #needed for register
d.set_type("employee")
d.set_description("Im trainee")
d.set_enterpriseId("E0000") #if enterprise id is not given, iotticket use default enterprise id.
d.set_attributes(deviceattribute("a","b"), deviceattribute("c","d"), deviceattribute("key","value"))
#register device demo
print("REGISTER DEVICE FUNTION.")
print(c.registerdevice(d))
print("END REGISTER DEVICE FUNCTION")
print("-------------------------------------------------------\n")
#move device demo
print("MOVE DEVICE FUNTION.")
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"
data = json.load(open(sys.argv[1]))
username = data["username"]
password = data["password"]
baseurl = data["baseurl"]

#create client object
c = Client(baseurl, username, password)
if (c != "404 URL NOT FOUND!!!"):
    #create device object and call set functions
    d = device()
    d.set_name("Raspi Temperature Sensor")
    d.set_manufacturer("Wapice")
    d.set_type("Sensor")
    d.set_description("Temperature sensor")
    d.set_attributes(deviceattribute("Sensor model", "DS18B20"))
    #call registerdevice function
    resp = c.registerdevice(d)
    #build the new json file for writing data process
    data = {
        "username": username,
        "password": password,
        "deviceId": resp.get_deviceId(),
        "baseurl": baseurl
    }
    with open("write.json", "w") as outfile:
        json.dump(data, outfile, sort_keys=True, indent=4)
    print(resp.get_deviceId())

else:
    print(c)
示例#6
0
 print("GET ALL QUOTA FUNTION.")
 print("Get all quota:\n", c.getallquota())
 print("END GET ALL QUOTA FUNCTION")
 print("-------------------------------------------------------\n")
 #get device quota demo
 print("GET DEVICE QUOTA FUNTION.")
 print(c.getdevicequota(deviceId))
 print("END GET DEVICE QUOTA FUNCTION")
 print("-------------------------------------------------------\n")
 #create a device
 d = device()
 d.set_name("Johan")
 d.set_manufacturer("Wapice")
 d.set_type("employee")
 d.set_description("Im trainee")
 d.set_attributes(deviceattribute("a", "b"), deviceattribute("c", "d"),
                  deviceattribute("key", "value"))
 #register device demo
 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")
from iotticket.models import device
from iotticket.models import criteria
from iotticket.models import deviceattribute
from iotticket.models import datanodesvalue
from iotticket.client import Client

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

#create client object
c= Client(baseurl,username,password)

#create device object and call set functions
d = device()
d.set_name("Raspi Temperature Sensor")
d.set_manufacturer("Wapice")
d.set_type("Sensor")
d.set_description("Temperature sensor")
d.set_attributes(deviceattribute("Sensor model","DS18B20"))
d.set_enterpriseId("E0000") #if enterprise id is not given, iotticket use default enterprise id.
#call registerdevice function
resp = c.registerdevice(d)
#build the new json file for writing data process
data={"username":username,"password":password,"deviceId":resp.get_deviceId(),"baseurl":baseurl}
with open("write.json","w") as outfile:
	json.dump(data, outfile, sort_keys=True, indent=4)
print(resp.get_deviceId())