Explicit 5-second timeout to ureq
This commit is contained in:
@@ -214,7 +214,9 @@ fn mqtt_connect(uri: String, client_id: String) -> Result<mqtt::Client, mqtt::Er
|
|||||||
|
|
||||||
fn gather(uri: &str, password: &str) -> Result<MQTTData, Error> {
|
fn gather(uri: &str, password: &str) -> Result<MQTTData, Error> {
|
||||||
let body = format!("optType=ReadRealTimeData&pwd={}", password);
|
let body = format!("optType=ReadRealTimeData&pwd={}", password);
|
||||||
let response = ureq::post(uri).send_string(&body)?;
|
let response = ureq::post(uri)
|
||||||
|
.timeout(Duration::from_secs(5))
|
||||||
|
.send_string(&body)?;
|
||||||
|
|
||||||
if response.status() < 200 || response.status() > 299 {
|
if response.status() < 200 || response.status() > 299 {
|
||||||
return Err(Error::MyError);
|
return Err(Error::MyError);
|
||||||
@@ -272,7 +274,7 @@ fn main() {
|
|||||||
Err(e) => println!("Failed to gather data from inverter: {:?}", e),
|
Err(e) => println!("Failed to gather data from inverter: {:?}", e),
|
||||||
};
|
};
|
||||||
|
|
||||||
std::thread::sleep(std::time::Duration::new(5, 0));
|
std::thread::sleep(std::time::Duration::from_secs(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
mqtt_client.disconnect(None).unwrap();
|
mqtt_client.disconnect(None).unwrap();
|
||||||
|
Reference in New Issue
Block a user