diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index dfc1ec1aa..b5c1f8c7f 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: allow remove last measure in device 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; diff --git a/lib/services/devices/deviceService.js b/lib/services/devices/deviceService.js index a31726071..457b91e4f 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; } } - + // Set polling and transport for autoprovisioned devices + if (!deviceData.transport && config.getConfig().defaultTransport) { + deviceData.transport = + configuration && configuration.transport + ? configuration.transport + : config.getConfig().defaultTransport; + } + if (deviceData.transport === 'HTTP') { + if (deviceData.endpoint) { + deviceData.polling = false; + } else { + deviceData.polling = !(configuration && configuration.endpoint); + } + } if (!deviceData.name) { let entityName = null; if (configuration && configuration.entityNameExp !== undefined && configuration.entityNameExp !== '') { @@ -363,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); }