Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set polling for autoprovisioned devices #1683

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: store last measure in device (by id, apikey, service and subservice) and new API field storeLastMeasure at group and device levels (#1669)
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
Loading