+use std::{
+ fmt,
+ net::{IpAddr, Ipv4Addr, UdpSocket},
+ str::FromStr,
+ thread,
+ time::{self, Duration},
+};
+
+use anyhow::Result;
+use ping::rawsock::ping;
+
+use crate::config::Config;
+
+mod config;
+
+const FILE_CONF: &str = "config.ron";
+const PING_TIMEOUT: Duration = Duration::from_secs(5);
+
+fn main() -> Result<()> {
+ println!("Raspberry Keep Alive");
+
+ let config = Config::read(FILE_CONF)?;
+ let ip_addr = IpAddr::V4(Ipv4Addr::from_str(&config.address)?);
+
+ println!("Configuration: {:?}", config);
+
+ loop {
+ let time_beginning_loop = time::Instant::now();
+
+ println!("Sending a ping to {}", config.address);
+
+ if let Err(error) = ping(ip_addr, Some(PING_TIMEOUT), None, None, None, None) {
+ println!("Error during ping: {:?}", error);
+ }
+
+ // println!("Time: {:?}", time::Instant::now() - time_beginning_loop);
+
+ let elapsed = time::Instant::now() - time_beginning_loop;
+
+ if elapsed < config.duration {
+ let to_wait = config.duration - elapsed;
+ thread::sleep(to_wait);
+ }
+ }
+}