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
- The gateway keeps no keys and has no settings. Solar Cloud keeps each device's Bluetooth address and key (on the
server only, never shown again) and sends them with every request.
- At each interval (every minute, every 15 minutes, ...) Solar Cloud asks for all devices of a system at once, with the
interval as averaging window (up to 30 minutes, the gateway's memory).
- Each log line holds the average for changing values (voltage, current, power) and the latest value for
counters (yield today, consumed Ah). A device out of range gets an empty value for that interval.
- Read fields asks the devices once: the numeric fields they send decide what can be logged. With Also log new fields,
a field a device starts sending later (e.g. a temperature after changing the shunt's aux input) gets a new column by itself.
- It only reads; Bluetooth instant readout can't change anything on the devices.
1. What you need
- A Linux computer with Bluetooth (built in or a USB dongle), within about 10 m of the devices (less through walls), on the
same network as the Solar Cloud server, with Python 3.8 or newer.
- Each device's encryption key (32 hex digits) and Bluetooth address: in the VictronConnect app, open the device →
Product info → Instant readout details (Instant readout must be switched on).
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 8088 | Where Solar Cloud connects. |
--keep 1800 | Seconds of broadcasts kept: the longest interval Solar Cloud can average. |
--stall-timeout 60 | Exit when no Victron broadcast is heard for this long, so systemd restarts it (Bluetooth scanning sometimes hangs). |
-v | Log 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
- No password and no encryption on the network: anyone who can reach port 8088 can list the devices, and the keys travel
in plain text from Solar Cloud to the gateway. Keep it on your home network (never forward port 8088 on your router).
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 nothing | Bluetooth 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 minute | It 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
- Solar Cloud opens one connection to the gateway (its address, port 5020), keeps it open and shares it
between all systems that use this gateway. After a gateway restart it reconnects by itself.
- It sends standard Modbus TCP requests. The unit ID in each request is the device's address on the RS485
bus, the field Device address (Modbus unit ID) in Solar Cloud. So one gateway serves several devices, such as
batteries 1 and 2 and inverter 5.
- It only reads (Modbus functions 3 and 4), in blocks of neighbouring registers with a short pause between
requests, once per read interval (60 seconds by default). It never changes anything on a device.
- The gateway puts one request at a time on the bus (RS485 can't do two at once) and queues the rest, so other
programs can use the same gateway.
- A device that doesn't answer comes back as gateway exception
0x0B. Solar Cloud shows "the device did not
answer" and tries again at the next reading.
- The bus settings (baud rate, parity, stop bits) are set on the gateway, not in Solar Cloud.
1. What you need
- A Linux computer on the same network as the Solar Cloud server, with Python 3.8 or newer.
- A USB-RS485 adapter. Wire A to A and B to B (sometimes marked D+ and D−) and, if the device has one,
GND to GND.
- Your devices' RS485 settings (baud rate, parity, stop bits) and addresses, from their manuals or display menus.
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|2 | Your devices' bus settings. 9600 8N1 is common; 8E1 and 8N2 too. |
--listen 0.0.0.0:5020 | Where Solar Cloud connects. Use a port above 1024 (502 needs root on Linux). |
--gap 50 | Milliseconds 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.0 | How long the gateway waits for a device's answer (seconds). |
--rtu-listen 0.0.0.0:5021 | Optional: raw RTU frames over TCP for other programs (e.g. minimalmodbus). Solar Cloud doesn't use it. |
-v | Log 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
- The gateway has no password and passes on writes. Anyone who can reach port 5020 can read and change the
devices on the bus. Keep it on your home network: never forward port 5020 on your router, and limit it with a firewall
if others use your network, e.g.
sudo ufw allow from <Solar Cloud server> to any port 5020.
- Only one program may open the serial port. While the gateway runs, other programs must go through the gateway too.
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 request | Wrong 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 502 | Ports 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 log | The USB adapter was unplugged or failed. |