Expand description
§Homey Energy Dongle local API access
Unofficial async implementation of Homey Energy Dongle discovery and local API access. See the support page for details on how to enable it in your dongle.
The crate includes the mDNS discovery with the discover feature and the local API access with the websocket feature. Both
features are disabled by default.
The general workflow with this crate is as follows:
- Discover the present Homey Energy Dongles on the network using mDNS using discover_devices_with_mdns() or supply the static address.
- Establish the WebSocket connection using WebsocketEnergyDongle::connect(). All necessary arguments for this call are returned by the discover_devices_with_mdns() function. If you store the connection details statically, you need to have the IP address, port and WebSocket URL path. The path is usually “/ws”.
- The WebsocketEnergyDongle struct implements Stream over Bytes buffers that the dongle sends. These buffers don’t always contain a complete DSMR telegram, so you’ll need some kind of buffer to store the intermediate bytes. For this you can use a more low-level RawTelegramReader with its RawTelegramReader::feed() method or a more easy-to-use RawTelegramStream wrapper which implements Stream over RawTelegram.
- Use a DSMR parsing library (e.g., dsmr5) to parse the RawTelegram and get a readable DSMR telegram.
§Example
use std::net::SocketAddr;
use std::time::Duration;
use futures_util::{stream, StreamExt};
async fn example() {
let dongles = homey_energy_dongle::discover::discover_devices_with_mdns(Duration::from_secs(5), 0).await.unwrap();
for dongle in dongles {
let addr = dongle.socket_addresses().next().unwrap();
let dongle_buffers = homey_energy_dongle::websocket::WebsocketEnergyDongle::connect(addr, &dongle.path)
.await
.unwrap()
.flat_map(|res| stream::iter(res.ok()));
let mut raw_telegram_reader = homey_energy_dongle::reader::RawTelegramStream::new(dongle_buffers);
while let Some(raw_telegram) = raw_telegram_reader.next().await {
dbg!(&raw_telegram);
}
}
}Modules§
Structs§
- Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.