Read data from Victron devices over Bluetooth Low Energy.
Some Victron devices broadcast some aspects of their state over Bluetooth on a regular basis. This crate makes it easy to access that data.
Use the open_stream
function to get a stream of state updates for a given
Victron device:
use std::{println, time::Duration};
use tokio_stream::StreamExt;
#[tokio::main]
async fn main() {
let device_name = "Victron Bluetooth device name".into();
let device_encryption_key = hex::decode("00"/* Victron device encryption key. See below. */).unwrap();
let mut device_state_stream = victron_ble::open_stream(
device_name,
device_encryption_key
).unwrap();
while let Some(result) = device_state_stream.next().await {
println!("{result:?}");
}
}
In order to turn on the Victron device's BLE state broadcasts you must enable the "Instant Readout" setting. This can be done via the Victron Connect App on iOS or Android.
The device status messages published by the Victron device are encrypted. In order to decrypt them the device encryption key is needed. This can be found for a given device using the Victron Connect app on iOS or Android.
Using the app, connect to the device, then go to Settings -> Product Info -> Encryption data.
Currently the following device types are supported. Support can be added for other device types if requested.
- Solar Charger
- Battery Monitor
- Inverter
- VE Bus
Adds the open_stream
function which handles all of the bluetooth discovery and receiving but is only supported for the macos
and linux
targets. With the bluetooth
feature off you still get the parse_manufacturer_data
function but you must source your own manufacturer data packet. bluetooth
is a default feature.
Makes the DeviceState
enum (de)serializable.
If you turn the bluetooth
feature off then the crate can be compiled in a no_std
context.
An example application is provided which prints the state of a given device to the terminal.
cargo run --example bluetooth <Victron device name> <Victron device encryption key>
Various aspects of this crate are either inspired by or copied from these projects: