Given the need to move a set of devices to a new tenant in the same Chirpstack instance, the data relating to the OTAA and session keys have been saved.
Subsequently, using the Chirpstack API, the devices have been registered in the new application following the following steps:
- Create the device
- Create the keys
- Activate it with the existing session keys
def create_device(server, token, device, keys, s_keys):
channel = grpc.insecure_channel(server)
client = api.DeviceServiceStub(channel)
auth_token = [("authorization", f"Bearer {token}")]
req = api.CreateDeviceRequest()
req.device.dev_eui = device['dev_eui']
req.device.name = device['name']
req.device.join_eui = device['join_eui']
req.device.application_id = device['application_id']
req.device.device_profile_id = device['device_profile_id']
req.device.skip_fcnt_check = device['skip_fcnt_check']
req.device.is_disabled = device['is_disabled']
req_keys = api.CreateDeviceKeysRequest()
req_keys.device_keys.dev_eui = device['dev_eui']
req_keys.device_keys.nwk_key = keys['nwk_key']
req_keys.device_keys.app_key = keys['app_key']
req_activate = api.ActivateDeviceRequest()
req_activate.device_activation.dev_eui = device['dev_eui']
req_activate.device_activation.dev_addr = s_keys['dev_addr']
req_activate.device_activation.app_s_key = s_keys['app_s_key']
req_activate.device_activation.nwk_s_enc_key = s_keys['nwk_s_key']
req_activate.device_activation.s_nwk_s_int_key = s_keys['nwk_s_key']
req_activate.device_activation.f_nwk_s_int_key = s_keys['nwk_s_key']
try:
resp = client.Create(req, metadata=auth_token)
resp_keys = client.CreateKeys(req_keys, metadata=auth_token)
resp_s_keys = client.Activate(req_activate, metadata=auth_token)
return {'device': resp, 'keys': resp_keys, 's_keys': resp_s_keys}
except grpc.RpcError as exc:
print(exc)
All devices successfully register and session keys are visible in the Chirpstack UI.
However, the last_seen field is null and new frames are not reaching the network server.