victron_ble

Crates.iovictron_ble
lib.rsvictron_ble
version
sourcesrc
created_at2024-10-19 06:56:24.221447
updated_at2024-10-19 07:07:20.193183
descriptionRead data from Victron devices over Bluetooth Low Energy.
homepage
repositoryhttps://github.com/felixwatts/victron_ble
max_upload_size
id1415131
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Felix Watts (felixwatts)

documentation

README

Victron BLE

Read data from Victron devices over Bluetooth Low Energy.

Some Victron devices use the BLE advertising data protocol to broadcast some aspects of their state on a regular basis. This crate enables you to easily decrypt and parse the broadcast data into usable form.

Currently only Solar Charger type devices are supported but support can be added for other device types if requested.

Usage

If you already have the manufacturer data from your Victron device you can use the basic function parse_manufacturer_data to decrypt and parse it.

let device_encryption_key = hex::decode("Victron device encryption key").unwrap();
// Sourced from the manufacturer data part of a BLE advertisement event
// The Victron manufacturer ID is 737
let device_manufacturer_data = [0x10, 0, 0, 0, 0 ]; 

let device_state_result = victron_ble::parse_manufacturer_data(&device_manufacturer_data, &device_encryption_key);

println!("{device_state_result:?}");

If you want the crate to handle the bluetooth side, including discovering the device and receiving the manufacturer data then use the open_stream function which currently supports MacOS and Linux.

let device_name = "Victon Bluetooth device name";
let device_encryption_key = hex::decode("Victron device encryption key").unwrap();

let mut device_state_stream = victron_ble::open_stream(
   device_name, 
   device_encryption_key
).await;

while let Some(result) = device_state_stream.recv().await {
   println!("{result:?}");
}

Encryption Key

The device status messages published by the Victron device are encrypted. In order to decrypt them the device encyption 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.

Serialization

If you add the serde feature then the DeviceState enum will be (de)serializable.

Ackowledgements

Various aspects of this crate are either inspired by or copied from these projects:

Sources

https://communityarchive.victronenergy.com/questions/187303/victron-bluetooth-advertising-protocol.html

And see the file is this repo: extra-manufacturer-data-2022-12-14.pdf

Commit count: 79

cargo fmt