-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpp-solar-setup
executable file
·133 lines (102 loc) · 2.81 KB
/
mpp-solar-setup
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
echo "Remember to modify this script to use your current MQTT connection details and the correct /dev/hidraw# numbers."
read -n1 -r -p "Do you want to continue? (Y/N) [Default: No]: "
if [[ $REPLY =~ ^[Yy]$ ]]; then
# User chose Y, so execute the rest of the script
echo "Continuing..."
else
# User chose N or didn't respond, so exit the script
echo "Aborted."
exit 1
fi
sudo usermod -a -G plugdev $USER
sudo sh -c 'cat <<\EOF >/etc/udev/rules.d/99-hidraw.rules
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0660", GROUP="plugdev"
EOF'
echo "Installing mppsolar package with pip..."
sudo apt update
sudo apt install python3-pip python3-dev libpq-dev python3-systemd libglib2.0-dev
sudo pip install mppsolar
sleep 3
echo "Creating /etc/mpp-solar/mpp-solar.conf"
echo "Please modify /etc/mpp-solar/mpp-solar.conf"
sleep 3
sudo mkdir -p /etc/mpp-solar
sudo sh -c 'cat <<\EOF >/etc/mpp-solar/mpp-solar.conf
[SETUP]
# Number of seconds to pause between command execution loop
# 0 is no pause, greater than 60 will cause service restarts
pause=5
mqtt_broker=192.168.0.2
mqtt_user=user
mqtt_pass=pass
# This example would work on a single LV5048
[Inverter1_LV5048]
protocol=PI41
port=/dev/hidraw1
baud=2400
command=QPGS0
tag=LV5048
outputs=hass_mqtt
[Inverter2_LV5048]
protocol=PI41
port=/dev/hidraw1
baud=2400
command=QP2GS0
tag=LV5048
outputs=hass_mqtt
[Inverter3_LV6048]
protocol=PI41
port=/dev/hidraw2
baud=2400
command=QPGS0
tag=LV6048
outputs=hass_mqtt
[Inverter4_LV6048]
protocol=PI41
port=/dev/hidraw2
baud=2400
command=QP2GS0
tag=LV6048
outputs=hass_mqtt
EOF'
sleep 3
echo "Creating /etc/systemd/user/mpp-solar.service"
echo "Please modify /etc/systemd/user/mpp-solar.service"
sleep 3
sudo sh -c 'cat <<\EOF >/etc/systemd/user/mpp-solar.service
# systemd unit file for the MPP-Solar Service
#
# needs to go to /etc/systemd/user/*
[Unit]
# Human readable name of the unit
Description=MPP Solar Service
[Service]
# Command to execute when the service is started
ExecStart=/usr/bin/python3 /usr/local/bin/mpp-solar -C /etc/mpp-solar/mpp-solar.conf --daemon
# Disable Python buffering of STDOUT and STDERR, so that output from the
# service shows up immediately in systemd logs
Environment=PYTHONUNBUFFERED=1
# Automatically restart the service if it crashes
Restart=always
WatchdogSec=300
# Our service will notify systemd once it is up and running
Type=notify
# Use a dedicated user to run our service
# User=mpp_service
[Install]
# Tell systemd to automatically start this service when the system boots
# (assuming the service is enabled)
WantedBy=default.target
EOF'
sleep 3
systemctl --user list-unit-files|grep mpp-solar
sleep 3
systemctl --user start mpp-solar
sleep 3
systemctl --user enable mpp-solar
sleep 3
sudo loginctl enable-linger $USER
sleep 3
systemctl --user list-unit-files | grep mpp-solar
echo "Finished"