EdgeX cli命令安装及使用

EdgeX提供了丰富的API接口,在学习EdgeX过程中,我们经常会遇到在终端输入类似如下的curl命令:

curl -X POST -d '{
    "name":"QuickStartExport",
    "addressable":{
        "name":"HiveMQBroker",
        "protocol":"tcp",
        "address":"broker.hivemq.com",
        "port":1883,
        "publisher":"EdgeXExportPublisher",
        "topic":"EdgeXQuickStartGuide"
    },
    "format":"JSON",
    "filter":{
        "deviceIdentifiers":["Random-Integer-Generator01"]
    },
    "enable":true,
    "destination":"MQTT_TOPIC"
}' http://localhost:48071/api/v1/registration

该接口提供导出设备的注册

Postman一定程度上简化了操作,然而还是不如cli命令行来的直接


image.png

EdgeX提供了cli命令行来简化这一系列操作,这里简单介绍cli的安装及使用

前提:安装go

安装及使用

zj@zj-Z390-UD:~/下载$ git clone https://github.com/edgexfoundry-holding/edgex-cli
正克隆到 'edgex-cli'...
remote: Enumerating objects: 257, done.
remote: Counting objects: 100% (257/257), done.
remote: Compressing objects: 100% (134/134), done.
remote: Total 1596 (delta 108), reused 189 (delta 69), pack-reused 1339
接收对象中: 100% (1596/1596), 317.59 KiB | 389.00 KiB/s, 完成.
处理 delta 中: 100% (769/769), 完成.
zj@zj-Z390-UD:~/下载$ cd edgex-cli/
zj@zj-Z390-UD:~/下载/edgex-cli$ make install
echo "GOBIN=/home/zj/go/bin"
GOBIN=/home/zj/go/bin
CGO_ENABLED=0 GO111MODULE=on go install -ldflags "-X github.com/edgexfoundry-holding/edgex-cli/cmd/version.Version=0.0.1"
verifying github.com/stretchr/[email protected]/go.mod: github.com/stretchr/[email protected]/go.mod: Get https://proxy.golang.org/sumdb/sum.golang.org/supported: dial tcp 172.217.24.17:443: i/o timeout
Makefile:32: recipe for target 'install' failed
make: *** [install] Error 1
zj@zj-Z390-UD:~/下载/edgex-cli$ export GOPROXY=https://goproxy.cn
zj@zj-Z390-UD:~/下载/edgex-cli$ make install
echo "GOBIN=/home/zj/go/bin"
GOBIN=/home/zj/go/bin
CGO_ENABLED=0 GO111MODULE=on go install -ldflags "-X github.com/edgexfoundry-holding/edgex-cli/cmd/version.Version=0.0.1"
go: downloading github.com/spf13/cobra v0.0.5
go: downloading github.com/edgexfoundry/go-mod-core-contracts v0.1.57
go: downloading github.com/spf13/viper v1.3.2
go: extracting github.com/spf13/viper v1.3.2
go: downloading github.com/fsnotify/fsnotify v1.4.7
go: downloading github.com/hashicorp/hcl v1.0.0
go: downloading github.com/magiconair/properties v1.8.0
go: extracting github.com/fsnotify/fsnotify v1.4.7
go: extracting github.com/spf13/cobra v0.0.5
go: downloading github.com/spf13/cast v1.3.0
go: extracting github.com/magiconair/properties v1.8.0
go: downloading golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
go: downloading github.com/spf13/afero v1.1.2
go: extracting github.com/hashicorp/hcl v1.0.0
go: extracting github.com/spf13/cast v1.3.0
go: downloading github.com/spf13/jwalterweatherman v1.0.0
go: downloading github.com/spf13/pflag v1.0.3
go: extracting github.com/spf13/afero v1.1.2
go: downloading golang.org/x/text v0.3.0
go: extracting github.com/spf13/jwalterweatherman v1.0.0
go: extracting github.com/spf13/pflag v1.0.3
go: extracting github.com/edgexfoundry/go-mod-core-contracts v0.1.57
go: downloading github.com/fxamacker/cbor/v2 v2.2.0
go: extracting github.com/fxamacker/cbor/v2 v2.2.0
go: downloading github.com/x448/float16 v0.8.4
go: extracting golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
go: extracting github.com/x448/float16 v0.8.4
go: extracting golang.org/x/text v0.3.0
go: finding github.com/spf13/viper v1.3.2
go: finding github.com/fsnotify/fsnotify v1.4.7
go: finding golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
go: finding github.com/hashicorp/hcl v1.0.0
go: finding github.com/magiconair/properties v1.8.0
go: finding github.com/spf13/afero v1.1.2
go: finding golang.org/x/text v0.3.0
go: finding github.com/spf13/cast v1.3.0
go: finding github.com/spf13/jwalterweatherman v1.0.0
go: finding github.com/spf13/pflag v1.0.3
go: finding github.com/edgexfoundry/go-mod-core-contracts v0.1.57
go: finding github.com/fxamacker/cbor/v2 v2.2.0
go: finding github.com/x448/float16 v0.8.4
go: finding github.com/spf13/cobra v0.0.5
mkdir -p /home/zj/.edgex-cli
cp ./res/configuration.toml /home/zj/.edgex-cli/configuration.toml
zj@zj-Z390-UD:~/下载/edgex-cli$ /home/zj/go/bin/edgex-cli 
 ______     _              __   __            _____  _       _____        
|  ____|   | |             \ \ / /           / ____|| |     |_   _|     
| |__    __| |  __ _   ___  \ V /   ______  | |     | |       | |        
|  __|  / _` | / _` | / _ \  > <   |______| | |     | |       | |        
| |____| (_| || (_| ||  __/ / . \           | |____ | |____  _| |_       
|______|\__,_| \__, | \___|/_/ \_\           \_____||______||_____| 
        __/ |                                                             
           |___/                                                              

EdgeX CLI version: 0.0.1
https://www.edgexfoundry.org/

Usage:
  edgex-cli [command]

Available Commands:
  addressable   Addressable command command
  db            Purges entire EdgeX Database. [USE WITH CAUTION]
  device        Device command
  deviceservice Device service command
  event         Event command
  help          Help about any command
  interval      Interval command
  notification  Notification command
  profile       Device profile command.
  reading       Reading command
  status        Checks the current status of each microservice.
  subscription  Subscription command
  version       Version command

Flags:
      --config-file string   configuration file
  -h, --help                 help for edgex-cli
      --no-pager             Do not pipe output into a pager.
  -u, --url                  Print URL(s) used by the entered command.
  -v, --verbose              Print entire HTTP response.

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

添加/home/zj/go/bin(GOBIN)到PATH环境变量后

zj@zj-Z390-UD:~/下载/edgex-cli$ echo $PATH
/home/zj/go/bin:/home/zj/anaconda2/bin:/usr/local/hadoop-2.10.0/bin:/usr/local/go/bin:/usr/local/apache-maven-3.6.3/bin:/usr/local/java/jdk1.8.0_241/bin:/usr/local/java/jdk1.8.0_241/jre/bin:/home/zj/anaconda2/condabin:/home/zj/.local/bin:/home/zj/anaconda2/bin:/usr/local/hadoop-2.10.0/bin:/usr/local/go/bin:/usr/local/apache-maven-3.6.3/bin:/usr/local/java/jdk1.8.0_241/bin:/usr/local/java/jdk1.8.0_241/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

使用edgex-cli命令查询设备

zj@zj-Z390-UD:~/下载/edgex-cli$ edgex-cli device list
Device ID                              Device Name                     Operating State   Device Service      Device Profile                  
12148c87-47f2-49ac-903c-21038fd3f870   Random-UnsignedInteger-Device   ENABLED           device-virtual      Random-UnsignedInteger-Device   
312ea3ab-f5f3-4b7e-88b7-3f118fe34f43   sample-json                     ENABLED           edgex-device-rest   sample-json                     
500951e7-206e-4c27-a2e8-470bd6b1ca79   sample-numeric                  ENABLED           edgex-device-rest   sample-numeric                  
719e86c2-fb94-4d1b-bbc8-812b8484259f   Random-Boolean-Device           ENABLED           device-virtual      Random-Boolean-Device           
a05b28a9-61aa-4d53-b9a2-e83fb06ce0ae   Random-Float-Device             ENABLED           device-virtual      Random-Float-Device             
c0d92a8c-80c3-4563-99cb-42523756e8b6   Random-Integer-Device           ENABLED           device-virtual      Random-Integer-Device           
c263a342-b05a-44d0-9184-c718e0a6ae48   Random-Binary-Device            ENABLED           device-virtual      Random-Binary-Device            
ff4f0b09-48d3-4f15-b9ec-00912d37cbdb   sample-image                    ENABLED           edgex-device-rest   sample-image

参考

https://github.com/edgexfoundry-holding/edgex-cli

你可能感兴趣的:(EdgeX cli命令安装及使用)