Last active
September 3, 2018 02:25
-
-
Save coisme/ece06f35e875129f7763a2832efabd0c to your computer and use it in GitHub Desktop.
Pelion Service API; Pull Notification Example Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample Output: