- Added lib/signal_reader.py with SignalGpsReader, SignalMeteoReader, and SignalDepthReader that use PropertiesChanged signal subscriptions instead of polling via GetValue(), reducing D-Bus overhead at steady state. - Each reader discovers its service dynamically, seeds its cache with a one-shot GetValue, then relies on signals for all subsequent updates. - Refactored dbus-tides, dbus-windy-station, dbus-no-foreign-land, dbus-lightning, and dbus-meteoblue-forecast to import from the shared library, removing ~600 lines of duplicated _unwrap() helpers and per-service GPS/meteo/depth reader classes. - Updated install.sh for all five services to deploy signal_reader.py to /data/lib/ on the target device. - Updated build-package.sh for all five services to bundle signal_reader.py into the .tar.gz package. - Updated README.md with the new lib/ entry in the project table and documented the shared D-Bus readers pattern. - Bumped version numbers in affected services (e.g. nfl_tracking 2.0.1). Made-with: Cursor
191 lines
5.9 KiB
Bash
191 lines
5.9 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Installation script for Meteoblue Forecast on Venus OS
|
|
#
|
|
# Run this on the Venus OS device after copying files to /data/dbus-meteoblue-forecast/
|
|
#
|
|
# Usage:
|
|
# chmod +x install.sh
|
|
# ./install.sh
|
|
#
|
|
|
|
set -e
|
|
|
|
INSTALL_DIR="/data/dbus-meteoblue-forecast"
|
|
|
|
# Find velib_python
|
|
VELIB_DIR=""
|
|
if [ -d "/opt/victronenergy/velib_python" ]; then
|
|
VELIB_DIR="/opt/victronenergy/velib_python"
|
|
else
|
|
for candidate in \
|
|
"/opt/victronenergy/dbus-systemcalc-py/ext/velib_python" \
|
|
"/opt/victronenergy/dbus-generator/ext/velib_python" \
|
|
"/opt/victronenergy/dbus-mqtt/ext/velib_python" \
|
|
"/opt/victronenergy/dbus-digitalinputs/ext/velib_python" \
|
|
"/opt/victronenergy/vrmlogger/ext/velib_python"
|
|
do
|
|
if [ -d "$candidate" ] && [ -f "$candidate/vedbus.py" ]; then
|
|
VELIB_DIR="$candidate"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
|
|
if [ -z "$VELIB_DIR" ]; then
|
|
VEDBUS_PATH=$(find /opt/victronenergy -name "vedbus.py" -path "*/velib_python/*" 2>/dev/null | head -1)
|
|
if [ -n "$VEDBUS_PATH" ]; then
|
|
VELIB_DIR=$(dirname "$VEDBUS_PATH")
|
|
fi
|
|
fi
|
|
|
|
# Determine service directory
|
|
if [ -d "/service" ] && [ ! -L "/service" ]; then
|
|
SERVICE_DIR="/service"
|
|
elif [ -d "/opt/victronenergy/service" ]; then
|
|
SERVICE_DIR="/opt/victronenergy/service"
|
|
elif [ -L "/service" ]; then
|
|
SERVICE_DIR=$(readlink -f /service)
|
|
else
|
|
SERVICE_DIR="/opt/victronenergy/service"
|
|
fi
|
|
|
|
echo "=================================================="
|
|
echo "Meteoblue Forecast - Installation"
|
|
echo "=================================================="
|
|
|
|
if [ ! -d "$SERVICE_DIR" ]; then
|
|
echo "ERROR: This doesn't appear to be a Venus OS device."
|
|
echo " Service directory not found."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Detected service directory: $SERVICE_DIR"
|
|
|
|
if [ ! -f "$INSTALL_DIR/meteoblue_forecast.py" ]; then
|
|
echo "ERROR: Installation files not found in $INSTALL_DIR"
|
|
echo " Please copy all files to $INSTALL_DIR first."
|
|
exit 1
|
|
fi
|
|
if [ ! -f "$INSTALL_DIR/service/run" ]; then
|
|
echo "ERROR: service/run not found. The package is incomplete."
|
|
exit 1
|
|
fi
|
|
|
|
echo "1. Making scripts executable..."
|
|
chmod +x "$INSTALL_DIR/service/run"
|
|
chmod +x "$INSTALL_DIR/service/log/run"
|
|
chmod +x "$INSTALL_DIR/meteoblue_forecast.py"
|
|
|
|
echo "2. Creating velib_python symlink..."
|
|
if [ -z "$VELIB_DIR" ]; then
|
|
echo "ERROR: Could not find velib_python on this system."
|
|
exit 1
|
|
fi
|
|
echo " Found velib_python at: $VELIB_DIR"
|
|
mkdir -p "$INSTALL_DIR/ext"
|
|
if [ -L "$INSTALL_DIR/ext/velib_python" ]; then
|
|
CURRENT_TARGET=$(readlink "$INSTALL_DIR/ext/velib_python")
|
|
if [ "$CURRENT_TARGET" != "$VELIB_DIR" ]; then
|
|
echo " Updating symlink (was: $CURRENT_TARGET)"
|
|
rm "$INSTALL_DIR/ext/velib_python"
|
|
fi
|
|
fi
|
|
if [ ! -L "$INSTALL_DIR/ext/velib_python" ]; then
|
|
ln -s "$VELIB_DIR" "$INSTALL_DIR/ext/velib_python"
|
|
echo " Symlink created: $INSTALL_DIR/ext/velib_python -> $VELIB_DIR"
|
|
else
|
|
echo " Symlink already exists"
|
|
fi
|
|
|
|
echo "3. Installing shared library..."
|
|
SHARED_LIB_DIR="/data/lib"
|
|
mkdir -p "$SHARED_LIB_DIR"
|
|
SIGNAL_READER=""
|
|
if [ -f "$INSTALL_DIR/signal_reader.py" ]; then
|
|
SIGNAL_READER="$INSTALL_DIR/signal_reader.py"
|
|
elif [ -f "$(dirname "$INSTALL_DIR")/lib/signal_reader.py" ]; then
|
|
SIGNAL_READER="$(dirname "$INSTALL_DIR")/lib/signal_reader.py"
|
|
fi
|
|
if [ -n "$SIGNAL_READER" ]; then
|
|
cp "$SIGNAL_READER" "$SHARED_LIB_DIR/"
|
|
echo " Installed signal_reader.py to $SHARED_LIB_DIR"
|
|
elif [ -f "$SHARED_LIB_DIR/signal_reader.py" ]; then
|
|
echo " signal_reader.py already installed"
|
|
else
|
|
echo "WARNING: signal_reader.py not found."
|
|
echo " Copy lib/signal_reader.py to $SHARED_LIB_DIR/ manually."
|
|
fi
|
|
|
|
echo "4. Creating service symlink..."
|
|
if [ -L "$SERVICE_DIR/dbus-meteoblue-forecast" ]; then
|
|
echo " Service link already exists, removing old link..."
|
|
rm "$SERVICE_DIR/dbus-meteoblue-forecast"
|
|
fi
|
|
if [ -e "$SERVICE_DIR/dbus-meteoblue-forecast" ]; then
|
|
rm -rf "$SERVICE_DIR/dbus-meteoblue-forecast"
|
|
fi
|
|
ln -s "$INSTALL_DIR/service" "$SERVICE_DIR/dbus-meteoblue-forecast"
|
|
|
|
if [ -L "$SERVICE_DIR/dbus-meteoblue-forecast" ]; then
|
|
echo " Symlink created: $SERVICE_DIR/dbus-meteoblue-forecast -> $INSTALL_DIR/service"
|
|
else
|
|
echo "ERROR: Failed to create service symlink"
|
|
exit 1
|
|
fi
|
|
|
|
echo "5. Creating log directory..."
|
|
mkdir -p /var/log/dbus-meteoblue-forecast
|
|
|
|
echo "6. Setting up rc.local for persistence..."
|
|
RC_LOCAL="/data/rc.local"
|
|
if [ ! -f "$RC_LOCAL" ]; then
|
|
echo "#!/bin/bash" > "$RC_LOCAL"
|
|
chmod +x "$RC_LOCAL"
|
|
fi
|
|
|
|
if ! grep -q "dbus-meteoblue-forecast" "$RC_LOCAL"; then
|
|
echo "" >> "$RC_LOCAL"
|
|
echo "# Meteoblue Forecast" >> "$RC_LOCAL"
|
|
echo "if [ ! -L $SERVICE_DIR/dbus-meteoblue-forecast ]; then" >> "$RC_LOCAL"
|
|
echo " ln -s /data/dbus-meteoblue-forecast/service $SERVICE_DIR/dbus-meteoblue-forecast" >> "$RC_LOCAL"
|
|
echo "fi" >> "$RC_LOCAL"
|
|
echo " Added to rc.local for persistence across firmware updates"
|
|
else
|
|
echo " Already in rc.local"
|
|
fi
|
|
|
|
echo "7. Activating service..."
|
|
sleep 2
|
|
if command -v svstat >/dev/null 2>&1; then
|
|
if svstat "$SERVICE_DIR/dbus-meteoblue-forecast" 2>/dev/null | grep -q "up"; then
|
|
echo " Service is running"
|
|
else
|
|
echo " Waiting for service to start..."
|
|
sleep 3
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
echo "=================================================="
|
|
echo "Installation complete!"
|
|
echo "=================================================="
|
|
echo ""
|
|
|
|
if command -v svstat >/dev/null 2>&1; then
|
|
echo "Current status:"
|
|
svstat "$SERVICE_DIR/dbus-meteoblue-forecast" 2>/dev/null || echo " Service not yet detected by svscan"
|
|
echo ""
|
|
fi
|
|
|
|
echo "IMPORTANT: Configure your Meteoblue API key:"
|
|
echo " 1. Edit $INSTALL_DIR/forecast_config.json"
|
|
echo " 2. Or use MQTT: W/<vrm-id>/meteoblueforecast/0/Settings/ApiKey"
|
|
echo ""
|
|
echo "To check status:"
|
|
echo " svstat $SERVICE_DIR/dbus-meteoblue-forecast"
|
|
echo ""
|
|
echo "To view logs:"
|
|
echo " tail -F /var/log/dbus-meteoblue-forecast/current | tai64nlocal"
|
|
echo ""
|