Coder Social home page Coder Social logo

MessageID about microcoapy HOT 6 CLOSED

Trifunik avatar Trifunik commented on June 22, 2024
MessageID

from microcoapy.

Comments (6)

ftylitak avatar ftylitak commented on June 22, 2024

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()

from microcoapy.

ftylitak avatar ftylitak commented on June 22, 2024

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.

from microcoapy.

ftylitak avatar ftylitak commented on June 22, 2024

@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?

from microcoapy.

Trifunik avatar Trifunik commented on June 22, 2024

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.

from microcoapy.

ftylitak avatar ftylitak commented on June 22, 2024

Yes unfortunatelly it was a misleading typo.

from microcoapy.

ftylitak avatar ftylitak commented on June 22, 2024

@Trifunik

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

Regards.

from microcoapy.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.