EdgeX cli命令安裝及使用

EdgeX提供了豐富的API接口,在學(xué)習(xí)EdgeX過程中,我們經(jīng)常會(huì)遇到在終端輸入類似如下的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

該接口提供導(dǎo)出設(shè)備的注冊(cè)

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
接收對(duì)象中: 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/objx@v0.2.0/go.mod: github.com/stretchr/objx@v0.2.0/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環(huán)境變量后

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命令查詢?cè)O(shè)備

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容