Started querying public transporatation
This commit is contained in:
parent
a201193d58
commit
57d8cdfd23
@ -14,3 +14,6 @@ chrono = { version = "0.4.23", default-features = false , features = ["iana-time
|
|||||||
chrono-tz = "0.8.0"
|
chrono-tz = "0.8.0"
|
||||||
colored = "2.0.0"
|
colored = "2.0.0"
|
||||||
datetime = "0.5.2"
|
datetime = "0.5.2"
|
||||||
|
# Necessary for web crawler
|
||||||
|
openssl = { version = "0.10", features = ["vendored"] }
|
||||||
|
reqwest = { version = "0.11", features = ["blocking", "json"] }
|
||||||
|
@ -19,6 +19,9 @@ use std::{net::UdpSocket, time::{Instant, Duration}};
|
|||||||
use std::{env, thread};
|
use std::{env, thread};
|
||||||
|
|
||||||
use openweathermap::forecast::Forecast;
|
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_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;
|
const IMAGE_WIDTH: u32 = 5 * 32;
|
||||||
@ -237,8 +240,8 @@ fn send_package(ipaddress: String, data: &Option<Result<Forecast, String>>) {
|
|||||||
|
|
||||||
|
|
||||||
package[1..PACKAGE_LENGTH].copy_from_slice(&display.image);
|
package[1..PACKAGE_LENGTH].copy_from_slice(&display.image);
|
||||||
|
// client need to bind to client port (1 before 4242)
|
||||||
let socket = UdpSocket::bind("0.0.0.0:4242").expect("couldn't bind to address");
|
let socket = UdpSocket::bind("0.0.0.0:14242").expect("couldn't bind to address");
|
||||||
socket
|
socket
|
||||||
.send_to(&package, ipaddress + ":4242")
|
.send_to(&package, ipaddress + ":4242")
|
||||||
.expect("couldn't send data");
|
.expect("couldn't send data");
|
||||||
@ -274,7 +277,8 @@ fn main() {
|
|||||||
|
|
||||||
let mut last_data = Option::None;
|
let mut last_data = Option::None;
|
||||||
|
|
||||||
|
// Test Webcrawler for public transportataion
|
||||||
|
straba::fetchData();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let delay = time::Duration::from_millis(10000);
|
let delay = time::Duration::from_millis(10000);
|
||||||
|
13
client/bin/src/straba.rs
Normal file
13
client/bin/src/straba.rs
Normal file
@ -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<dyn Error>> {
|
||||||
|
println!("Test RNV API");
|
||||||
|
let resp = reqwest::blocking::get(stationURL)?.text()?;
|
||||||
|
println!("{:#?}", resp);
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user