From 57d8cdfd238c7dcfd809418718553e5a51fff7d4 Mon Sep 17 00:00:00 2001 From: Ollo Date: Fri, 18 Aug 2023 00:03:38 +0200 Subject: [PATCH] Started querying public transporatation --- client/bin/Cargo.toml | 3 +++ client/bin/src/main.rs | 10 +++++++--- client/bin/src/straba.rs | 13 +++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 client/bin/src/straba.rs diff --git a/client/bin/Cargo.toml b/client/bin/Cargo.toml index 60a2278..2a0eddb 100644 --- a/client/bin/Cargo.toml +++ b/client/bin/Cargo.toml @@ -14,3 +14,6 @@ chrono = { version = "0.4.23", default-features = false , features = ["iana-time chrono-tz = "0.8.0" colored = "2.0.0" datetime = "0.5.2" +# Necessary for web crawler +openssl = { version = "0.10", features = ["vendored"] } +reqwest = { version = "0.11", features = ["blocking", "json"] } diff --git a/client/bin/src/main.rs b/client/bin/src/main.rs index 40c1efb..e24c9c1 100644 --- a/client/bin/src/main.rs +++ b/client/bin/src/main.rs @@ -19,6 +19,9 @@ use std::{net::UdpSocket, time::{Instant, Duration}}; use std::{env, thread}; use openweathermap::forecast::Forecast; +// This declaration will look for a file named `straba.rs` and will +// insert its contents inside a module named `straba` under this scope +mod straba; const IMAGE_SIZE_BYTE: usize = (IMAGE_WIDTH_BYTE * IMAGE_HEIGHT) as usize; /* one byte contains 8 LEDs, one in each bit */ const IMAGE_WIDTH: u32 = 5 * 32; @@ -237,8 +240,8 @@ fn send_package(ipaddress: String, data: &Option>) { package[1..PACKAGE_LENGTH].copy_from_slice(&display.image); - - let socket = UdpSocket::bind("0.0.0.0:4242").expect("couldn't bind to address"); + // client need to bind to client port (1 before 4242) + let socket = UdpSocket::bind("0.0.0.0:14242").expect("couldn't bind to address"); socket .send_to(&package, ipaddress + ":4242") .expect("couldn't send data"); @@ -274,7 +277,8 @@ fn main() { let mut last_data = Option::None; - + // Test Webcrawler for public transportataion + straba::fetchData(); loop { let delay = time::Duration::from_millis(10000); diff --git a/client/bin/src/straba.rs b/client/bin/src/straba.rs new file mode 100644 index 0000000..91e51b3 --- /dev/null +++ b/client/bin/src/straba.rs @@ -0,0 +1,13 @@ +/* @file straba.rs + * @brief fetch next depature of light rail vehicle + */ +use std::error::Error; + +const stationURL:&str = "https://www.rnv-online.de/rest/departure/2494/1"; + +pub fn fetchData() -> Result<(), Box> { + println!("Test RNV API"); + let resp = reqwest::blocking::get(stationURL)?.text()?; + println!("{:#?}", resp); + Ok(()) +}