-
Notifications
You must be signed in to change notification settings - Fork 0
/
deye_read_exec.sh
65 lines (54 loc) · 1.62 KB
/
deye_read_exec.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
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#set -e / set -u stop scripts if something is wrong
set -e
set -u
# Script: deye_read_exec.sh
# Author: Tobias Baumann aka RaptorSDS
# License: MIT
# with help of OpenAI GPT-3.5 and VZlogger Group
# idee by script for KOSTAL_Pico JSON VZlogger exec
# Function to display script usage
usage() {
echo "Usage: $0 <hostname> <reading1> <reading2> ..."
exit 1
}
# Validate required arguments
if [ "$#" -lt 2 ]; then
usage
fi
# Extract hostname
HOSTNAME="$1"
shift
# Extract readings
READINGS="$*"
user="admin"
password="admin"
# Request values based on input readings
for READING in $READINGS; do
if [ "$READING" == "ACTUAL" ]; then
ACTUAL=$(/usr/local/bin/mi600 "$HOSTNAME" "$user" "$password" webdata_now_p)
#Remove end SPACE-Char
ACTUAL_NUM=$(($ACTUAL))
OUTPUT="$ACTUAL_NUM"
printf "%s = %s\n" "$READING" "$OUTPUT"
elif [ "$READING" == "TOTAL" ]; then
TOTAL=$(/usr/local/bin/mi600 "$HOSTNAME" "$user" "$password" webdata_total_e)
##Remove end SPACE-Char
TOTAL_NUM=$(echo "$TOTAL" | sed 's/[[:space:]]*$//')
OUTPUT="$TOTAL_NUM"
if [ $TOTAL_NUM == "0.0" ] || [ $TOTAL_NUM == "0" ] ; then
printf "%s = %s\n" "undefine" "$OUTPUT"
else
printf "%s = %s\n" "$READING" "$OUTPUT"
fi
elif [ "$READING" == "DAY" ]; then
DAY=$(/usr/local/bin/mi600 "$HOSTNAME" "$user" "$password" webdata_today_e)
##Remove end SPACE-Char
DAY_NUM=$(echo "$DAY" | sed 's/[[:space:]]*$//')
OUTPUT="$DAY_NUM"
printf "%s = %s\n" "$READING" "$OUTPUT"
else
echo "Invalid reading: $READING"
fi
done