diff --git a/cmd/main.go b/cmd/main.go index 9e36114..96ef806 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -13,6 +13,7 @@ import ( "strconv" "strings" "syscall" + "time" coap "github.com/absmach/coap-cli/coap" "github.com/fatih/color" @@ -92,14 +93,26 @@ func main() { func printMsg(m *pool.Message, verbose bool) { if m != nil && verbose { - log.Printf("\nMESSAGE:\n%s", m.String()) + fmt.Printf("Date: %s\n", time.Now().Format(time.RFC1123)) + fmt.Printf("Code: %s\n", m.Code().String()) + fmt.Printf("Type: %s\n", m.Type().String()) + fmt.Printf("Token: %s\n", m.Token().String()) + fmt.Printf("Message-ID: %d\n", m.MessageID()) + cf, err := m.ContentFormat() + if err == nil { + fmt.Printf("Content-Format: %s \n", cf.String()) + } + bs, err := m.BodySize() + if err == nil { + fmt.Printf("Content-Length: %d\n", bs) + } } body, err := m.ReadBody() if err != nil { log.Fatalf("failed to read body %v", err) } if len(body) > 0 { - log.Printf("MESSAGE BODY:\n %s", string(body)) + fmt.Printf("\n%s\n", string(body)) } } diff --git a/coap/client.go b/coap/client.go index a6e1bf7..4c4fdd5 100644 --- a/coap/client.go +++ b/coap/client.go @@ -74,7 +74,11 @@ func (c Client) Receive(path string, verbose bool, opts ...message.Option) (mux. return c.conn.Observe(ctx, path, func(res *pool.Message) { if verbose { - fmt.Printf("RECEIVED OBSERVE: %v\n", res) + fmt.Printf("Date: %s\n", time.Now().Format(time.RFC1123)) + fmt.Printf("Code: %s\n", res.Code().String()) + fmt.Printf("Type: %s\n", res.Type().String()) + fmt.Printf("Token: %s\n", res.Token().String()) + fmt.Printf("Message-ID: %d\n", res.MessageID()) } body, err := res.ReadBody() if err != nil {