Implementazione supporto multi-inverter paralleli e fix comunicazione MQTT
Build Docker Image for Raspberry Pi / build-and-push (push) Failing after 1m15s
Build Docker Image for Raspberry Pi / build-and-push (push) Failing after 1m15s
- Aggiunto supporto lettura inverter paralleli tramite comandi QPGS0-QPGS9 - Implementato discovery automatico inverter con filtro duplicati e serial invalidi - Risolti bug critici comunicazione seriale: * Fix buffer ExecuteCmd da 7 a 200 bytes * Supporto terminatori CR e LF * Modalità blocking con delay 500ms * Lettura byte-by-byte per terminatore affidabile - Implementato script MQTT per pubblicazione dati multi-inverter: * mqtt-push-parallel.sh con topic separati per ogni inverter * Fix autenticazione MQTT con username/password * Aggiunto flag retain (-r) per persistenza dati - Creato test-loop-parallel.sh per simulazione completa container - Aggiornata documentazione con compatibilità MKS IV e guida test loop - Aggiornati profili debug VS Code per bash e parallel discovery - Configurazione MQTT completa con server reale (192.168.1.37:1883) Sistema testato e funzionante con 2 inverter Voltronic Axpert MKS IV
This commit is contained in:
Executable
+142
@@ -0,0 +1,142 @@
|
||||
#!/bin/bash
|
||||
# Test comunicazione con Voltronic Axpert MKS IV provando diversi baudrate
|
||||
# Il MKS IV potrebbe usare un baudrate diverso dal classico 2400
|
||||
|
||||
DEVICE="${1:-/dev/ttyUSB0}"
|
||||
|
||||
echo "=== Test Baudrate per Voltronic Axpert MKS IV su $DEVICE ==="
|
||||
echo ""
|
||||
|
||||
# Verifica device
|
||||
if [ ! -e "$DEVICE" ]; then
|
||||
echo "ERROR: Device $DEVICE non trovato!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Array di baudrate da testare
|
||||
# Il MKS IV potrebbe usare: 2400, 9600, 19200, 38400 o 115200
|
||||
BAUDRATES=(2400 9600 19200 38400 115200)
|
||||
|
||||
for BAUD in "${BAUDRATES[@]}"; do
|
||||
echo "============================================"
|
||||
echo "Testing BAUDRATE: $BAUD"
|
||||
echo "============================================"
|
||||
|
||||
# Configura device
|
||||
sudo stty -F $DEVICE $BAUD cs8 -cstopb -parenb -echo raw
|
||||
sudo chmod 666 $DEVICE
|
||||
|
||||
# Test con Python
|
||||
python3 << PYTHON_EOF
|
||||
import sys
|
||||
import serial
|
||||
import time
|
||||
|
||||
def calc_crc(data):
|
||||
"""Calcola CRC secondo protocollo Voltronic"""
|
||||
crc_ta = [
|
||||
0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
|
||||
0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef
|
||||
]
|
||||
|
||||
crc = 0
|
||||
for byte in data:
|
||||
da = ((crc >> 8) >> 4)
|
||||
crc = (crc << 4) & 0xFFFF
|
||||
crc ^= crc_ta[da ^ (byte >> 4)]
|
||||
|
||||
da = ((crc >> 8) >> 4)
|
||||
crc = (crc << 4) & 0xFFFF
|
||||
crc ^= crc_ta[da ^ (byte & 0x0F)]
|
||||
|
||||
return crc.to_bytes(2, 'big')
|
||||
|
||||
try:
|
||||
ser = serial.Serial(
|
||||
port='$DEVICE',
|
||||
baudrate=$BAUD,
|
||||
bytesize=8,
|
||||
parity='N',
|
||||
stopbits=1,
|
||||
timeout=2
|
||||
)
|
||||
|
||||
print(f"Porta aperta a {$BAUD} baud")
|
||||
|
||||
# Flush buffers
|
||||
ser.reset_input_buffer()
|
||||
ser.reset_output_buffer()
|
||||
time.sleep(0.3)
|
||||
|
||||
# Test comando QMOD (semplice, 5 bytes di risposta)
|
||||
cmd = 'QMOD'
|
||||
print(f"Invio comando: {cmd}")
|
||||
|
||||
cmd_bytes = cmd.encode('ascii')
|
||||
crc = calc_crc(cmd_bytes)
|
||||
full_cmd = cmd_bytes + crc + b'\r'
|
||||
|
||||
print(f" Hex: {full_cmd.hex()}")
|
||||
|
||||
# Invia
|
||||
ser.write(full_cmd)
|
||||
ser.flush()
|
||||
time.sleep(0.5)
|
||||
|
||||
# Leggi risposta
|
||||
response = ser.read(200)
|
||||
|
||||
if len(response) > 0:
|
||||
print(f" [OK] RISPOSTA RICEVUTA ({len(response)} bytes)")
|
||||
print(f" Hex: {response.hex()}")
|
||||
try:
|
||||
ascii_text = response.decode('ascii', errors='replace')
|
||||
print(f" ASCII: {ascii_text.strip()}")
|
||||
|
||||
# Verifica se è una risposta valida (inizia con '(' e non è NAK)
|
||||
if response[0:1] == b'(' and b'NAK' not in response:
|
||||
print(f" *** BAUDRATE CORRETTO: {$BAUD} ***")
|
||||
sys.exit(0) # Success
|
||||
elif b'NAK' in response:
|
||||
print(f" [X] NAK ricevuto (inverter non comprende)")
|
||||
else:
|
||||
print(f" [X] Risposta non valida")
|
||||
except:
|
||||
print(f" [X] Risposta non decodificabile")
|
||||
else:
|
||||
print(f" [X] Nessuna risposta (timeout)")
|
||||
|
||||
ser.close()
|
||||
|
||||
except Exception as e:
|
||||
print(f" [X] Errore: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
PYTHON_EOF
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo ""
|
||||
echo "╔═══════════════════════════════════════════╗"
|
||||
echo "║ BAUDRATE CORRETTO TROVATO: $BAUD ║"
|
||||
echo "╚═══════════════════════════════════════════╝"
|
||||
echo ""
|
||||
echo "Aggiorna /etc/inverter/inverter.conf se necessario"
|
||||
echo "Modifica sources/inverter-cli/inverter.cpp:"
|
||||
echo " Cambia: speed_t baud = B$BAUD;"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "============================================"
|
||||
echo "NESSUN BAUDRATE FUNZIONANTE TROVATO"
|
||||
echo "============================================"
|
||||
echo ""
|
||||
echo "Possibili cause:"
|
||||
echo "1. Inverter spento o disconnesso"
|
||||
echo "2. Cavo USB/RS232 difettoso"
|
||||
echo "3. Device errato (prova /dev/ttyUSB1 o /dev/hidraw0)"
|
||||
echo "4. Inverter in modalità incompatibile"
|
||||
echo ""
|
||||
Reference in New Issue
Block a user