Skip to content

Commit

Permalink
Merge pull request #736 from Keshav-NEC/Fix_for_690
Browse files Browse the repository at this point in the history
Fix for binary data representation when sending data through HTTP & MQTT
  • Loading branch information
mapedraza authored Oct 3, 2023
2 parents 952447f + f5f7406 commit a79ee65
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1 @@

- Fix: binary data representation when sending data through HTTP & MQTT (#690)
4 changes: 2 additions & 2 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ This product is a FIWARE Generic Enabler. If you would like to learn about the o

### Introduction

This IoT Agent uses the [FIWARE IoT Agent Node.js Library](https://github.com/telefonicaid/iotagent-node-lib) framework.
This is why most of the functionalities of this component depend on the new features of the library itself.
This IoT Agent uses the [FIWARE IoT Agent Node.js Library](https://github.com/telefonicaid/iotagent-node-lib) framework.
This is why most of the functionalities of this component depend on the new features of the library itself.

For this reason, the roadmap of this component would be defined by the IoT Agent Node Library Roadmap that you can check
[here](https://github.com/telefonicaid/iotagent-node-lib/blob/master/doc/roadmap.md)
5 changes: 4 additions & 1 deletion lib/bindings/HTTPBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ function parseData(req, res, next) {
next(error);
} else {
req.jsonPayload = data;

if (req.body !== undefined ) {
data = data.toString('hex');
}
config.getLogger().debug(context, 'Parsed data: [%j]', data);
next();
}
Expand Down Expand Up @@ -290,6 +292,7 @@ function handleIncomingMeasure(req, res, next) {

if (req.attr && req.jsonPayload) {
config.getLogger().debug(context, 'Parsing attr [%s] with value [%s]', req.attr, req.jsonPayload);
req.jsonPayload = req.jsonPayload.toString('hex');
const theAttr = [{ name: req.attr, value: req.jsonPayload, type: 'None' }];
attributeArr.push(theAttr);
} else {
Expand Down
20 changes: 20 additions & 0 deletions test/unit/ngsiv2/MQTT_receive_measures-test2.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,24 @@ describe('MQTT: Measure reception ', function () {
});
});
});
describe('When a POST single Raw measure arrives for the HTTP binding', function () {
beforeEach(function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasuresRawTypes1.json')
)
.reply(204);
});
it('should send its value to the Context Broker', function (done) {
mqttClient.publish('/1234/MQTT_2/attrs/humidity', 'A$Ci1', null, function (error) {
setTimeout(function () {
contextBrokerMock.done();
done();
}, 100);
});
});
});
});
8 changes: 1 addition & 7 deletions test/unit/ngsiv2/contextRequests/singleMeasuresRawTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
"type":"AnMQTTDevice",
"humidity":{
"type": "degrees",
"value": {
"type": "Buffer",
"data": [
51,
50
]
}
"value": "3332"
}
}
8 changes: 8 additions & 0 deletions test/unit/ngsiv2/contextRequests/singleMeasuresRawTypes1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id":"Second MQTT Device",
"type":"AnMQTTDevice",
"humidity":{
"type": "degrees",
"value": "4124436931"
}
}

0 comments on commit a79ee65

Please sign in to comment.