-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathixiMessageHandler.sh
More file actions
39 lines (35 loc) · 1023 Bytes
/
ixiMessageHandler.sh
File metadata and controls
39 lines (35 loc) · 1023 Bytes
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
#!/usr/bin/env bash
. helpers.sh
GPIO_PIN=4
pinctrl set $GPIO_PIN op pu dl
# Listen for MQTT messages
mosquitto_sub -t "Chat/#" | while read -r message; do
# Parse JSON message
data=$(echo "$message" | jq -rc '[.sender,.data.data] | @tsv')
sender=$(echo "$data" | awk '{print $1}')
cmd=$(echo "$data" | awk '{print tolower($2)}')
args="$(echo "$data" | cut -f2-)"
case "$cmd" in
on)
pinctrl set $GPIO_PIN op pu dh
;;
off)
pinctrl set $GPIO_PIN op pu dl
;;
temp)
temp "$sender"
;;
wifi)
wifi "$sender" "${args[@]}"
;;
contacts)
contacts "$sender" "${args[@]}"
;;
help)
send_message "$sender" "Commands: on, off, temp, wifi [add/remove/list], contacts [accept/add/remove/list], help"
;;
*)
send_message "$sender" "Unknown command, use help for more info."
;;
esac
done