Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
iotAgentLib.getDevice(deviceId, deviceObject.service, deviceObject.subservice, function (error, device) {
if (error) {
errorMessage = 'Error getting IoTA device object';
winston.error(errorMessage, JSON.stringify(error));
} else if (device) {
winston.info('IOTA provisioned devices:', JSON.stringify(device));
var ngsiMessage = dataTranslation.toNgsi(message, device);
if (ngsiMessage && ngsiMessage instanceof Array && ngsiMessage.length > 0) {
iotAgentLib.update(device.name, device.type, '', ngsiMessage, device, function (iotaError) {
if (iotaError) {
errorMessage = 'Couldn\'t send the updated values to the Context Broker due to an error:';
winston.error(errorMessage, JSON.stringify(iotaError));
} else {
winston.info('Observations sent to CB successfully for device ', deviceId);
}
});
} else {
errorMessage = 'Could not cast message to NGSI';
winston.error(errorMessage);
}
} else {
errorMessage = 'Couldn\'t find device data for DeviceId ' + deviceId;
winston.error(errorMessage);
}
});