From 9c093fac3f96ce9bc17b580803da03f37a7381f8 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 16 Jan 2025 14:59:09 +0100 Subject: [PATCH 1/5] set polling for autoprovisioned devices --- lib/services/devices/deviceService.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/services/devices/deviceService.js b/lib/services/devices/deviceService.js index a31726071..174cd659d 100644 --- a/lib/services/devices/deviceService.js +++ b/lib/services/devices/deviceService.js @@ -283,7 +283,20 @@ function registerDevice(deviceObj, callback) { deviceData.ngsiVersion = configuration.ngsiVersion; } } - + // polling for autoprovision? + if (!deviceData.transport && config.getConfig().defaultTransport) { + device.transport = + configuration && configuration.transport + ? configuration.transport + : config.getConfig().defaultTransport; + } + if (device.transport === 'HTTP') { + if (device.endpoint) { + device.polling = false; + } else { + device.polling = !(group && group.endpoint); + } + } if (!deviceData.name) { let entityName = null; if (configuration && configuration.entityNameExp !== undefined && configuration.entityNameExp !== '') { From 1243197ab7118a68eae7268319333c01a9844cc1 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 16 Jan 2025 15:19:16 +0100 Subject: [PATCH 2/5] fix device obj --- lib/services/devices/deviceService.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/services/devices/deviceService.js b/lib/services/devices/deviceService.js index 174cd659d..a2eea82c9 100644 --- a/lib/services/devices/deviceService.js +++ b/lib/services/devices/deviceService.js @@ -285,16 +285,16 @@ function registerDevice(deviceObj, callback) { } // polling for autoprovision? if (!deviceData.transport && config.getConfig().defaultTransport) { - device.transport = + deviceData.transport = configuration && configuration.transport ? configuration.transport : config.getConfig().defaultTransport; } - if (device.transport === 'HTTP') { - if (device.endpoint) { - device.polling = false; + if (deviceData.transport === 'HTTP') { + if (deviceData.endpoint) { + deviceData.polling = false; } else { - device.polling = !(group && group.endpoint); + deviceData.polling = !(configuration && configuration.endpoint); } } if (!deviceData.name) { From 4845e03a1ed0f5f57b6db2038f2b2d2b020b53d8 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 16 Jan 2025 16:23:40 +0100 Subject: [PATCH 3/5] read defaultTransport --- lib/commonConfig.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/commonConfig.js b/lib/commonConfig.js index 13ce45304..721995094 100644 --- a/lib/commonConfig.js +++ b/lib/commonConfig.js @@ -352,6 +352,11 @@ function processEnvironmentVariables() { config.defaultResource = process.env.IOTA_DEFAULT_RESOURCE; } + // Default transport + if (process.env.IOTA_DEFAULT_TRANSPORT !== undefined) { + config.defaultTransport = process.env.IOTA_DEFAULT_TRANSPORT; + } + // Default explicitAttrs if (process.env.IOTA_EXPLICIT_ATTRS !== undefined) { config.explicitAttrs = process.env.IOTA_EXPLICIT_ATTRS; From 8883366739c0da682138f5c128e078b22215f195 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 16 Jan 2025 16:45:20 +0100 Subject: [PATCH 4/5] store polling and transport when autoprovisioned devices --- lib/services/devices/deviceService.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/services/devices/deviceService.js b/lib/services/devices/deviceService.js index a2eea82c9..82cf1e14e 100644 --- a/lib/services/devices/deviceService.js +++ b/lib/services/devices/deviceService.js @@ -283,7 +283,7 @@ function registerDevice(deviceObj, callback) { deviceData.ngsiVersion = configuration.ngsiVersion; } } - // polling for autoprovision? + // polling and transport for autoprovisioned devices if (!deviceData.transport && config.getConfig().defaultTransport) { deviceData.transport = configuration && configuration.transport @@ -376,6 +376,12 @@ function registerDevice(deviceObj, callback) { if ('apikey' in deviceData && deviceData.apikey !== undefined) { deviceObj.apikey = deviceData.apikey; } + if ('transport' in deviceData && deviceData.transport !== undefined) { + deviceObj.transport = deviceData.transport; + } + if ('polling' in deviceData && deviceData.polling !== undefined) { + deviceObj.polling = deviceData.polling; + } logger.debug(context, 'Storing device :\n%s', JSON.stringify(deviceObj, null, 4)); config.getRegistry().store(deviceObj, callback); } From b937f4d5984f04fec16822432877ef79fe6e1738 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Fri, 17 Jan 2025 10:27:12 +0100 Subject: [PATCH 5/5] update CNR --- CHANGES_NEXT_RELEASE | 1 + lib/services/devices/deviceService.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 9932dbfa9..a9646510b 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,3 +1,4 @@ +- Fix: set polling and transport for autoprovisioned devices - Add: option to force to use CB flow control with new API field useCBflowControl at group and device device level (#1420) - Add: useCBflowControl config setting (IOTA_CB_FLOW_CONTROL env var) to set CB flow control behaviour at instance level (#1420) - Add: store last measure in device (by id, apikey, service and subservice) and new API field storeLastMeasure at group and device levels (#1669) diff --git a/lib/services/devices/deviceService.js b/lib/services/devices/deviceService.js index 82cf1e14e..457b91e4f 100644 --- a/lib/services/devices/deviceService.js +++ b/lib/services/devices/deviceService.js @@ -283,7 +283,7 @@ function registerDevice(deviceObj, callback) { deviceData.ngsiVersion = configuration.ngsiVersion; } } - // polling and transport for autoprovisioned devices + // Set polling and transport for autoprovisioned devices if (!deviceData.transport && config.getConfig().defaultTransport) { deviceData.transport = configuration && configuration.transport