This repository has been archived by the owner on Aug 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lamp.sh
executable file
·92 lines (86 loc) · 1.75 KB
/
lamp.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# In The Name Of God
# ========================================
# [] File Name : lamp.sh
#
# [] Creation Date : 21-09-2016
#
# [] Improved By : Iman Tabrizian (tabrizian@outlook.com)
#
# [] Created By : Parham Alvani (parham.alvani@gmail.com)
# =======================================
i1820_address=${1:-"192.168.128.90"}
node_id=${2:-"066156d8-df62-5894-809b-d51ec5a2ff3d"}
echo "[I1820] using $i1820_address as I1820 server"
echo "[I1820] using $node_id as your target RPi ID."
# Trun
# parameter 1: lamp node - string
# parameter 2: lamp identification - string
# parameter 3: true -> on | false -> off - bool
turn() {
curl -X PUT -H "Content-Type: application/json" -d "{
\"type\": \"lamp\",
\"rpi_id\": \"$node_id\",
\"device_id\": \"$1:$2\",
\"settings\": {
\"on\": $3
}
}" "$i1820_address:8080/thing"
echo ""
echo "=============================================================================="
sleep 2
}
bandari() {
for i in $(seq 1 9); do
turn 1 $i true
turn 2 $i true
done
for i in $(seq 1 9); do
turn 1 $i false
turn 2 $i false
done
}
zabdari() {
turn 1 1 true
turn 2 1 true
turn 1 5 true
turn 2 5 true
turn 1 9 true
turn 2 9 true
turn 1 7 true
turn 2 7 true
turn 1 3 true
turn 2 3 true
turn 1 1 false
turn 2 1 false
turn 1 5 false
turn 2 5 false
turn 1 9 false
turn 2 9 false
turn 1 7 false
turn 2 7 false
turn 1 3 false
turn 2 3 false
}
oPS3=$PS3
PS3="[I1820] Please choose your way [ENTER to list options]:"
select t in "Let's do a bandari" "Let's do a zabdari" "Quit"; do
if [ ! -z "$t" ]; then
case $REPLY in
1)
bandari
break
;;
2)
zabdari
break
;;
3)
exit
;;
esac
else
echo "$REPLY in not a valid option"
fi
done
PS3=$oPS3