Skip to content

Commit

Permalink
Merge pull request #1683 from telefonicaid/fix/set_polling_for_autopr…
Browse files Browse the repository at this point in the history
…ovision_devices

set polling for autoprovisioned devices
  • Loading branch information
fgalan authored Jan 20, 2025
2 parents 90c33a7 + 494aabf commit 6088e84
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/commonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 20 additions & 1 deletion lib/services/devices/deviceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 !== '') {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 6088e84

Please sign in to comment.