2323 datefmt = '%Y-%m-%d %H:%M:%S' )
2424
2525# ThingsBoard REST API URL
26- url = "http://192.168.1.201:8380 "
26+ url = "http://127.0.0.1:8080 "
2727
2828# Default Tenant Administrator credentials
2929@@ -37,38 +37,36 @@ def main():
3737 # Auth with credentials
3838 rest_client .login (username = username , password = password )
3939
40- print (rest_client .save_device_attributes (DeviceId ('34416c10-bba7-11ef-9c05-3598fcc4571c' , 'DEVICE' ), 'SHARED_SCOPE' , {'temperature' : 45.0 }))
41-
4240 # Creating an Asset
43- # default_asset_profile_id = rest_client.get_default_asset_profile_info().id
44- # asset = Asset(name="Building 1", label="Building 1",
45- # asset_profile_id=default_asset_profile_id)
46- # asset = rest_client.save_asset(asset)
47- #
48- # logging.info("Asset was created:\n%r\n", asset)
49- #
50- # rest_client.process_devices_bulk_import()
51- #
52- # # Creating a Device
53- # # Also, you can use default Device Profile:
54- # # default_device_profile_id = rest_client.get_default_device_profile_info().id
55- # device_profile = DeviceProfile(name="Thermometer",
56- # type="DEFAULT",
57- # transport_type="DEFAULT",
58- # profile_data=DeviceProfileData(configuration={"type": "DEFAULT"},
59- # transport_configuration={"type": "DEFAULT"}))
60- # device_profile = rest_client.save_device_profile(device_profile)
61- # device = Device(name="Thermometer 1", label="Thermometer 1",
62- # device_profile_id=device_profile.id)
63- # device = rest_client.save_device(device)
64- #
65- # logging.info(" Device was created:\n%r\n", device)
66- #
67- # # Creating relations from device to asset
68- # relation = EntityRelation(_from=asset.id, to=device.id, type="Contains")
69- # rest_client.save_relation(relation)
70- #
71- # logging.info(" Relation was created:\n%r\n", relation)
41+ default_asset_profile_id = rest_client .get_default_asset_profile_info ().id
42+ asset = Asset (name = "Building 1" , label = "Building 1" ,
43+ asset_profile_id = default_asset_profile_id )
44+ asset = rest_client .save_asset (asset )
45+
46+ logging .info ("Asset was created:\n %r\n " , asset )
47+
48+ rest_client .process_devices_bulk_import ()
49+
50+ # Creating a Device
51+ # Also, you can use default Device Profile:
52+ # default_device_profile_id = rest_client.get_default_device_profile_info().id
53+ device_profile = DeviceProfile (name = "Thermometer" ,
54+ type = "DEFAULT" ,
55+ transport_type = "DEFAULT" ,
56+ profile_data = DeviceProfileData (configuration = {"type" : "DEFAULT" },
57+ transport_configuration = {"type" : "DEFAULT" }))
58+ device_profile = rest_client .save_device_profile (device_profile )
59+ device = Device (name = "Thermometer 1" , label = "Thermometer 1" ,
60+ device_profile_id = device_profile .id )
61+ device = rest_client .save_device (device )
62+
63+ logging .info (" Device was created:\n %r\n " , device )
64+
65+ # Creating relations from device to asset
66+ relation = EntityRelation (_from = asset .id , to = device .id , type = "Contains" )
67+ rest_client .save_relation (relation )
68+
69+ logging .info (" Relation was created:\n %r\n " , relation )
7270 except ApiException as e :
7371 logging .exception (e )
7472
0 commit comments