def create(self, activate=False): device = iotkitclient.Device(acct) js = device.create(info, activate) # if activate: # code = acct.renew_activation_code() # device.activate(code) return device
def setUpClass(cls): global iot, acct iot = iotkitclient.Client(host=hostname, proxies=proxies) iot.login(username, password) acct = iotkitclient.Account(iot) acct.get_account(account_name) while True: try: device = iotkitclient.Device(acct, deviceid) print "Deleting ", deviceid device.delete() except: break
def test_create_device(self): device = iotkitclient.Device(acct) info = { "deviceId": deviceid, "gatewayId": deviceid, "name": "Device #1", "tags": ["US", "California", "Sacramento"], "loc": [45.5434085, -122.654422, 124.3], "attributes": { "vendor": "intel", "platform": "x86", "os": "linux" } } js = device.create(info) self.assertEqual(js["deviceId"], deviceid) self.assertEqual(js["status"], "created")
def test_list_all_devices(self): device = iotkitclient.Device(acct) devlist = device.list_account_devices() self.assertTrue(devlist)
def bulkdelete(self): for i in (range(4)): device = iotkitclient.Device(acct) name = deviceid + str(i) js = device.delete()
def bulkcreate(self): for i in (range(4)): device = iotkitclient.Device(acct) info["deviceId"] = deviceid + str(i) js = device.create(info)
def delete(self, name): device = iotkitclient.Device(acct, name) js = device.delete()
print "Connecting to %s ..." % config.hostname iot = iotkitclient.Connect(host=config.hostname, proxies=config.proxies) iot.login(config.username, config.password) print "Connected. User ID: %s ..." % iot.user_id # Link to a specific IoT Analytics account acct = iotkitclient.Account(iot) try: acct.get_account(config.account_name) except: acct.create_account(config.account_name) iot.reinit(config.username, config.password) print "Using Account: %s ..." % config.account_name # Link to a specific device in the account device = iotkitclient.Device(acct) device_id = iot.user_id + "_01" try: device.get_device(device_id) except: device_info = { "deviceId": device_id, "gatewayId": device_id, "name": "Device #1" } device.create_device(device_info) act_code = acct.renew_activation_code() device.activate_new_device(act_code) device.save_config("device.json", True) device.load_config("device.json")
import time # Connect to IoT Analytics site and authenticate iot = iotkitclient.Connect(host=config.hostname, proxies=config.proxies) iot.login(config.username, config.password) # Create IoT Analytics account instance acct = iotkitclient.Account(iot) try: # Check if account exists acct.get_account(config.account_name) except Exception, err: raise RuntimeError("Unable to find account %s" % str(err)) device_id = iot.user_id + "_01" device = iotkitclient.Device(acct, device_id) comp = iotkitclient.Component(device) comp.get_component(config.component_name) t0 = 0 t1 = None devices = [device_id] components = [comp.id] data = acct.search_data(t0, t1, devices, components, csv=False) print "\nSimple query..." iotkitclient.prettyprint(data) data = acct.search_data(t0, t1, devices, components, csv=True) print "\nSimple query (CSV format)..." iotkitclient.prettyprint(data)