From 5b207c8f16228b7da7ed0fec4433fb1350251bb7 Mon Sep 17 00:00:00 2001 From: Marc-Philippe Fuller Date: Thu, 21 Apr 2022 17:52:34 -0700 Subject: [PATCH] fix: updated example scripts to work with current changes of edgex (#74) Signed-off-by: Marc-Philippe Fuller --- examples/command.sh | 27 +++++++++++++-------------- examples/data.sh | 3 +-- examples/example.sh | 32 ++++++++++++++++---------------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/examples/command.sh b/examples/command.sh index 0ec3c5b7..c7d8ab6d 100755 --- a/examples/command.sh +++ b/examples/command.sh @@ -72,7 +72,7 @@ devices() { if [[ -n "$DEVICE" ]]; then echo "$DEVICE" else - curl ${CURL_OPTS} "$HOST:$CMDS_PORT/api/v2/device" | jq '[.[]|select(.labels[]=="LLRP")]' + curl ${CURL_OPTS} "$HOST:$CMDS_PORT/api/v2/device/all" | jq '[.deviceCoreCommands[]|select(.profileName | startswith("LLRP"))]' fi } @@ -84,20 +84,21 @@ put_file() { if [[ "$1" == "put" ]]; then CMD_NAME="${2}" else - CMD_NAME="${1^}${2}" + CMD_NAME="${2}" fi TYPE=${2} FILE_PATH="${3}" - devices | jq '.[].commands[]|select(.name=="'"$CMD_NAME"'")|.put.url' | \ + devices | jq '.[].coreCommands[]|select(.name=="'"$CMD_NAME"'")|.url+.path' | \ sed -e "s/edgex-core-command/${HOST}/" | \ xargs -L1 curl ${CURL_OPTS} -X PUT -H 'Content-Type: application/json' \ - --data '@'<(jq '.|{'"$TYPE"': @text}' "$FILE_PATH") + --data '@'<(echo "{\"${TYPE}\":$(<"$FILE_PATH")}") } put() { set -x - devices | jq '.[].commands[]|select(.name=="'"${2}"'")|.put.url' | \ + + devices | jq '.[].coreCommands[]|select(.name=="'"${2}"'")|.url+.path' | \ sed -e "s/edgex-core-command/${HOST}/" | \ xargs -L1 curl ${CURL_OPTS} -X PUT -H 'Content-Type: application/json' \ --data "${3}" @@ -108,12 +109,10 @@ put_num() { usage; exit fi - CMD_NAME="${1^}${2}" + CMD_NAME="${1}${2}" TYPE="${2}ID" NUM="${3}" - - devices | jq '.[].commands[]|select(.name=="'"$CMD_NAME"'")|.put.url' | \ - sed -e "s/edgex-core-command/${HOST}/" | \ + devices | jq '.[].coreCommands[]|select(.name=="'"$CMD_NAME"'")|.url+.path' | sed -e "s/edgex-core-command/${HOST}/" | \ xargs -L1 curl ${CURL_OPTS} -X PUT -H 'Content-Type: application/json' \ --data '{"'"$TYPE"'": "'"$NUM"'"}' } @@ -126,12 +125,12 @@ get() { if [[ "$1" == "pull" ]]; then CMD_NAME="${2}" else - CMD_NAME="Get${1}" + CMD_NAME="${1}" fi - devices | jq '.[].commands[]|select(.name=="'"$CMD_NAME"'")|.get.url' | \ + devices | jq '.[].coreCommands[]|select(.name=="'"$CMD_NAME"'") | .url+.path' | \ sed -e "s/edgex-core-command/${HOST}/" | \ - xargs -L1 curl ${CURL_OPTS} | jq '.readings[].value|fromjson' + xargs -L1 curl ${CURL_OPTS} | jq '.event.readings[].objectValue' } list() { @@ -142,10 +141,10 @@ list() { case "$1" in devices) - devices | jq '.[].name' | tr -d '"' + devices | jq '.[].deviceName' | tr -d '"' ;; commands) - devices | jq '.[].commands[]|{name, url:(.get.url // .put.url), get:(.get.path!=null),put:(.put.path!=null)}' | \ + devices | jq '.[].coreCommands[]' | \ jq -s '.|=.' ;; *) diff --git a/examples/data.sh b/examples/data.sh index d48745c3..a0d98f9e 100755 --- a/examples/data.sh +++ b/examples/data.sh @@ -74,8 +74,7 @@ fi # get up to 1000 readings from EdgeX's core-data and return reading[].value as unquoted json get() { TARGET=$1 - curl ${CURL_OPTS} "${HOST}":"${DATA_PORT}"/api/v2/reading/name/"${TARGET}"/1000 | \ - jq '.[].value|fromjson' + curl ${CURL_OPTS} "${HOST}":"${DATA_PORT}"/api/v2/reading/all?limit=50 | jq '.readings[].objectValue' } # based on the target, get some data and filter it diff --git a/examples/example.sh b/examples/example.sh index 35f9b6b8..9cdd2729 100755 --- a/examples/example.sh +++ b/examples/example.sh @@ -20,7 +20,7 @@ set -euo pipefail IFS=$'\n\t' # Get the first device -device=$(curl -so- ${HOST}:${META_PORT}/api/v2/device/servicename/device-rfid-llrp | jq '.[0].name' | tr -d '"') +device=$(curl -so- ${HOST}:${META_PORT}/api/v2/device/all | jq '[.devices[]|select(.serviceName=="device-rfid-llrp" )]' | jq '.[0].name' | tr -d '"') dev_url=${HOST}:${CMDS_PORT}/api/v2/device/name/${device} echo "Using ${dev_url}" @@ -28,37 +28,37 @@ echo "Using ${dev_url}" # Add an ROSpec echo "Adding ROSpec ${ROSPEC_LOCATION}" -curl -so- "${dev_url}" | jq '.commands[]|select(.name=="AddROSpec")|.put.url' | sed -e "s/edgex-core-command/${HOST}/" | xargs -L1 \ - curl -so- -X PUT -H 'Content-Type: application/json' --data '@'<(jq '.|{ROSpec: @text}' "${ROSPEC_LOCATION}") +curl -so- "${dev_url}" | jq '.deviceCoreCommand.coreCommands[]|select(.name=="ROSpec")|.url+.path' | sed -e "s/edgex-core-command/${HOST}/" | xargs -L1 \ + curl -so- -X PUT -H 'Content-Type: application/json' --data '@'<(echo "{\"ROSpec\":$(<"$ROSPEC_LOCATION")}") # Get ROSpecs echo "Getting ROSpecs from Reader" -curl -so- "${dev_url}" | jq '.commands[]|select(.name=="GetROSpec")|.get.url' | sed -e "s/edgex-core-command/${HOST}/" | xargs -L1 \ - curl -so- | jq '.readings[0].value|fromjson' - +curl -so- "${dev_url}" | jq '.deviceCoreCommand.coreCommands[]|select(.name=="ROSpec")|.url+.path' | sed -e "s/edgex-core-command/${HOST}/" | xargs -L1 \ + curl -so- | jq '.event.readings[].objectValue.ROSpecs' +​ # Enable ROSpec echo "Enabling ROSpec 1" -curl -so- "${dev_url}" | jq '.commands[]|select(.name=="EnableROSpec")|.put.url' | sed -e "s/edgex-core-command/${HOST}/" | xargs -L1 \ +curl -so- "${dev_url}" | jq '.deviceCoreCommand.coreCommands[]|select(.name=="enableROSpec")|.url+.path' | sed -e "s/edgex-core-command/${HOST}/" | xargs -L1 \ curl -so- -X PUT -H 'Content-Type: application/json' --data '{"ROSpecID": "1"}' - +​ # wait a bit for i in {10..1}; do echo "Waiting ${i} more seconds..." sleep 1 done - - +​ +​ # Disable ROSpec echo "Disabling ROSpec 1" -curl -so- "${dev_url}" | jq '.commands[]|select(.name=="DisableROSpec")|.put.url' | sed -e "s/edgex-core-command/${HOST}/" | xargs -L1 \ +curl -so- "${dev_url}" | jq '.deviceCoreCommand.coreCommands[]|select(.name=="disableROSpec")|.url+.path' | sed -e "s/edgex-core-command/${HOST}/" | xargs -L1 \ curl -so- -X PUT -H 'Content-Type: application/json' --data '{"ROSpecID": "1"}' - +​ # Delete ROSpec echo "Deleting ROSpec 1" -curl -so- "${dev_url}" | jq '.commands[]|select(.name=="DeleteROSpec")|.put.url' | sed -e "s/edgex-core-command/${HOST}/" | xargs -L1 \ +curl -so- "${dev_url}" | jq '.deviceCoreCommand.coreCommands[]|select(.name=="deleteROSpec")|.url+.path' | sed -e "s/edgex-core-command/${HOST}/" | xargs -L1 \ curl -so- -X PUT -H 'Content-Type: application/json' --data '{"ROSpecID": "1"}' - +​ # See collected EPCs (assuming EPC96) echo "Displaying EPCs" -curl -so- ${HOST}:${DATA_PORT}/api/v2/reading/resourceName/ROAccessReport?limit=1000 | \ - jq '.[].value|fromjson|.TagReportData[]?.EPC96.EPC' | tr -d '"' | base64 -d | od --endian=big -t x2 -An -w12 -v | sort | uniq -c +curl -so- ${HOST}:${DATA_PORT}/api/v2/reading/all?limit=1000 | \ + jq '.readings[].objectValue.TagReportData[]?|.EPC96.EPC//.EPCData.EPC' | tr -d '"' | base64 -d | od --endian=big -t x2 -An -w12 -v | sort | uniq -c