From b49aa6e5f2dd45b3160db1d07f5b1213f9e08253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Borov=C4=8Danin?= Date: Tue, 20 Aug 2019 11:06:33 +0200 Subject: [PATCH] Add message ID and token flags --- README.md | 17 +++++++++-------- cmd/main.go | 17 +++++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9e3ce0e..65b3539 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,15 @@ Simple CoAP cli client written in Go. When running, please provide following format: `go run` or, if compiled, `./binary_name` followed by method code (`get`, `put`, `post`, `delete`) and CoAP URL. After that, you can pass following flags: -| Flag | Description | Default value | -|------|--------------------------------|---------------| -| ACK | Acknowledgement | false | -| C | Confirmable | false | -| NC | Non-Confirmable | false | -| O | Observe | false | -| d | Data to be sent in POST or PUT | "" | - +| Flag | Description | Default value | +|-------|--------------------------------|----------------------------------------| +| ACK | Acknowledgement | false | +| C | Confirmable | false | +| NC | Non-Confirmable | false | +| O | Observe | false | +| d | Data to be sent in POST or PUT | "" | +| id | Message ID | 0 | +| token | Token | Byte array of empty string: [49 50 51] | # Examples: ```bash diff --git a/cmd/main.go b/cmd/main.go index 50f1770..3f88e70 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -3,6 +3,7 @@ package main import ( "errors" "flag" + "fmt" "log" "net/url" "os" @@ -60,8 +61,8 @@ func checkType(c, n, a, r *bool) (gocoap.COAPType, error) { func printMsg(m *gocoap.Message) { if m != nil { - log.Printf("Type: %d\nCode: %d\nMessageID: %d\nToken: %s\nPayload: %s\n", - m.Type, m.Code, m.MessageID, m.Token, m.Payload) + log.Printf("Type: %d\nCode: %s\nMessageID: %d\nToken: %s\nPayload: %s\n", + m.Type, m.Code.String(), m.MessageID, m.Token, m.Payload) } } @@ -84,10 +85,12 @@ func main() { a := flag.Bool("ACK", false, "Acknowledgement") r := flag.Bool("RST", false, "Reset") o := flag.Bool("O", false, "Observe") - - cf := flag.Int("CF", 0, "Content format") - + // Default type is JSON. + cf := flag.Int("CF", 50, "Content format") d := flag.String("d", "", "Message data") + id := flag.Uint("id", 0, "Message ID") + token := flag.String("token", "", "Message data") + flag.Parse() t, err := checkType(c, n, a, r) @@ -117,7 +120,9 @@ func main() { }) } - res, err := client.Send(t, code, 12, nil, []byte(*d), opts) + fmt.Println("sasa", []byte(*token)) + + res, err := client.Send(t, code, uint16(*id), []byte(*token), []byte(*d), opts) if err != nil { log.Fatal("ERROR: ", err) }