Crates.io | sunsniff |
lib.rs | sunsniff |
version | |
source | src |
created_at | 2022-11-06 09:04:52.640496 |
updated_at | 2024-12-07 05:43:19.206355 |
description | Intercept and store telemetry from a Sunsynk inverter |
homepage | |
repository | https://github.com/bmerry/sunsniff |
max_upload_size | |
id | 706416 |
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` |
size | 0 |
This program collects data from a Sunsynk/Deye router and makes it available for use. It can collect the data in two ways (referred to as "frontends"):
By running on a router sitting between an inverter with an
Inteless WiFi dongle and the remote server. In this mode it is a completely
passive observer, so it cannot interface with the inverter's operation. This is
called the pcap
frontend.
By connecting a serial cable to the inverter, it is possible to query it
interactively. This requires additional hardware, but allows the query
interval be set (and made much faster than the 5 minute interval the dongle
uses), and the dongle can be removed for better privacy and security. In this
mode commands are sent to your inverter, but they only read (not write) the
registers, so it is still pretty safe. This is the modbus
frontend. See
this guide for
information on how to wire the RS485 cable. There are reports that the RS232
connection works too.
There are also currently two "backends", which determine what to do with the data.
This is alpha software (although I am using it every day). All the schemas may change. The data you collect might vanish, or leak onto the internet (but it's already being sent unencrypted, which is why this project works in the first place). The config file format may change. It may hang your router.
cargo install sunsniff
to install the binary. Alternatively,
check out the repository and run cargo build --release
. This will compile
the binary to target/release/sunsniff
.If you want to cross-compile:
cross build --release --target=armv7-unknown-linux-gnueabihf
(replace
with your target architecture).target/<arch>/release/target
.I had problems because the resulting binary needed a newer glibc than the host
I was targeting. To build a static binary, set the environment variable
RUSTFLAGS
to -C target-feature=+crt-static -lpcap
. I also found that DNS
wasn't working with glibc, so I ended up using a target of
armv7-unknown-linux-musleabihf
instead.
Configuration is stored in a TOML file, which is passed on the command line.
Configure one of the possible frontends (do not try to configure more than one), and least one backend. It's possible to have more than one instance of the same backend (the doubled square brackets are the TOML syntax that allows for this).
Create a [pcap]
section. It has the following fields:
device
(required): the Ethernet device to capture. Note that the any
device is not currently supported.filter
(optional but recommended): A pcap filter to select the traffic to
inspect. If the device
handles data for any other devices on the network
then setting filter
is necessary to prevent other data from being
accidentally interpreted as sensor readings.file
(optional): if set to true, then device
is interpreted as a pcap
file rather than a device. Note that the pcap file is fully loaded into
memory, so it should not be used with very large files.timezone
(required): The timezone name used by the inverter. This is used
to convert the timestamps to UTC.I have the following setup:
[pcap]
device = "br0"
filter = "src host 192.168.0.21"
timezone = "Africa/Johannesburg"
Create a [modbus]
section. It has the following fields:
device
(required): the serial device, or the address for Modbus over TCP
in the format host:port (the port is required even when using the Modbus
default).interval
(required): time (in seconds) between samplesbaud
(optional): baud rate for the serial port. Defaults to 9600.modbus_id
(optional): Modbus slave number of the inverter. Check your
inverter settings. Defaults to 1.I have the following configuration:
[modbus]
device = "/dev/ttyUSB0"
baud = 9600
interval = 20
The readings are inserted into an Influxdb 2.x bucket. Note that the schema is not final.
The configuration section looks like this:
[[influxdb2]]
host = "http://192.168.0.123:8086/"
org = "my_org"
bucket = "my_bucket"
token = "..."
The implementation tries very hard to deal with intermittent connections to Influxdb, buffering messages until it is able to deliver them (but only in memory; if the service is stopped, any pending messages are lost). Since the updates are only sent every 5 minutes is can be quite practical to buffer messages for hours or days, and I'm currently running the Influxdb server on my home PC which is switched off at night.
The downside of this robustness is that if you get the configuration wrong, the server won't stop with an error. It will just keep trying to deliver, and use more and more memory to buffer the incoming messages.
This backend publishes sensor values to an MQTT broker. The topics are specifically designed for use with Home Assistant and provide the appropriate discovery information, but this doesn't prevent other use cases. You will need to install an MQTT broker (Home Assistant supports Mosquitto as an add-on) and configure Home Assistant to use it. A typical configuration then looks like this:
[[mqtt]]
url = "mqtt://192.168.0.123:1883"
username = "my_username"
password = "my_password"
The username and password can be omitted if the broker doesn't require authentication.
Unfortunately the MQTT library I'm using doesn't support MQTT last will messages, so there is no availability information to indicate that the service is running.
So far I've only tested this with my personal setup. I'm hoping other devices will work too. If it works for you, please let me know. Note that it's unlikely to work with the 3-phase inverters, as they use different registers.
Logging is done with
env_logger, so you can
enable debugging by setting the environment variable RUST_LOG=debug
. There
isn't very much logging yet though.
TODO:
grid_connected
sensorpv_voltage 1
to pv_voltage_1
(the space was a typo).grid_power
, inverter_power
, load_power
.
This makes no difference on my inverter, but may give you more correct
values if you have additional connections.Add more fields.
First release.