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

MessageID #4

Closed
Trifunik opened this issue Jan 1, 2020 · 6 comments
Closed

MessageID #4

Trifunik opened this issue Jan 1, 2020 · 6 comments

Comments

@Trifunik
Copy link

Trifunik commented Jan 1, 2020

Hi,
I am using your lib as a client for a small project of mine --> https://github.com/Trifunik/condensation_alert.
Do you know any elegant way to get the coapPacket.messageid from the get function?
I want to be sure that the payload is the response to the wright GET request, because I have sometimes a race condition between two GET requests.

Many thanks in advance!
Nikola

@ftylitak
Copy link
Member

ftylitak commented Jan 2, 2020

Hello @Trifunik

You are looking for a way to get the coapPacket.messageid of a GET function and I will suppose that you require the messageid of the request packet. Correct?

If this is indeed true, then the messsageid of the request packet is the integer value returned by the client.get function.

Note here that the example in our source code has a typo. At the print of the return value of the get function, it is named as payload which should be replaced with messageid.

example:

import microcoapy
# your code to connect to the network
#...
def receivedMessageCallback(packet, sender):
        print('Message received:', packet, ', from: ', sender)
        print('Mesage payload: ', packet.payload.decode('unicode_escape'))
        print('Response ID: ', packet.messageid.decode('unicode_escape'))

client = microcoapy.Coap()
client.resposeCallback = receivedMessageCallback
client.start()

_SERVER_IP="192.168.1.2"
_SERVER_PORT=5683
requestId= client.get(_SERVER_IP, _SERVER_PORT, "current/measure")
print("[GET] Request ID: ", requestId)

client.poll(2000)

client.stop()

@ftylitak
Copy link
Member

ftylitak commented Jan 2, 2020

Update: according to the CoAP specification, the messageid is mainly used for duplicate message detection and optional reliability in case of losses. On the other hand, token is used for request/response matching.

Based on this info, I will go over our implementation to see if it needs adjustments.

@ftylitak
Copy link
Member

ftylitak commented Jan 2, 2020

@Trifunik
As a respose to your question, after a proper code review, the correct approach is to use the token field to match request/respose pairs.

The functions get, put, post have been updated to support a token parameter. Thus, if you provide as a last argument a token byte array, this exact token must exist in the corresponding response.

To get the new functionality please pull the latest changes from master. Be aware of some minor breaking changes at parameter names.

Does this approach solves your request?

@Trifunik
Copy link
Author

Trifunik commented Jan 2, 2020

Thank you!
Yes, I did not look good enough at your GET function. Because I saw in the example "bytesTransferred = client.get(...)" and thought I have to look somewhere else.

@ftylitak
Copy link
Member

ftylitak commented Jan 2, 2020

Yes unfortunatelly it was a misleading typo.

@ftylitak
Copy link
Member

ftylitak commented Jan 6, 2020

@Trifunik

as soon as you test it in your project and you need no further changes, could you close the issue?

Regards.

@Trifunik Trifunik closed this as completed Jan 8, 2020
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

No branches or pull requests

2 participants