Skip to content

Commit c00d755

Browse files
committed
install grott proxy server
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
1 parent 1e4e300 commit c00d755

3 files changed

Lines changed: 262 additions & 0 deletions

File tree

functions/grott-install.bash

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/usr/bin/env bash
2+
3+
## Install the Grott proxy server on the current system
4+
##
5+
## install_grott(String openhab-ip-address, String username, String interactive)
6+
##
7+
install_grott() {
8+
# Validate install type argument
9+
if [ "$#" -lt 1 ]; then
10+
echo "Error: Please supply install type."
11+
echo "Usage: $0 <install|remove> <username> (<openhab-ip>)"
12+
exit 1
13+
elif [[ "$1" != "install" && "$1" != "remove" ]]; then
14+
echo "Error: Invalid install type '$1'. Use 'install' or 'remove'."
15+
exit 1
16+
fi
17+
INSTALL_TYPE="$1"
18+
19+
# Validate user name argument
20+
if [ "$#" -lt 2 ]; then
21+
echo "Error: Please supply user name."
22+
echo "Usage: $0 <install|remove> <username> (<openhab-ip>)"
23+
exit 1
24+
elif ! id "$2" &>/dev/null; then
25+
echo "Error: User '$2' does not exist."
26+
exit 1
27+
fi
28+
USERNAME="$2"
29+
INSTALL_DIR="/home/$USERNAME/grott"
30+
31+
SERVICE_FILE="/etc/systemd/system/grott.service"
32+
33+
if [[ $INSTALL_TYPE == "install" ]]; then
34+
# Validate openhab ip address argument
35+
if [ "$#" -lt 3 ]; then
36+
echo "Error: Please supply openHAB IP address."
37+
echo "Usage: $0 <install|remove> <username> <openhab-ip>"
38+
exit 1
39+
elif ! [[ "$3" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
40+
echo "Error: Invalid IP address format: $3"
41+
exit 1
42+
fi
43+
EXT_URL="http://$3:8080/growatt"
44+
45+
echo -n "[openHABian] Installing Grott Proxy with extension URL: $EXT_URL "
46+
47+
# Update system and install dependencies
48+
sudo apt update
49+
sudo apt install -y python3 python3-pip
50+
sudo pip3 install paho-mqtt requests # paho-mqtt is a required dependency (even if disabled)
51+
52+
# Prepare installation directory and pouplate it with Grott files
53+
sudo -u "$USERNAME" mkdir -p "$INSTALL_DIR"
54+
if [ ! -d "$INSTALL_DIR" ]; then
55+
echo "Error: Installation directory $INSTALL_DIR does not exist."
56+
exit 1
57+
fi
58+
59+
download_grott_files || {
60+
echo "Failed to download Grott files. Exiting."
61+
return 1
62+
}
63+
64+
# Create grott.service systemd file from template
65+
if ! sed -e "s|%INSTALL_DIR|$INSTALL_DIR|g" \
66+
-e "s|%USERNAME|$USERNAME|g" \
67+
"${BASEDIR:-/opt/openhabian}/includes/grott.service" > "$SERVICE_FILE"; then
68+
echo "FAILED (sed substitution)"
69+
return 1
70+
fi
71+
72+
# Create grott.ini file from template
73+
if ! sed -e "s|%EXT_URL|$EXT_URL|g" \
74+
"${BASEDIR:-/opt/openhabian}/includes/grott.ini" > "$INSTALL_DIR/grott.ini"; then
75+
echo "FAILED (sed substitution)"
76+
return 1
77+
fi
78+
79+
# Enable and start service
80+
sudo systemctl daemon-reexec
81+
sudo systemctl enable grott
82+
sudo systemctl start grott
83+
84+
if [[ -n "$INTERACTIVE" ]]; then
85+
whiptail --title "Grott Proxy installed" --msgbox "We installed Grott Proxy on your system." 7 80
86+
fi
87+
88+
return 0
89+
90+
elif [[ $INSTALL_TYPE == "remove" ]]; then
91+
echo -n "[openHABian] Removing Grott Proxy... "
92+
93+
# Stop and disable systemd service
94+
if sudo systemctl is-active --quiet grott; then
95+
sudo systemctl stop grott
96+
fi
97+
98+
if sudo systemctl is-enabled --quiet grott; then
99+
sudo systemctl disable grott
100+
fi
101+
102+
# Remove systemd service file
103+
if [ -f "$SERVICE_FILE" ]; then
104+
sudo rm "$SERVICE_FILE"
105+
sudo systemctl daemon-reload
106+
fi
107+
108+
# Remove installation directory
109+
if [ -d "$INSTALL_DIR" ]; then
110+
sudo rm -rf "$INSTALL_DIR"
111+
echo "Removed $INSTALL_DIR"
112+
else
113+
echo "Directory $INSTALL_DIR not found."
114+
fi
115+
116+
if [[ -n "$INTERACTIVE" ]]; then
117+
whiptail --title "Grott Proxy removed" --msgbox "We removed Grott Proxy from your system." 7 80
118+
fi
119+
120+
return 0
121+
fi
122+
}
123+
124+
download_grott_files() {
125+
GROTT_FILE_URL="https://raw.githubusercontent.com/johanmeijer/grott/master"
126+
GROTT_PY_FILES=(
127+
"grott.py"
128+
"grottconf.py"
129+
"grottdata.py"
130+
"grottproxy.py"
131+
"grottserver.py"
132+
"grottsniffer.py"
133+
)
134+
135+
for file in "${GROTT_PY_FILES[@]}"; do
136+
FILE_URL="${GROTT_FILE_URL}/${file}"
137+
echo "Downloading $file..."
138+
curl -fsSL "$FILE_URL" -o "${INSTALL_DIR}/${file}" || {
139+
echo "Failed to download $file"
140+
return 1
141+
}
142+
done
143+
}

includes/grott.ini

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Specify grott monitor configuration
2+
# Defaults are described
3+
# Remove # and update the value to enable the setting
4+
# Last updated: 2022-11-04
5+
# Version 2.7.0
6+
7+
[Generic]
8+
# Specify verbose for extended messaging
9+
verbose = True
10+
11+
# Specify minrecl for debugging purposes only (default = 100)
12+
#minrecl = 100
13+
14+
# Specify mode (sniff or proxy)(> 2.1.0 proxy is default)
15+
mode = proxy
16+
17+
# Specify port and IP address to listen to (only proxy), default port 5279, 0.0.0.0 ==> own ip address
18+
ip = default
19+
port = 5279
20+
21+
# To blocks commands from outside (to channge inverter and shine devices settings) specify blockcmd = True,
22+
# Specify noipf = True if you still want be able to set the destination ip addres from growatt server (advice
23+
# only to use this for a short time)
24+
#blockcmd = True
25+
#noipf = True
26+
27+
# Time = auto/server parameter enable/disable date/time retrieval from data record (server), default is
28+
# auto: grott decides which time is used (data record if valid otherwise Server)
29+
# If time = server Grott server time is alwas used
30+
#time = auto
31+
32+
# Sendbuf = True / False parameter to enable / disable sending historical (buffered) data. Default is sendbuf = True.
33+
#sendbuf = True
34+
35+
# Compat is True and valoffset needs to be set if offset / growatt protocol has been changed.
36+
compat = False
37+
#valueoffset = 6
38+
39+
# Specify inverter id (not necessary in version >2.1.0 if compat = false!)
40+
#inverterid = KUM0CLU03Y
41+
# Specify the type of the inverter (default/sph/spf/max)
42+
invtype = sph
43+
44+
# Decrypt is False if growatt communication is not encrypted (older inverters), (not necessary in version
45+
# >2.1.0 if compat = false!)
46+
#decrypt = True
47+
48+
[Growatt]
49+
# Server name/IP address and port of Growatt server
50+
# specify only if the IP address of server.growatt.com is changed
51+
# The address as of Nov 2022 is 47.91.67.66
52+
53+
ip = server.growatt.com
54+
#ip = 47.91.67.66
55+
#port = 5279
56+
57+
[MQTT]
58+
# Mqtt parameters definitions
59+
# Be aware nomqtt = True means no MQTT processing will be done!!!!!!
60+
61+
nomqtt = True
62+
#ip = localhost
63+
#port = 1883
64+
#topic= energy/growatt
65+
#auth = False
66+
#user = grott
67+
#password = growatt2020
68+
69+
[PVOutput]
70+
# PVOutput parameters definitions
71+
72+
pvoutput = False
73+
#apikey = yourapikey
74+
# Data upload limit (in minutes)
75+
#pvuplimit = 5
76+
# Use this if you have one inverter
77+
#systemid = 12345
78+
79+
# Use this if you have multiple inverters
80+
#pvinverters = 2
81+
#systemid1 = 12345
82+
#inverterid1 = inverter1
83+
#systemid2 = 67890
84+
#inverterid2 = inverter2
85+
86+
#systemid99 = 99999
87+
#inverterid99 = inverter99
88+
89+
[influx]
90+
# Influxdb parameters definitions
91+
92+
#influx = False
93+
#influx2 = False
94+
#dbname = grottdb
95+
#ip = localhost
96+
#port = 8086
97+
#user = grott
98+
#password = growatt2020
99+
#token = "influx_token"
100+
#org = "grottorg"
101+
#bucket = "grottdb"
102+
103+
[extension]
104+
# grott extension parameters definitions
105+
extension = True
106+
extname = grottext
107+
extvar = {"url": "%EXT_URL"}

includes/grott.service

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=Grott Proxy Service
3+
After=network.target
4+
5+
[Service]
6+
ExecStart=/usr/bin/python3 -u %INSTALL_DIR/grott.py -v
7+
WorkingDirectory=%INSTALL_DIR
8+
Restart=on-failure
9+
User=%USERNAME
10+
11+
[Install]
12+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)