So I’m experimenting with the python sdk:
https://www.thethingsnetwork.org/docs/applications/python/api-reference.html
I have MQTTClient working OK, ApplicationClient, I’ve got as far as querying an existing device which is working fine.
I am struggling with creating/registering a new device though. Using the register_device function:
https://www.thethingsnetwork.org/docs/applications/python/api-reference.html#register_device
It tells me to supply a dictionary containing device information as per this format:
https://www.thethingsnetwork.org/docs/applications/python/api-reference.html#deviceobject
I’m unclear on which attributes are required and which are optional though, I’ve tried a few combinations such as this:
this_device = {
"app_id": self.app_id,
"dev_id": device_id,
"lorawan_device": {
"app_eui": self.app_eui.encode('utf-8'),
"dev_eui": dev_eui.encode('utf-8'),
"app_key": self.app_key.encode('utf-8'),
"disable_f_cnt_check": True,
}
Tried the EUIs as plain strings, encoding them to bytestrings etc…
I just get:
'Error when updating the', ' device: INVALID_ARGUMENT'
Back through the API.
Reading through the SDK source on github, I found an example usage of register_device which passes this dictionary:
devicetest = {
"description": "Description",
"appEui": "0011223344556677",
"devEui": "9988776655443322",
"devAddr": "11223344",
"nwkSKey": binascii.b2a_hex(os.urandom(16)).upper(),
"appSKey": binascii.b2a_hex(os.urandom(16)).upper(),
"appKey": binascii.b2a_hex(os.urandom(16)).upper(),
"fCntUp": 10,
"fCntDown": 11,
"latitude": 100,
"longitude": 200,
"altitude": 300,
"attributes": {
"foo": "bar",
},
"disableFCntCheck": True,
"uses32BitFCnt": True,
}
Which seems very different to the API documentation but also doesn’t work for me (same error message back from the API).
Does anyone have a working example of the format of the device dictionary to use?