Skip to content

Commit

Permalink
fix: updated example scripts to work with current changes of edgex (#74)
Browse files Browse the repository at this point in the history
Signed-off-by: Marc-Philippe Fuller <[email protected]>
  • Loading branch information
marcpfuller authored Apr 22, 2022
1 parent 8b44d22 commit 5b207c8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
27 changes: 13 additions & 14 deletions examples/command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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}"
Expand All @@ -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"'"}'
}
Expand All @@ -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() {
Expand All @@ -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 '.|=.'
;;
*)
Expand Down
3 changes: 1 addition & 2 deletions examples/data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions examples/example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,45 @@ 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}"


# 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

0 comments on commit 5b207c8

Please sign in to comment.