-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceive.sh
41 lines (32 loc) · 917 Bytes
/
receive.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh
## script to parse JSON commands received from the Losant Cloud Platform
# include the json sh library
. /usr/share/libubox/jshn.sh
# function to parse messages received from Losant
parseReceived () {
# parse received json
json_init
json_load $1
# read the command and arguments
json_get_var cmd name
json_get_var argument payload
# take action based on the command
if [ "$cmd" == "expled" ]; then
handleExpLed $argument
fi
## YOUR TURN - IF: extend this 'if' statement with your custom command that calls your very own handler function
}
# program the Expansion Dock LED - handler for the 'expled' command
handleExpLed () {
# only call expled if an argument is present
colour="$1"
if [ "$colour" != "" ]; then
expled $colour > /dev/null
fi
}
## YOUR TURN - HANDLER: add your own handler functions
# main script - loop reading stdin
while read input
do
parseReceived $input
done