Skip to content

Commit

Permalink
Add message ID and token flags
Browse files Browse the repository at this point in the history
  • Loading branch information
dborovcanin committed Aug 20, 2019
1 parent 785a830 commit b49aa6e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"flag"
"fmt"
"log"
"net/url"
"os"
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit b49aa6e

Please sign in to comment.