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

Leshan does not decode SenML-CBOR string value (3) correctly #1654

Closed
kipusoep opened this issue Oct 3, 2024 · 10 comments
Closed

Leshan does not decode SenML-CBOR string value (3) correctly #1654

kipusoep opened this issue Oct 3, 2024 · 10 comments
Labels
question Any question about leshan

Comments

@kipusoep
Copy link

kipusoep commented Oct 3, 2024

Version(s)

f0825b5

Which components

leshan client demo

Tested With

No response

What happened

I am trying to PUT SenML_CBOR data from my LWM2M server to the leshan client demo, but I get an error:
Invalid SenML record : record must have a value (v,vb,vlo,vd,vs) : {"3": "hhh", "-2": "/3442/0/110"}

This doesn't make sense to me, as the value (vs) is present in the form of 3.
If I send the same payload in json format it works fine (with bn and vs obviously).
I checked the verbose logs and the client states:
Unable to decode node[path:/3442/0/110] : 81a2613363686868622d326b2f333434322f302f313130

If I take this binary hex and paste it in this online cbor tool, it also shows the correct json:
image

Looking at the source it tries to find an item with key 3, but it is present...
So I am really confused about what's going on. If I do the same request from the leshan server demo, it works fine, but I'm not sure what the difference is?

Thanks in advance for any help!

Relevant Output

This is the payload from the leshan server demo (left) vs my payload (right), maybe it's helpful?
image

@kipusoep kipusoep added the bug Dysfunctionnal behavior label Oct 3, 2024
@sbernard31
Copy link
Contributor

Thx for taking to report that. 🙏

I will try to have a look and will let you know what I will find.

@kipusoep
Copy link
Author

kipusoep commented Oct 3, 2024

@sbernard31 hi, thanks! But I think I might be doing something wrong, especially if you look at the payload comparison at the bottom of my post. Do you have any idea?
It seems the keys of the properties are different between them.

@sbernard31
Copy link
Contributor

Ok so this is your payload :

81a2613363686868622d326b2f333434322f302f313130

[{"3": "hhh", "-2": "/3442/0/110"}]

81                              # array(1)
   A2                           # map(2)
      61                        # text(1)
         33                     # "3"
      63                        # text(3)
         686868                 # "hhh"
      62                        # text(2)
         2D32                   # "-2"
      6B                        # text(11)
         2F333434322F302F313130 # "/3442/0/110"

===> Invalid SenML record : record must have a value (v,vb,vlo,vd,vs) : {"3": "hhh", "-2": "/3442/0/110"}

And this is the expected one :

81A20363686868216B2F333434322F302F313130

[{3: "hhh", -2: "/3442/0/110"}]

81                              # array(1)
   A2                           # map(2)
      03                        # unsigned(3)
      63                        # text(3)
         686868                 # "hhh"
      21                        # negative(1)
      6B                        # text(11)
         2F333434322F302F313130 # "/3442/0/110"

==> LwM2mSingleResource [id=110, value=hhh, type=STRING]

The difference you are using string as key instead of number.
I will double check the RFC but I think Leshan is right.

I agree that error message is not so good.

@kipusoep
Copy link
Author

kipusoep commented Oct 3, 2024

It seems you are absolutely right! I tried using a different CBOR library (for C#) and used integer keys, now it works! Thanks!

@sbernard31
Copy link
Contributor

Reading 6. CBOR Representation (application/senml+cbor) :

For compactness, the CBOR representation uses integers for the
labels, as defined in Table 4. This table is conclusive, i.e.,
there is no intention to define any additional integer map keys;
any extensions will use string map keys. This allows translators
converting between CBOR and JSON representations to also convert
all future labels without needing to update implementations. Base
values are given negative CBOR labels, and others are given
non-negative labels.

And examples confirm that.

@sbernard31
Copy link
Contributor

I can try to improve a bit the error message.

@sbernard31 sbernard31 added question Any question about leshan and removed bug Dysfunctionnal behavior labels Oct 3, 2024
@sbernard31
Copy link
Contributor

sbernard31 commented Oct 3, 2024

Maybe something like :

record must have a value : one of those field must be present v(number:2), vb(number:4), vlo(string:vlo) ,vd(number:8) or vs(number:3)

?

@sbernard31
Copy link
Contributor

sbernard31 commented Oct 3, 2024

@kipusoep let me know if you think this is clearer ☝️

(or if you have better idea)

@kipusoep
Copy link
Author

kipusoep commented Oct 3, 2024

Yeah I think it is an improvement, although I am afraid I still wouldn't figure it out if I has that error message instead :-P

@sbernard31
Copy link
Contributor

sbernard31 commented Oct 3, 2024

Yeah I think it is an improvement

Ok so I integrated that changed in master (commit a878c18)

although I am afraid I still wouldn't figure it out if I has that error message instead

Arf at least it will be easier for Leshan devs to answer to this kind of question. 😁

I think we can close this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Any question about leshan
Projects
None yet
Development

No branches or pull requests

2 participants