Victron devices over Bluetooth

Victron devices such as the SmartShunt and SmartSolar MPPT broadcast their readings over Bluetooth ("instant readout"), encrypted with a key per device. The Victron BLE gateway is a small program on a computer near them (for example a Raspberry Pi) that listens to those broadcasts. Solar Cloud asks it once per interval for each device's reading and the average over that interval.

Solar Cloud server ── HTTP, port 8088: "read these devices, average of the last 15 min" ─▶ victron_ble_gateway.py ◀── Bluetooth ── Victron devices

Log in to download the gateway Free account: sign up.

A gateway on your home network can only be read by a Solar Cloud server on that same network, i.e. when you run Solar Cloud yourself. On a public Solar Cloud, accounts may only connect to public internet addresses.

How Solar Cloud talks to the gateway

1. What you need

2. Install and try it

pip3 install --user bleak victron-ble
python3 victron_ble_gateway.py -v               # listens on port 8088; prints "Hearing …" for each device
curl http://localhost:8088/devices              # the Victron devices it hears
--port 8088Where Solar Cloud connects.
--keep 1800Seconds of broadcasts kept: the longest interval Solar Cloud can average.
--stall-timeout 60Exit when no Victron broadcast is heard for this long, so systemd restarts it (Bluetooth scanning sometimes hangs).
-vLog every request (keys are never logged).

Then in Solar Cloud: Add a system → Victron over Bluetooth, the gateway's address, Find devices, Add each device, paste its key, Read fields, choose the interval, and Create.

3. Start it automatically

sudo mkdir -p /opt/victronblegateway && sudo chown $USER /opt/victronblegateway
cp victron_ble_gateway.py /opt/victronblegateway/
sudo cp victron-ble-gateway.service.example /etc/systemd/system/victron-ble-gateway.service
sudo nano /etc/systemd/system/victron-ble-gateway.service      # your user and folder
sudo systemctl daemon-reload
sudo systemctl enable --now victron-ble-gateway
journalctl -u victron-ble-gateway -f                           # its log

Safety

When it doesn't work

"Gateway … can't be reached"The gateway isn't running, the address or port is wrong, or a firewall is in between.
Find devices shows nothingBluetooth off (bluetoothctl show), devices out of range, or Instant readout not switched on in VictronConnect.
"not seen yet"That device isn't in range of the gateway, or the gateway just restarted.
"Incorrect advertisement key"Wrong key: copy it again from VictronConnect.
Nonsense values (e.g. 3,218 V)A wrong key that passed the gateway's one-byte check (about 1 in 256): copy the key again.
The gateway restarts every minuteIt hears no Victron broadcasts at all: see "Find devices shows nothing".

An RS485 bus on the network

Many inverters, chargers and batteries talk Modbus over RS485: two wires, A and B. The Modbus gateway is a small program that runs on a computer next to them (for example a Raspberry Pi) with a USB-RS485 adapter. It puts the bus on your network, so Solar Cloud can read the devices from another machine.

Solar Cloud server ──┐
other programs     ──┴─▶ network, TCP port 5020 ─▶ modbus_gateway.py ─▶ USB-RS485 adapter ─▶ RS485 bus ─▶ devices

Log in to download the gateway Free account: sign up.

A gateway on your home network can only be read by a Solar Cloud server on that same network, i.e. when you run Solar Cloud yourself. On a public Solar Cloud, accounts may only connect to public internet addresses.

How Solar Cloud talks to the gateway

1. What you need

2. Install

sudo mkdir -p /opt/modbusgateway && sudo chown $USER /opt/modbusgateway
cp modbus_gateway.py /opt/modbusgateway/
pip3 install --user pyserial            # or: sudo apt install python3-serial
sudo usermod -aG dialout $USER          # access to the serial port; log out and in again
ls /dev/serial/by-id/                   # the adapter's fixed name (better than /dev/ttyUSB0, which can change)

3. Try it by hand

python3 /opt/modbusgateway/modbus_gateway.py /dev/serial/by-id/YOUR-ADAPTER --baud 9600 --listen 0.0.0.0:5020 --gap 50 -v
--baud, --parity N|E|O, --stopbits 1|2Your devices' bus settings. 9600 8N1 is common; 8E1 and 8N2 too.
--listen 0.0.0.0:5020Where Solar Cloud connects. Use a port above 1024 (502 needs root on Linux).
--gap 50Milliseconds of quiet on the bus between requests. Real devices often need far more than the Modbus minimum; 40–50 is a safe start.
--timeout 1.0How long the gateway waits for a device's answer (seconds).
--rtu-listen 0.0.0.0:5021Optional: raw RTU frames over TCP for other programs (e.g. minimalmodbus). Solar Cloud doesn't use it.
-vLog every request and answer, to see what happens.

Then in Solar Cloud: Add a system → Read my inverter directly, connection RS485 gateway, the gateway computer's address, port 5020, the device address, and press Test. Stop the gateway with Ctrl+C when you're done trying.

4. Start it automatically

Download the service file template, fill in the user, folder, serial port and baud rate, and install it:

sudo cp modbusGateway.service.example /etc/systemd/system/modbusGateway.service
sudo nano /etc/systemd/system/modbusGateway.service
sudo systemctl daemon-reload
sudo systemctl enable --now modbusGateway
systemctl status modbusGateway          # running?
journalctl -u modbusGateway -f          # its log

Safety

When it doesn't work

"Gateway … can't be reached"The gateway isn't running, the address or port is wrong, or a firewall is in between.
"The device did not answer" for every requestWrong device address, device off, wrong baud rate / parity / stop bits on the gateway, or A and B swapped.
Now and then "did not answer", mostly with several devices--gap too small: try 50.
PermissionError on port 502Ports below 1024 need root: use 5020.
Permission denied: '/dev/ttyUSB0'The user isn't in the dialout group (log out and in after adding).
gateway error: … in the gateway's logThe USB adapter was unplugged or failed.