///! **Getting Started** ///! ///! This example demostrates reading measurements from the sensor via a network connection. You can either use WiFi or Ethernet. // // Import the client library. Add this to your `Cargo.toml`: // islabtech-upw-sensor-v1 = "0" use islabtech_upw_sensor_v1::{connect_via_network_on_port, Device, Error}; // You also want to import `tokio` in order to easily call the async library functions. // Add this to your Cargo.toml: // tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] } use tokio; use std::{thread::sleep, time::Duration}; #[tokio::main] async fn main() -> Result<(), Error> { // establish a connection to your sensor over network. // The device shows its IP address(es) on its home screen. // The API port is 80. let sensor = connect_via_network_on_port( "192.168.1.123".parse().unwrap(), // put your sensor's IP address here. It shows its address on its home screen. 80.into(), // insert your port here or use `Default::default()` (defaults to 80) Default::default(), // specify TLS settings here or use `Default::default()` (defaults to `UseTls::Auto`) ); loop { // pull the latest measurement info from the device let measurement = sensor.latest_measurement().await?; println!("measurement: {measurement:?}"); sleep(Duration::from_secs(1)) } // Example output: // measurement: Measurement { timestamp: 2024-05-22T17:53:07.177248Z, conductivity: Some(0.19378 µS/cm), temperature: None } // measurement: Measurement { timestamp: 2024-05-22T17:53:08.431233Z, conductivity: Some(0.19386 µS/cm), temperature: None } // measurement: Measurement { timestamp: 2024-05-22T17:53:09.686237Z, conductivity: Some(0.19393 µS/cm), temperature: None } }