diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index f5f0d296..9169e9e9 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1,2 @@ -- Fix: ensure device apikey in already provisioned device (iota-node-lib#1430) +- Fix: try to use apikey from measure/group to find, update and remove device in first attempt (iota-node-lib#1426) +- Fix: ensure device apikey in already provisioned device (iota-node-lib#1430, iota-node-lib#1435) diff --git a/lib/iotaUtils.js b/lib/iotaUtils.js index 18d24427..e3ccc430 100644 --- a/lib/iotaUtils.js +++ b/lib/iotaUtils.js @@ -63,8 +63,8 @@ function getEffectiveApiKey(service, subservice, device, callback) { } } -function findOrCreate(deviceId, transport, group, callback) { - iotAgentLib.getDeviceSilently(deviceId, group.service, group.subservice, function (error, device) { +function findOrCreate(deviceId, transport, apikey, group, callback) { + iotAgentLib.getDeviceSilently(deviceId, apikey, group.service, group.subservice, function (error, device) { if (!error && device) { if ( (!('apikey' in device) || device.apikey === undefined) && @@ -75,11 +75,12 @@ function findOrCreate(deviceId, transport, group, callback) { .getLogger() .info(context, 'Update provisioned device %j with measure/group apikey %j', device, group.apikey); device.apikey = group.apikey; // group apikey is the same of current measure apikey - iotAgentLib.updateRegister(device, function (error, device) { + iotAgentLib.updateDevice(device, function (error) { callback(error, device, group); }); + } else { + callback(null, device, group); } - callback(null, device, group); } else if (error.name === 'DEVICE_NOT_FOUND') { const newDevice = { id: deviceId, @@ -232,7 +233,7 @@ function retrieveDevice(deviceId, apiKey, transport, callback) { async.waterfall( [ apply(iotAgentLib.getConfigurationSilently, config.getConfig().iota.defaultResource, apiKey), - apply(findOrCreate, deviceId, transport), + apply(findOrCreate, deviceId, transport, apiKey), // group.apikey and apikey are the same mergeDeviceWithConfiguration ], callback