Failed to get correct respond on GetDeviceKeysRequest() with chirpstack-api in Python

When I do a GetDeviceKeysRequest() I get the same result as GetDeviceRequest(). Is there somethin I mis or is the there something in the library pointing to wrong location? The library version is 4.6.0

Here the basic code which I use:

from chirpstack_api import api as chirpstack

channel = grpc.insecure_channel(chirpstack_server)
auth_token = [(“authorization”, “Bearer %s” % chirpstack_token)]
client = chirpstack.DeviceServiceStub(channel)

req = chirpstack.GetDeviceKeysRequest()
req.dev_eui = dev_eui
resp = client.Get(req, metadata=auth_token)

Currently it gives the following output which is exactly the same as for GetDeviceRequest() while I expect to get the keys from the device:

device {
dev_eui: “1234567890123456”
name: “eui-1234567890123456”
description: “description”
application_id: “d432ba9d-8093-48af-871d-607b6c6247f7”
device_profile_id: “ebd486b2-5edc-40a6-b413-3c8867a7a927”
join_eui: “9876543210987654”
created_at {
seconds: 1702985568
nanos: 631758000
updated_at {
seconds: 1707688422
nanos: 204145000
last_seen_at {
seconds: 1707820563
nanos: 509398000
device_status {
margin: 10
battery_level: 45.27

You are calling the wrong function. It should be GetKeys() not Get()

Here is my getKeys function.

def getDeviceKeys(client,token,dev_eui):
  print("Retrieving keys from device with EUI: " + dev_eui)
  # Define the API key meta-data.
  auth_token = [("authorization", "Bearer %s" % token)]
    # Construct request.
    req = api.GetDeviceMetricsRequest()
    req.dev_eui = dev_eui

    resp = client.GetKeys(req, metadata=auth_token)
    return resp
  except grpc.RpcError as e:
    print('Ensure server URL is correct, API token is valid, devEUI is correct.')

Thnx for your tip to get the key. But I find it strange. It does not matter which existing function you call with the req as long I use the client.GetKeys(…) I get always the same output. Also not exactly as I expect but at least the info is there.

device_keys {
dev_eui: “1234567890123456”
nwk_key: “a6843729fcb27ae3a23e276c9de0549b”
app_key: “00000000000000000000000000000000”

Here the appKey is placed in the variable nwk_key and the app_key are only zero’s
It looks like it is a mix from variable names in my first impression as networkSessoinKey and applicationSessionKey.

For now I can request my information, hope in the future the functions are more clearly and consistent.

To my knowledge the different request types are only objects holding the relevant information for that API call. Since Get() and GetKeys() both only take the devEUI the requests are in function the same thing.

As for the names being switched it says this in the API documentation:

1 Like

Thnx for your explanation.

1 Like