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

Fix: binary data representation when sending data through HTTP & MQTT #690 #725

Conversation

MayankSingh-NEC
Copy link

@MayankSingh-NEC MayankSingh-NEC commented May 29, 2023

Hi @mapedraza and @fgalan,

This PR originates from #696
Issue: #690

@MayankSingh-NEC MayankSingh-NEC changed the title Fix: binary data representation when sending data through HTTP #690 Fix: binary data representation when sending data through HTTP & MQTT #690 May 29, 2023
@MayankSingh-NEC
Copy link
Author

Hi @mapedraza and @fgalan ,

I have performed the UTs on my local environment and all the test cases are getting passed.
Please find the below attachment:

MQTT: Commands
When a command with payloadtype arrives to the Agent for a device with the MQTT_JSON protocol
✓ should return a 204 OK without errors
✓ should update the status in the Context Broker
✓ binaryfromhex - should publish the transformed command information in the MQTT topic (146ms)
✓ text - should publish the transformed command information in the MQTT topic (140ms)

The above UT (CI / Unit Tests (14.x)) is not failed due to this PR. Please let me know your opinion. Thanks!

.reply(204);
});
it('should send its value to the Context Broker', function (done) {
mqttClient.publish('/1234/MQTT_2/attrs/humidity', '0x4D', null, function (error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mqttClient.publish('/1234/MQTT_2/attrs/humidity', '0x4D', null, function (error) {
mqttClient.publish('/1234/MQTT_2/attrs/humidity', '0x4D', null, function (error) {

This case is not totally correct. You are not sending binary data through MQTT here. When sending '0x4D', you are sending a string of ascii chars. In that case, the binary representation (in Hex) is made of 4 bytes:

Hex representation

0x30,0x78,0x34,0x44

Binary representation

00110000 01111000 00110100 01000100

So, the expected value persisted in that case should be:

"value": "30783444"

So, the initial part (0x), should not be removed

In order to don't lead to confusion, I suggest to change the test string without including the initial part 0x.
Additionally, the part of the code that removes 0x should be removed

@mapedraza
Copy link
Collaborator

Overpassed by #736

@mapedraza mapedraza closed this Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants