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

[Observable] Set CON/NON for notifications #32

Closed
palsivertsen opened this issue Jan 16, 2019 · 5 comments
Closed

[Observable] Set CON/NON for notifications #32

palsivertsen opened this issue Jan 16, 2019 · 5 comments

Comments

@palsivertsen
Copy link

RFC7641 states:

A notification can be confirmable or non-confirmable, i.e., it can be
sent in a confirmable or a non-confirmable message. The message type
used for a notification is independent of the type used for the
request and of any previous notification.

The ResponseWriter and Message interfaces are both missing an option to set the type of a message to CON/NON.

Is there a way to set message type for a notification when responding to a observe request?

@jkralik
Copy link
Member

jkralik commented Jan 16, 2019

Request contains client that provides call NewMessage.
Eg:

req.Client.NewMessage(coap.MessageParams{
   	Type:  NonConfirmable,
   	...
})

Is it helps you?

@palsivertsen
Copy link
Author

Yes, that would help. Thanks!

@palsivertsen
Copy link
Author

Shouldn't coap.ResponseWriter.WriteMsg if there's no ACK of a CON message?

I'm running the observe client/server example like so:
server/main.go:

....
func sendResponse(w coap.ResponseWriter, req *coap.Request, subded time.Time) error {
  resp := req.Client.NewMessage(coap.MessageParams{
    Type: coap.Confirmable,
    Code: coap.Content,
  })  
  resp.SetOption(coap.ContentFormat, coap.TextPlain)
  resp.SetObserve(5)
  resp.SetPayload([]byte(fmt.Sprintf("Been running for %v", time.Since(subded))))
  return w.WriteMsg(resp)
}
...

@palsivertsen palsivertsen reopened this Jan 17, 2019
@jkralik
Copy link
Member

jkralik commented Jan 30, 2019

But i think you need to set Token and MessageId(for udp) because the client cannot pair notification..... something like:

func sendResponse(w coap.ResponseWriter, req *coap.Request, subded time.Time) error {
  resp := req.Client.NewMessage(coap.MessageParams{
    Type: coap.Confirmable,
    Code: coap.Content,
    MessageID: req.Msg.MessageID(),
    Token:     req.Msg.Token(),
  })  
  resp.SetOption(coap.ContentFormat, coap.TextPlain)
  resp.SetObserve(5)
  resp.SetPayload([]byte(fmt.Sprintf("Been running for %v", time.Since(subded))))
  return w.WriteMsg(resp)
}
...

@jkralik
Copy link
Member

jkralik commented Mar 8, 2019

I will close this issue. Please if you have still problem please reopen it. Thx

@jkralik jkralik closed this as completed Mar 8, 2019
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