Skip to content

Instantly share code, notes, and snippets.

@coisme
Last active September 3, 2018 02:25
Show Gist options
  • Save coisme/ece06f35e875129f7763a2832efabd0c to your computer and use it in GitHub Desktop.
Save coisme/ece06f35e875129f7763a2832efabd0c to your computer and use it in GitHub Desktop.
Pelion Service API; Pull Notification Example Script
#!/bin/tcsh
set apiKey="<< YOUR API KEY >>"
set deviceId="<< DEVICE ID >>" # Endpoint Name
set resourcePath="3200/0/5501"
while(1)
# Show current time
date +"%I:%M:%S"
# Read from a resource (asynchronous)
set responseCode=`\
curl -s -X GET -w "%{http_code}\n"\
-o body.tmp \
"https://api.us-east-1.mbedcloud.com/v2/endpoints/${deviceId}/${resourcePath}" \
-H "authorization: Bearer ${apiKey}"`
if(${responseCode} == 202) then
# 202 Accepted. Returns an asynchronous response ID.
set value=`\
curl -s -X GET \
https://api.us-east-1.mbedcloud.com/v2/notification/pull \
-H "authorization: Bearer ${apiKey}" \
| python -m json.tool \
| grep 'payload' \
| awk -F':' '{print $2}' \
| sed 's/\}//g' \
| sed 's/\"//g' \
| base64 --decode`
echo "${value}"
else if(${responseCode} == 200) then
# 200 Resource value found in cache. Returns the string value of the resource.
set cachedValue=`cat body.tmp`
echo "${cachedValue} (cached)"
else
echo "${responseCode} Unexpected."
endif
# new line
echo
sleep 5
end
@coisme
Copy link
Author

coisme commented Aug 30, 2018

Sample Output:

{
    "async-responses": [
        {
            "ct": "text/plain",
            "id": "2b4090fb-b85f-4842-afca-72e5d7948ddf",
            "max-age": 0,
            "payload": "NA==",
            "status": 200
        }
    ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment