Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
# Copyright (c) Abstract Machines
# SPDX-License-Identifier: Apache-2.0

INSTALL_DIR=/usr/local/bin
BUILD_DIR=build
BUILD_FLAGS=-ldflags "-s -w"
INSTALL_DIR ?= /usr/local/bin
BUILD_DIR ?= build
BUILD_FLAGS ?= -ldflags "-s -w"
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)

.PHONY: all linux darwin windows install install-linux
.PHONY: all linux darwin windows install

all: linux darwin windows

linux:
CGO_ENABLED=0 GOOS=linux go build $(BUILD_FLAGS) -o $(BUILD_DIR)/coap-cli-linux main.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o $(BUILD_DIR)/coap-cli-linux-amd64 main.go
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(BUILD_FLAGS) -o $(BUILD_DIR)/coap-cli-linux-arm64 main.go
CGO_ENABLED=0 GOOS=linux GOARCH=riscv64 go build $(BUILD_FLAGS) -o $(BUILD_DIR)/coap-cli-linux-riscv64 main.go

darwin:
CGO_ENABLED=0 GOOS=darwin go build $(BUILD_FLAGS) -o $(BUILD_DIR)/coap-cli-darwin main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAGS) -o $(BUILD_DIR)/coap-cli-darwin-amd64 main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build $(BUILD_FLAGS) -o $(BUILD_DIR)/coap-cli-darwin-arm64 main.go

windows:
CGO_ENABLED=0 GOOS=windows go build $(BUILD_FLAGS) -o $(BUILD_DIR)/coap-cli-windows main.go

install: install-linux
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build $(BUILD_FLAGS) -o $(BUILD_DIR)/coap-cli-windows-amd64 main.go
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build $(BUILD_FLAGS) -o $(BUILD_DIR)/coap-cli-windows-arm64 main.go

install-linux:
@cp $(BUILD_DIR)/coap-cli-linux $(INSTALL_DIR)/coap-cli || { echo "Installation failed"; exit 1; }
install:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build $(BUILD_FLAGS) -o $(BUILD_DIR)/coap-cli main.go
cp $(BUILD_DIR)/coap-cli $(INSTALL_DIR)/coap-cli || { echo "Installation failed"; exit 1; }

clean:
rm -rf $(BUILD_DIR)/*
50 changes: 45 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,52 @@

Simple CoAP cli client written in Go.

## Installation

### Linux

```bash
# x86_64
curl -sL https://github.com/absmach/coap-cli/releases/download/v0.4.1/coap-cli-linux-amd64 -o coap-cli && chmod +x coap-cli
# arm64
curl -sL https://github.com/absmach/coap-cli/releases/download/v0.4.1/coap-cli-linux-arm64 -o coap-cli && chmod +x coap-cli
# riscv64
curl -sL https://github.com/absmach/coap-cli/releases/download/v0.4.1/coap-cli-linux-riscv64 -o coap-cli && chmod +x coap-cli
```

### MacOS

```bash
# x86_64
curl -sL https://github.com/absmach/coap-cli/releases/download/v0.4.1/coap-cli-darwin-amd64 -o coap-cli && chmod +x coap-cli
# arm64
curl -sL https://github.com/absmach/coap-cli/releases/download/v0.4.1/coap-cli-darwin-arm64 -o coap-cli && chmod +x coap-cli
```

### Windows

```bash
# x86_64
curl -sL https://github.com/absmach/coap-cli/releases/download/v0.4.1/coap-cli-windows-amd64 -o coap-cli.exe
# arm64
curl -sL https://github.com/absmach/coap-cli/releases/download/v0.4.1/coap-cli-windows-arm64 -o coap-cli.exe
```

### Build from source

Make sure you have Go and Make installed.

```bash
git clone https://github.com/absmach/coap-cli.git
cd coap-cli
make install # or INSTALL_DIR=~/go/bin make install
```

## Usage

```bash
CLI for CoAP

Usage:
coap-cli [command]

Expand All @@ -26,13 +69,11 @@ Flags:
-k, --keep-alive uint Send a ping after interval seconds of inactivity. If not specified (or 0), keep-alive is disabled (default).
-K, --key-file string Client key file
-m, --max-retries uint32 Max retries for keep alive (default 10)
-O, --options num,text Add option num with contents of text to the request. If the text begins with 0x, then the hex text (two [0-9a-f] per byte) is converted to binary data.
-O, --options stringArray Add option num with contents of text to the request. If the text begins with 0x, then the hex text (two [0-9a-f] per byte) is converted to binary data.
-p, --port string Port (default "5683")
-v, --verbose Verbose output
-d, --data string Data(default "") - only available for put, post and delete commands
-o, --observe bool Observe - only available for get command

Use "coap-cli [command] --help" for more information about a command
Use "coap-cli [command] --help" for more information about a command.
```

The options flag accepts a comma separated string comprising of the optionID defined by [RFC-7252](https://datatracker.ietf.org/doc/html/rfc7252) and a string or hex value. Hex values are used to set options that require numerical values e.g observe, maxAge
Expand All @@ -55,7 +96,6 @@ coap-cli get m/aa844fac-2f74-4ec3-8318-849b95d03bcc/c/0bb5ba61-a66e-4972-bab6-26
coap-cli post m/aa844fac-2f74-4ec3-8318-849b95d03bcc/c/0bb5ba61-a66e-4972-bab6-26f19962678f/subtopic --auth 1e1017e6-dee7-45b4-8a13-00e6afeb66eb -d "hello world"
```


```bash
coap-cli post m/aa844fac-2f74-4ec3-8318-849b95d03bcc/c/0bb5ba61-a66e-4972-bab6-26f19962678f/subtopic --auth 1e1017e6-dee7-45b4-8a13-00e6afeb66eb -d "hello world" -H 0.0.0.0 -p 1234
```
Expand Down