-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·175 lines (152 loc) · 5.19 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·175 lines (152 loc) · 5.19 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
set -e
# Installation script for TriStar MPPT driver
# For Venus OS v3.4+ (including v3.67)
# Uses CORRECT daemontools structure with persistent storage
SERVICE_NAME=dbus-tristar
SCRIPT_NAME=dbus_tristar.py
# Persistent directories (survive firmware updates)
INSTALL_DIR=/data/$SERVICE_NAME
SERVICE_DIR=/data/etc/sv/$SERVICE_NAME
LOG_DIR=/data/log/$SERVICE_NAME
echo "================================================================"
echo "TriStar MPPT Driver Installation (Venus OS v3.4+)"
echo "================================================================"
echo ""
echo "Modern Python driver - zero compilation, easy configuration."
echo "NO QML files needed - configure via D-Bus command line."
echo ""
# Create installation directory for scripts
echo "Creating installation directory: $INSTALL_DIR"
mkdir -p $INSTALL_DIR
# Copy driver
echo "Installing driver..."
cp $SCRIPT_NAME $INSTALL_DIR/
chmod +x $INSTALL_DIR/$SCRIPT_NAME
# Create service directory structure (daemontools persistent)
echo "Setting up persistent service structure..."
mkdir -p $SERVICE_DIR/log
mkdir -p $LOG_DIR
# Create run script (main service with vrmlogger dependency)
cat > $SERVICE_DIR/run << 'EOF'
#!/bin/sh
echo "*** starting dbus-tristar ***"
# Wait for vrmlogger to be running (max 30 seconds)
echo "Waiting for vrmlogger to start..."
COUNTER=0
while [ $COUNTER -lt 30 ]; do
if svstat /service/vrmlogger 2>/dev/null | grep -q "up"; then
echo "vrmlogger is running, proceeding..."
sleep 2 # Extra 2 seconds to ensure vrmlogger has done service discovery
break
fi
sleep 1
COUNTER=$((COUNTER + 1))
done
if [ $COUNTER -ge 30 ]; then
echo "WARNING: vrmlogger not detected after 30 seconds, starting anyway..."
fi
exec 2>&1
exec python3 -u /data/dbus-tristar/dbus_tristar.py
EOF
chmod +x $SERVICE_DIR/run
# Create log run script
cat > $SERVICE_DIR/log/run << 'EOF'
#!/bin/sh
exec 2>&1
exec multilog t s25000 n4 /data/log/dbus-tristar
EOF
chmod +x $SERVICE_DIR/log/run
echo "✓ Service structure created"
# Setup rc.local for automatic symlink restoration on boot
RC_LOCAL=/data/rc.local
if [ ! -f $RC_LOCAL ]; then
echo "Creating /data/rc.local..."
cat > $RC_LOCAL << 'EOF'
#!/bin/sh
# Re-create service symlinks at boot (persistent across reboots)
ln -sf /data/etc/sv/dbus-tristar /service/dbus-tristar
exit 0
EOF
chmod +x $RC_LOCAL
echo "✓ Created /data/rc.local"
else
# Check if our service is already in rc.local
if ! grep -q "dbus-tristar" $RC_LOCAL; then
echo "Adding dbus-tristar to existing /data/rc.local..."
# Insert before 'exit 0'
sed -i '/^exit 0/i ln -sf /data/etc/sv/dbus-tristar /service/dbus-tristar' $RC_LOCAL
echo "✓ Added to /data/rc.local"
else
echo "✓ Already in /data/rc.local"
fi
fi
# Create symlink (starts service immediately)
echo "Creating service symlink..."
if [ -L /service/$SERVICE_NAME ]; then
rm /service/$SERVICE_NAME
fi
ln -sf $SERVICE_DIR /service/$SERVICE_NAME
echo "✓ Service symlink created"
# Install Python dependencies if not present
if ! python3 -c "import pymodbus" 2>/dev/null; then
echo "Installing pymodbus..."
opkg update
opkg install python3-pymodbus
else
echo "✓ pymodbus already installed"
fi
# Wait for service to start
echo ""
echo "Waiting for service to start..."
sleep 5
# Check service status
echo ""
echo "Service status:"
svstat /service/$SERVICE_NAME
echo ""
echo "================================================================"
echo "✓ Installation complete!"
echo "================================================================"
echo ""
echo "STRUCTURE:"
echo " Driver: $INSTALL_DIR/$SCRIPT_NAME"
echo " Service: $SERVICE_DIR/ (persistent)"
echo " Logs: $LOG_DIR/current"
echo " Autostart: /data/rc.local"
echo " Symlink: /service/$SERVICE_NAME → $SERVICE_DIR"
echo ""
echo "📋 NEXT STEP: Configure via D-Bus command line"
echo ""
echo "Set TriStar IP address (REQUIRED):"
echo " dbus -y com.victronenergy.settings /Settings/TristarMPPT/IPAddress SetValue \"YOUR_IP_HERE\""
echo ""
echo "Optional settings (with defaults):"
echo " dbus -y com.victronenergy.settings /Settings/TristarMPPT/PortNumber SetValue 502"
echo " dbus -y com.victronenergy.settings /Settings/TristarMPPT/Interval SetValue 5000"
echo " dbus -y com.victronenergy.settings /Settings/TristarMPPT/SlaveID SetValue 1"
echo " dbus -y com.victronenergy.settings /Settings/TristarMPPT/DeviceInstance SetValue 0"
echo ""
echo "After configuring, restart the driver:"
echo " svc -t /service/$SERVICE_NAME"
echo ""
echo "📊 Verification:"
echo ""
echo "Check service status:"
echo " svstat /service/$SERVICE_NAME"
echo ""
echo "Check logs:"
echo " tail -f $LOG_DIR/current"
echo ""
echo "Check logs with timestamps:"
echo " tail -f $LOG_DIR/current | tai64nlocal"
echo ""
echo "Check D-Bus registration:"
echo " dbus -y com.victronenergy.solarcharger.tristar_0 /ProductName GetValue"
echo ""
echo "Check current values:"
echo " dbus -y com.victronenergy.solarcharger.tristar_0 /Dc/0/Voltage GetValue"
echo " dbus -y com.victronenergy.solarcharger.tristar_0 /Yield/Power GetValue"
echo ""
echo "✅ Service will AUTO-START after reboot (configured in /data/rc.local)"
echo ""