From ea16a2c57634ffa402ce509c256efc7db023670d Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 21 Nov 2024 17:10:49 +0100 Subject: [PATCH] add and check store last measure config --- config.js | 3 ++- lib/commonConfig.js | 8 +++++++- lib/services/ngsi/ngsiService.js | 13 +++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/config.js b/config.js index 88b4e610d..d9ad2e7a4 100644 --- a/config.js +++ b/config.js @@ -77,7 +77,8 @@ var config = { providerUrl: 'http://192.168.56.1:4041', deviceRegistrationDuration: 'P1M', defaultType: 'Thing', - expressLimit: '1Mb' + expressLimit: '1Mb', + storeLastMeasure: false }; module.exports = config; diff --git a/lib/commonConfig.js b/lib/commonConfig.js index d16908615..3f166abdd 100644 --- a/lib/commonConfig.js +++ b/lib/commonConfig.js @@ -157,7 +157,8 @@ function processEnvironmentVariables() { 'IOTA_FALLBACK_PATH', 'IOTA_LD_SUPPORT_NULL', 'IOTA_LD_SUPPORT_DATASET_ID', - 'IOTA_EXPRESS_LIMIT' + 'IOTA_EXPRESS_LIMIT', + 'IOTA_STORE_LAST_MEASURE' ]; const iotamVariables = [ 'IOTA_IOTAM_URL', @@ -474,6 +475,11 @@ function processEnvironmentVariables() { } else { config.expressLimit = config.expressLimit ? config.expressLimit : '1mb'; } + if (process.env.IOTA_STORE_LAST_MEASURE) { + config.storeLastMeasure = process.env.IOTA_STORE_LAST_MEASURE === 'true'; + } else { + config.storeLastMeasure = config.storeLastMeasure === true; + } } function setConfig(newConfig) { diff --git a/lib/services/ngsi/ngsiService.js b/lib/services/ngsi/ngsiService.js index bf9b2f064..2b233de87 100644 --- a/lib/services/ngsi/ngsiService.js +++ b/lib/services/ngsi/ngsiService.js @@ -69,10 +69,15 @@ function init() { * @param {String} token User token to identify against the PEP Proxies (optional). */ function sendUpdateValue(entityName, attributes, typeInformation, token, callback) { - deviceService.storeLastMeasure(attributes, typeInformation, function () { - const newCallback = statsRegistry.withStats('updateEntityRequestsOk', 'updateEntityRequestsError', callback); - return entityHandler.sendUpdateValue(entityName, attributes, typeInformation, token, newCallback); - }); + // check config about store last measure + const newCallback = statsRegistry.withStats('updateEntityRequestsOk', 'updateEntityRequestsError', callback); + if (config.getConfig().storeLastMeasure) { + deviceService.storeLastMeasure(attributes, typeInformation, function () { + return entityHandler.sendUpdateValue(entityName, attributes, typeInformation, token, newCallback); + }); + } else { + entityHandler.sendUpdateValue(entityName, attributes, typeInformation, token, newCallback); + } } /**