delay messages to reduce mqtt issues (sender to fast) improve mqtt debugging
This commit is contained in:
parent
e070c802d5
commit
869a581242
@ -325,32 +325,44 @@ fn safe_main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
|
|
||||||
let mut water_frozen = false;
|
let mut water_frozen = false;
|
||||||
|
let mut temp:Option<f32> = None;
|
||||||
for _attempt in 0..5 {
|
for _attempt in 0..5 {
|
||||||
let water_temperature = board.water_temperature_c();
|
let water_temperature = board.water_temperature_c();
|
||||||
match water_temperature {
|
match water_temperature {
|
||||||
Ok(temp) => {
|
Ok(res) => {
|
||||||
if online_mode == OnlineMode::Online {
|
temp = Some(res);
|
||||||
let _ = board.mqtt_publish(
|
|
||||||
&config,
|
|
||||||
"/water/temperature",
|
|
||||||
temp.to_string().as_bytes(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
//FIXME mqtt here
|
|
||||||
println!("Water temp is {}", temp);
|
|
||||||
if temp < 4_f32 {
|
|
||||||
water_frozen = true;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if online_mode == OnlineMode::Online {
|
println!("Could not get water temp {} attempt {}", err, _attempt)
|
||||||
let _ = board.mqtt_publish(&config, "/water/temperature", "Error".as_bytes());
|
|
||||||
}
|
|
||||||
println!("Could not get water temp {}", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
match temp {
|
||||||
|
Some(res) => {
|
||||||
|
println!("Water temp is {}", res);
|
||||||
|
if res < 4_f32 {
|
||||||
|
water_frozen = true;
|
||||||
|
}
|
||||||
|
if online_mode == OnlineMode::Online {
|
||||||
|
let _ = board.mqtt_publish(
|
||||||
|
&config,
|
||||||
|
"/water/temperature",
|
||||||
|
res.to_string().as_bytes(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
if online_mode == OnlineMode::Online {
|
||||||
|
let _ = board.mqtt_publish(&config, "/water/temperature", "Error".as_bytes());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mut plantstate = [PlantState {
|
let mut plantstate = [PlantState {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@ -560,7 +572,6 @@ fn safe_main() -> anyhow::Result<()> {
|
|||||||
//is light out of work trigger soon?
|
//is light out of work trigger soon?
|
||||||
//is battery low ??
|
//is battery low ??
|
||||||
//is deep sleep
|
//is deep sleep
|
||||||
|
|
||||||
mark_app_valid();
|
mark_app_valid();
|
||||||
|
|
||||||
unsafe { esp_deep_sleep(1000 * 1000 * 60 * deep_sleep_duration_minutes as u64) };
|
unsafe { esp_deep_sleep(1000 * 1000 * 60 * deep_sleep_duration_minutes as u64) };
|
||||||
@ -953,9 +964,6 @@ fn determine_next_plant(
|
|||||||
}
|
}
|
||||||
println!("Plant {} state is {:?}", plant, state);
|
println!("Plant {} state is {:?}", plant, state);
|
||||||
}
|
}
|
||||||
if online_mode == OnlineMode::Online {
|
|
||||||
update_plant_state(plantstate, board, config);
|
|
||||||
}
|
|
||||||
for plant in 0..PLANT_COUNT {
|
for plant in 0..PLANT_COUNT {
|
||||||
let state = &plantstate[plant];
|
let state = &plantstate[plant];
|
||||||
println!(
|
println!(
|
||||||
|
@ -723,11 +723,14 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
true,
|
true,
|
||||||
message,
|
message,
|
||||||
);
|
);
|
||||||
|
Delay::new(10).delay_ms(10);
|
||||||
match publish {
|
match publish {
|
||||||
OkStd(_) => return Ok(()),
|
OkStd(message_id) => {
|
||||||
|
println!("Published mqtt topic {} with message {:#?} msgid is {:?}",full_topic, String::from_utf8_lossy(message), message_id);
|
||||||
|
return Ok(())
|
||||||
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!("Error during mqtt send on topic {} with message {:#?} error is {:?}",full_topic, message, err);
|
println!("Error during mqtt send on topic {} with message {:#?} error is {:?}",full_topic, String::from_utf8_lossy(message), err);
|
||||||
return Err(err)?
|
return Err(err)?
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user