Skip to content

Commit

Permalink
Merge branch 'master' into task/allow_ngsiv2_as_measure
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Oct 25, 2023
2 parents de727ec + b6060de commit 9928b4c
Show file tree
Hide file tree
Showing 22 changed files with 74 additions and 171 deletions.
2 changes: 1 addition & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- Fix: binary data representation when sending data through HTTP & MQTT (#690)
- Fix: ensure service and subservice from device in logs about error proccesing message
- Remove: legacy code about unused parsedMessageError flag
- Remove: legacy code about unused parsedMessageError flag
21 changes: 0 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,6 @@ their APIs can be found in the IoT Agent Library [documentation](https://iotagen
The latest IoT Agent for JSON documentation is also available on
[ReadtheDocs](https://fiware-iotagent-json.readthedocs.io/en/latest/)

## Command-line Client

The JSON IoT Agent comes with a client that can be used to test its features, simulating a device. The client can be
executed with the following command:

```console
bin/iotaJsonTester.js
```

This will show a prompt where commands can be issued to the MQTT broker. For a list of the currently available commands
type `help`.

The client loads a global configuration used for all the commands, containing the host and port of the MQTT broker and
the API Key and Device ID of the device to simulate. This information can be changed with the `config` command.

In order to use any of the MQTT commands, you have to connect to the MQTT broker first. If no connection is available,
MQTT commands will show an error message reminding you to connect.

The command-line Client gets its default values from a config file in the root of the project: `client-config.js`. This
config file can be used to permanently tune the MQTT broker parameters, or the default device ID and APIKey.

## Contributing

If you'd like to contribute, start by searching through the issues and pull requests to see whether someone else has
Expand Down
4 changes: 2 additions & 2 deletions lib/bindings/HTTPBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function executeCommand(apiKey, device, cmdName, serializedPayload, contentType,
.getLogger()
.info(
context,
'Cmd:\n %j was sent to the device %s with http options %j',
'Cmd: %j was sent to the device %s with http options %j',
serializedPayload,
cmdName,
options
Expand All @@ -236,7 +236,7 @@ function executeCommand(apiKey, device, cmdName, serializedPayload, contentType,
.getLogger()
.info(
context,
'Cmd:\n %j was sent to the device %s with http options %j',
'Cmd: %j was sent to the device %s with http options %j',
serializedPayload,
cmdName,
options
Expand Down
14 changes: 7 additions & 7 deletions lib/bindings/MQTTBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function recreateSubscriptions(callback) {
callback(error);
} else {
iotAgentLib.alarms.release(constants.MQTTB_ALARM);
config.getLogger().info(context, 'Successfully subscribed to the following topics:\n%j\n', topics);
config.getLogger().info(context, 'Successfully subscribed to the following topics: %j', topics);
if (callback) {
callback(null);
}
Expand Down Expand Up @@ -175,7 +175,7 @@ function sendConfigurationToDevice(apiKey, deviceId, results, callback) {
if (config.getConfig().mqtt.retain === true) {
options.retain = config.getConfig().mqtt.retain;
}
config.getLogger().debug(context, 'Sending requested configuration to the device:\n %j', configurations);
config.getLogger().debug(context, 'Sending requested configuration to the device: %j', configurations);
const leadingSlash = config.getConfig().mqtt.avoidLeadingSlash ? '' : '/';

const commandTopic =
Expand All @@ -199,17 +199,17 @@ function sendConfigurationToDevice(apiKey, deviceId, results, callback) {
.getLogger()
.error(
context,
'Error %j in Configuration:\n %j sent to the device %s with mqtt options %j',
'Error %j in Configuration: %j sent to the device %s with mqtt options %j',
error,
JSON.stringify(configurations),
commandTopic,
options
);
}
});
config.getLogger().info(context, 'Configuration:\n %j was sent to the device: %s', configurations, commandTopic);
config.getLogger().info(context, 'Configuration: %j was sent to the device: %s', configurations, commandTopic);
} else {
config.getLogger().error(context, 'Configuration:\n %j was not set to the device: %s due to not connected', configurations, commandTopic);
config.getLogger().error(context, 'Configuration: %j was not set to the device: %s due to not connected', configurations, commandTopic);
}
callback();
}
Expand Down Expand Up @@ -407,7 +407,7 @@ function executeCommand(apiKey, device, cmdName, serializedPayload, contentType,
.getLogger()
.error(
context,
'Error %j in Cmd:\n %j sent to the device %s with mqtt options %j',
'Error %j in Cmd: %j sent to the device %s with mqtt options %j',
error,
serializedPayload,
commandTopic,
Expand All @@ -419,7 +419,7 @@ function executeCommand(apiKey, device, cmdName, serializedPayload, contentType,
.getLogger()
.info(
context,
'Cmd:\n %j was sent to the device %s with mqtt options %j',
'Cmd: %j was sent to the device %s with mqtt options %j',
serializedPayload,
commandTopic,
options
Expand Down
22 changes: 5 additions & 17 deletions lib/commandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function generateCommandExecution(apiKey, device, attribute) {
.getLogger()
.debug(
context,
'Sending command execution to device [%s] with apikey [%s] and payload [%j] ',
'Sending command execution to device %s with apikey %s and payload %j ',
device.id,
apiKey,
payload
Expand Down Expand Up @@ -134,14 +134,7 @@ function generateCommandExecution(apiKey, device, attribute) {
function commandHandler(id, type, service, subservice, attributes, callback) {
config
.getLogger()
.debug(
context,
'Handling command %j for device [%s] in service [%s - %s]',
attributes,
id,
service,
subservice
);
.debug(context, 'Handling command %j for device %s in service %s - %s', attributes, id, service, subservice);

function concat(previous, current) {
previous = previous.concat(current);
Expand All @@ -153,7 +146,7 @@ function commandHandler(id, type, service, subservice, attributes, callback) {
config.getLogger().error(
context,

"COMMAND-001: Command execution could not be handled, as device for entity [%s] [%s] wasn't found",
"COMMAND-001: Command execution could not be handled, as device for entity %s %s wasn't found",

id,
type
Expand Down Expand Up @@ -207,20 +200,15 @@ function updateCommand(apiKey, deviceId, device, messageObj) {
context,

"COMMANDS-002: Couldn't update command status in the Context broker " +
'for device [%s] with apiKey [%s]: %s',
'for device %s with apiKey %s: %s',
device.id,
apiKey,
error
);
} else {
config
.getLogger()
.debug(
context,
'Single measure for device [%s] with apiKey [%s] successfully updated',
device.id,
apiKey
);
.debug(context, 'Single measure for device %s with apiKey %s successfully updated', device.id, apiKey);
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions lib/iotaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function manageConfiguration(apiKey, deviceId, device, objMessage, sendFunction,
.getLogger()
.error(
context,
'CONFIG-002: There was an error subscribing device [%s] to attributes [%j]',
'CONFIG-002: There was an error subscribing device %s to attributes %j',
device.name,
objMessage.fields
);
Expand All @@ -106,7 +106,7 @@ function manageConfiguration(apiKey, deviceId, device, objMessage, sendFunction,
.getLogger()
.debug(
context,
'Successfully subscribed device [%s] to attributes[%j]',
'Successfully subscribed device %s to attributes %j',
device.name,
objMessage.fields
);
Expand All @@ -115,7 +115,7 @@ function manageConfiguration(apiKey, deviceId, device, objMessage, sendFunction,
callback(error);
});
} else {
config.getLogger().error(context, 'CONFIG-003: Unknown command type from device [%s]', device.name);
config.getLogger().error(context, 'CONFIG-003: Unknown command type from device %s', device.name);
callback();
}
}
Expand Down Expand Up @@ -228,7 +228,7 @@ function retrieveDevice(deviceId, apiKey, transport, callback) {
config.getLogger().error(
context,

"MEASURES-001: Couldn't find device data for APIKey [%s] and DeviceId[%s]",
"MEASURES-001: Couldn't find device data for APIKey %s and DeviceId %s",

apiKey,
deviceId
Expand Down
10 changes: 5 additions & 5 deletions lib/transportSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ function startTransportBindings(newConfig, callback) {

const bindings = fs.readdirSync(path.join(__dirname, './bindings'));

transportBindings = bindings.map(function(item) {
transportBindings = bindings.map(function (item) {
return require('./bindings/' + item);
});

/* eslint-disable no-unused-vars */
async.map(transportBindings, invokeBinding, function(error) {
async.map(transportBindings, invokeBinding, function (error) {
callback();
});
}

function createExecutionsForBinding(argument, functionName, protocol) {
config.getLogger().debug('Creating execution for function [%s] and protocol [%s]', functionName, protocol);
config.getLogger().debug('Creating execution for function %s and protocol %s', functionName, protocol);

function addHandler(current, binding) {
if (binding[functionName] && (!protocol || binding.protocol === protocol)) {
const args = [binding[functionName]].concat(argument);
const boundFunction = binding[functionName].bind.apply(binding[functionName], args);

config.getLogger().debug('Binding found for function [%s] and protocol [%s]', functionName, protocol);
config.getLogger().debug('Binding found for function %s and protocol %s', functionName, protocol);
current.push(boundFunction);
}

Expand All @@ -79,7 +79,7 @@ function createExecutionsForBinding(argument, functionName, protocol) {
* @param {String} protocol Transport protocol where the function must be executed.
*/
function applyFunctionFromBinding(argument, functionName, protocol, callback) {
config.getLogger().debug('Looking for bindings for the function [%s] and protocol [%s]', functionName, protocol);
config.getLogger().debug('Looking for bindings for the function %s and protocol %s', functionName, protocol);

async.series(createExecutionsForBinding(argument, functionName, protocol), callback);
}
Expand Down
3 changes: 1 addition & 2 deletions test/deviceProvisioning/provisionDeviceTimeinstant2.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
},
{
"type": "DateTime",
"name": "TimeInstant",
"object_id": "t"
"name": "TimeInstant"
}
],
"entity_type": "sensor",
Expand Down
16 changes: 8 additions & 8 deletions test/unit/ngsiv2/HTTP_reveice_measures-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ describe('HTTP: Measure reception ', function () {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
json: {
humidity: '111222',
h: '111222',
pressure: '20',
TimeInstant: '20200222T222222'
TimeInstant: '2020-02-22T22:22:22Z'
},
headers: {
'fiware-service': 'smartgondor',
Expand Down Expand Up @@ -217,9 +217,9 @@ describe('HTTP: Measure reception ', function () {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
json: {
humidity: '111222',
h: '111222',
pressure: '20',
TimeInstant: '20200222T222222'
TimeInstant: '2020-02-22T22:22:22Z'
},
headers: {
'fiware-service': 'smartgondor',
Expand Down Expand Up @@ -280,7 +280,7 @@ describe('HTTP: Measure reception ', function () {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
json: {
humidity: '111222',
h: '111222',
pressure: '20'
},
headers: {
Expand All @@ -290,7 +290,7 @@ describe('HTTP: Measure reception ', function () {
qs: {
i: 'dev0130101',
k: '1234',
t: '20200222T222222'
t: '2020-02-22T22:22:22Z'
}
};
const provisionOptions = {
Expand Down Expand Up @@ -343,7 +343,7 @@ describe('HTTP: Measure reception ', function () {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
json: {
humidity: '111222',
h: '111222',
pressure: '20'
},
headers: {
Expand All @@ -353,7 +353,7 @@ describe('HTTP: Measure reception ', function () {
qs: {
i: 'dev0130101',
k: '1234',
t: '20200222T222222'
t: '2020-02-22T22:22:22Z'
}
};
const provisionOptions = {
Expand Down
17 changes: 9 additions & 8 deletions test/unit/ngsiv2/HTTP_reveice_measures-test2.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ describe('HTTP: Measure reception ', function () {
method: 'POST',
json: [
{
humidity: '111222',
TimeInstant: '20200222T222222'
h: '111222',
TimeInstant: '2020-02-22T22:22:22Z'
},
{
humidity: '111333',
TimeInstant: '20200222T222222'
h: '111333',
TimeInstant: '2020-02-22T22:22:22Z'
}
],
headers: {
Expand Down Expand Up @@ -254,10 +254,11 @@ describe('HTTP: Measure reception ', function () {
method: 'POST',
json: [
{
humidity: '111222'
h: '111222'

},
{
humidity: '111333'
h: '111333'
}
],
headers: {
Expand All @@ -266,8 +267,8 @@ describe('HTTP: Measure reception ', function () {
},
qs: {
i: 'dev0130101',
k: '1234',
t: '20200222T222222'
k: '1234' ,
t:'2020-02-22T22:22:22Z'
}
};
const provisionOptions = {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/ngsiv2/MQTT_receive_measures-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ describe('MQTT: Measure reception ', function () {
const values = {
humidity: '32',
temperature: '87',
TimeInstant: '20071103T131805'
TimeInstant: '2007-11-03T13:18:05Z'
};

mqttClient.publish('/1234/MQTT_2/attrs', JSON.stringify(values), null, function (error) {
Expand All @@ -282,7 +282,7 @@ describe('MQTT: Measure reception ', function () {
const values = {
humidity: '32',
temperature: '87',
TimeInstant: '20071103T131805'
TimeInstant: '2007-11-03T13:18:05Z'
};

mqttClient.publish('json/1234/MQTT_2/attrs', JSON.stringify(values), null, function (error) {
Expand Down
Loading

0 comments on commit 9928b4c

Please sign in to comment.