SDM72 Modbus Library and Tool
This repository contains a Rust library and a command-line tool for interacting with Eastron SDM72 series energy meters via the Modbus protocol.
Table of Contents
- Hardware Requirements
- Technical Documentation
- Technical Specifications
- Installation & Compilation
- Command-Line Usage
- Library Usage
- Cargo Features
- License
Hardware Requirements
To use this tool, you need:
- An Eastron SDM72 series energy meter.
- A USB-to-RS485 converter (for RTU mode) or a Modbus TCP gateway.
Technical Documentation
For more detailed information, please refer to the official datasheets available in the docs/ directory:
Technical Specifications
| Feature | Details |
|---|---|
| Nominal Voltage | 230/400V AC (3~) |
| Operational Voltage | 80%~120% of nominal voltage |
| Current Measurement | Up to 100A direct connection |
| Communication Protocol | Modbus RTU/TCP |
| Baud Rates | 2400, 4800, 9600, 19200, 38400 |
| Data Format | N, 8, 1 (No parity, 8 data bits, 1 stop bit) |
Installation & Compilation
Prerequisites
Ensure you have the following dependencies installed before proceeding:
- Rust and Cargo: Install via rustup
- Git: To clone the repository
- A C compiler and linker
Building from Source
- Clone the repository:
- Compile the project:
The compiled binary will be available at: - (Optional) Install the binary system-wide:
This installssdm72to$HOME/.cargo/bin, making it accessible from anywhere.
Command-Line Usage
View Available Commands
To list all available commands and their options, run:
Read All Values
For RTU Modbus (RS485) connected devices:
For TCP Modbus connected devices:
Daemon Mode with MQTT
You can also run the tool as a daemon that publishes data to an MQTT broker. The connection is configured via an mqtt.yaml file.
Library Usage
The sdm72_lib crate provides two main ways to interact with the SDM72 energy meters:
-
High-Level, Safe Clients: Stateful, thread-safe clients that are easy to share and use in concurrent applications. This is the recommended approach for most users. See
tokio_sync_safe_client::SafeClient(blocking) andtokio_async_safe_client::SafeClient(async). -
Low-Level, Stateless Functions: A set of stateless functions that directly map to the device's Modbus commands. This API offers maximum flexibility but requires manual management of the Modbus context. See the
tokio_syncandtokio_asyncmodules.
Quick Start: Synchronous Client
Here's a quick example of how to use the synchronous SafeClient to read all values over a TCP connection.
Dependencies
First, add the required dependencies to your project:
Example Usage
use ;
use tcp;
use Slave;
use Duration;
Cargo Features
This crate uses a feature-based system to minimize dependencies. When using it as a library, you should disable default features and select only the components you need.
default: Enablesbin-dependencies, intended for compiling thesdm72command-line tool.
Client Features
tokio-rtu-sync: Synchronous (blocking) RTU client.tokio-tcp-sync: Synchronous (blocking) TCP client.tokio-rtu: Asynchronous (non-blocking) RTU client.tokio-tcp: Asynchronous (non-blocking) TCP client.
High-Level Wrappers
safe-client-sync: A thread-safe, stateful wrapper for synchronous clients.safe-client-async: A thread-safe, stateful wrapper for asynchronous clients.
Utility Features
serde: Implementsserde::Serializeandserde::Deserializefor protocol structs.bin-dependencies: All features required to build thesdm72binary.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.