Skip to main content

solaredge_modbus/
lib.rs

1//! # SolarEdge modbus client for Rust
2//!
3//! Enables access to the SolarEdge equipment over the local network via the
4//! [Modbus protocol](https://knowledge-center.solaredge.com/sites/kc/files/sunspec-implementation-technical-note.pdf)
5//! (solar panels, inverters, meters) with the nice typed Rust interface.
6//!
7//! At the moment only the TCP transport is supported, as this is the only way I can test it, but I'm open for contributions to
8//! add support for serial or other transports.
9//!
10//! Modbus TCP might need to be enabled first, see for example
11//! [this guide](https://github.com/binsentsu/home-assistant-solaredge-modbus#enabling-modbus-tcp-on-solaredge-inverter).
12//!
13//! An optional `discover` feature is available to find the inverters on the local network using mDNS.
14//!
15//! ```
16//! use solaredge_modbus::{TcpClient, discover_with_mdns};
17//! use std::time::Duration;
18//!
19//! async fn run() -> Result<(), Box<dyn std::error::Error>> {
20//!    let hosts = discover_with_mdns(Duration::from_secs(3), 1).await?;
21//!    let host_info = hosts.into_iter().next().ok_or("No host found")?;
22//!    let mut client = TcpClient::new_from_host_info(&host_info)?;
23//!    let lifetime_energy = client.energy_wh()?;
24//!    Ok(())
25//! }
26//! ```
27
28pub use error::Error;
29pub use tcp_client::TcpClient;
30
31mod error;
32pub mod tcp_client;
33#[cfg(feature = "discover")]
34pub use discover::{SolaredgeHostInfo, discover_with_mdns};
35#[cfg(feature = "discover")]
36pub mod discover;