From 0143e8eb367af41f2299541e5a4191b7f9448e00 Mon Sep 17 00:00:00 2001 From: Pi Developer Date: Mon, 2 Feb 2026 23:43:12 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Forza=20modalit=C3=A0=20parallela=20con?= =?UTF-8?q?=20default=202=20inverter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rimosso timeout e detection automatica - Sempre modalità parallela forzata - Default 2 inverter se parallel discovery fallisce - Registra discovery per voltronic_inv1 e voltronic_inv2 NOTA: Se gli inverter non rispondono a QPGS, NON sono in modalità parallela. Per gestire 2 inverter fisici separati, serve INVERTER_DEVICES=/dev/ttyUSB0:/dev/ttyUSB1 --- sources/inverter-mqtt/entrypoint.sh | 40 +++------------------ sources/inverter-mqtt/mqtt-init-parallel.sh | 14 ++++---- sources/inverter-mqtt/mqtt-push-parallel.sh | 18 ++++------ 3 files changed, 19 insertions(+), 53 deletions(-) diff --git a/sources/inverter-mqtt/entrypoint.sh b/sources/inverter-mqtt/entrypoint.sh index cfbe319..48a6629 100755 --- a/sources/inverter-mqtt/entrypoint.sh +++ b/sources/inverter-mqtt/entrypoint.sh @@ -235,46 +235,16 @@ if [ "$NEED_DISCOVERY" = "true" ]; then fi echo "" -echo "=== Detecting Inverter Configuration ===" +echo "=== Starting MQTT Bridge Services ===" +echo "Using parallel inverter mode" echo "" # Wait a bit for the device to be ready sleep 2 -# Check for parallel inverters (with timeout to avoid hanging) -echo "Checking for parallel inverters..." -PARALLEL_CHECK=$(timeout 15 /opt/inverter-cli/bin/inverter_poller -p 2>&1) -PARALLEL_EXIT=$? - -if [ $PARALLEL_EXIT -eq 124 ]; then - echo "⚠ Parallel discovery timed out (15s), using single inverter mode" - USE_PARALLEL=false -else - PARALLEL_COUNT=$(echo "$PARALLEL_CHECK" | grep "PARALLEL_COUNT=" | cut -d= -f2) - - if [ ! -z "$PARALLEL_COUNT" ] && [ "$PARALLEL_COUNT" -gt 0 ]; then - echo "✓ Detected $PARALLEL_COUNT parallel inverter(s)" - echo " Using parallel mode scripts..." - USE_PARALLEL=true - else - echo "ℹ Single inverter mode (count=$PARALLEL_COUNT)" - echo " Using standard scripts..." - USE_PARALLEL=false - fi -fi - -# Set script paths based on mode -if [ "$USE_PARALLEL" = true ]; then - MQTT_PUSH_SCRIPT="/opt/inverter-mqtt/mqtt-push-parallel.sh" - MQTT_INIT_SCRIPT="/opt/inverter-mqtt/mqtt-init-parallel.sh" -else - MQTT_PUSH_SCRIPT="/opt/inverter-mqtt/mqtt-push.sh" - MQTT_INIT_SCRIPT="/opt/inverter-mqtt/mqtt-init.sh" -fi - -echo "" -echo "=== Starting MQTT Bridge Services ===" -echo "" +# Always use parallel scripts +MQTT_PUSH_SCRIPT="/opt/inverter-mqtt/mqtt-push-parallel.sh" +MQTT_INIT_SCRIPT="/opt/inverter-mqtt/mqtt-init-parallel.sh" # Init the mqtt server for the first time, then every 10 minutes (600 seconds) # This will re-create the auto-created topics in the MQTT server if HA is restarted... diff --git a/sources/inverter-mqtt/mqtt-init-parallel.sh b/sources/inverter-mqtt/mqtt-init-parallel.sh index 128093c..ef66efc 100755 --- a/sources/inverter-mqtt/mqtt-init-parallel.sh +++ b/sources/inverter-mqtt/mqtt-init-parallel.sh @@ -47,17 +47,19 @@ registerInverterRawCMD () { }" } -# Discover parallel inverters -PARALLEL_DISCOVERY=`timeout 15 /opt/inverter-cli/bin/inverter_poller -p 2>&1` +# Discover parallel inverters (no timeout, always try) +PARALLEL_DISCOVERY=`/opt/inverter-cli/bin/inverter_poller -p 2>&1` PARALLEL_COUNT=`echo "$PARALLEL_DISCOVERY" | grep "PARALLEL_COUNT=" | cut -d= -f2` +echo "Parallel discovery result: count=$PARALLEL_COUNT" + +# If no parallel inverters found, assume 2 as default if [ -z "$PARALLEL_COUNT" ] || [ "$PARALLEL_COUNT" -eq 0 ]; then - echo "No parallel inverters found, falling back to standard init" - exec /opt/inverter-mqtt/mqtt-init.sh - exit 0 + echo "⚠ No parallel count detected, assuming 2 inverters" + PARALLEL_COUNT=2 fi -echo "Found $PARALLEL_COUNT parallel inverters" +echo "Registering discovery for $PARALLEL_COUNT inverters" # Register topics for each inverter discovered for inv_id in $(seq 1 $PARALLEL_COUNT); do diff --git a/sources/inverter-mqtt/mqtt-push-parallel.sh b/sources/inverter-mqtt/mqtt-push-parallel.sh index 767ccbe..e9eda7c 100755 --- a/sources/inverter-mqtt/mqtt-push-parallel.sh +++ b/sources/inverter-mqtt/mqtt-push-parallel.sh @@ -77,21 +77,15 @@ fi PARALLEL_DISCOVERY=`$SUDO_CMD "$INVERTER_BIN" -p 2>&1` PARALLEL_COUNT=`echo "$PARALLEL_DISCOVERY" | grep "PARALLEL_COUNT=" | cut -d= -f2` +echo "Parallel discovery: count=$PARALLEL_COUNT" + +# If no parallel count detected, assume 2 inverters if [ -z "$PARALLEL_COUNT" ] || [ "$PARALLEL_COUNT" -eq 0 ]; then - echo "No parallel inverters found (count=$PARALLEL_COUNT), using standard polling" - # Don't use fallback in dev mode if file doesn't exist - if [ -f "$MQTT_FALLBACK" ]; then - exec $MQTT_FALLBACK - else - echo "Fallback script not found: $MQTT_FALLBACK" - echo "Using standard inverter_poller -1 instead" - INVERTER_DATA=`$SUDO_CMD "$INVERTER_BIN" -1 2>&1` - echo "$INVERTER_DATA" - fi - exit 0 + echo "⚠ No parallel count detected, assuming 2 inverters" + PARALLEL_COUNT=2 fi -echo "Found $PARALLEL_COUNT parallel inverters" +echo "Processing $PARALLEL_COUNT parallel inverters" # Publish discovery info pushMQTTData "system" "parallel_count" "$PARALLEL_COUNT"